Skip to content

Commit a7d0059

Browse files
authored
DEVOPS-1040: governance snapshot and api migration to gcp (#263)
* feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * fix: DEVOPS-1087 ionise website prod migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp * feat: DEVOPS-1040 snapshot-hub migration to gcp
1 parent 3ca0c3b commit a7d0059

File tree

184 files changed

+43495
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+43495
-2
lines changed

.github/workflows/cicd-prd.yml

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
devex,
2828
devex-apollo,
2929
eth-spout,
30+
governance-api,
31+
governance-snapshot,
3032
neo-savant,
3133
zilliqa-isolated-server,
3234
zillion,
@@ -57,6 +59,16 @@ jobs:
5759
path: products/eth-spout
5860
tag_length: 9
5961
tag_latest: true
62+
- application: governance-api
63+
image_name: governance-api
64+
path: products/governance-api
65+
tag_length: 8
66+
tag_latest: false
67+
- application: governance-snapshot
68+
image_name: governance-snapshot
69+
path: products/governance-snapshot
70+
tag_length: 8
71+
tag_latest: false
6072
- application: neo-savant
6173
image_name: neo-savant
6274
path: products/neo-savant

.github/workflows/cicd-stg.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
application:
25-
[developer-portal, devex, devex-apollo, neo-savant, zillion]
25+
[
26+
developer-portal,
27+
devex,
28+
devex-apollo,
29+
governance-api,
30+
governance-snapshot,
31+
neo-savant,
32+
zillion,
33+
]
2634
include:
2735
- application: developer-portal
2836
image_name: developer-portal
@@ -44,6 +52,16 @@ jobs:
4452
path: products/neo-savant
4553
tag_length: 8
4654
tag_latest: false
55+
- application: governance-api
56+
image_name: governance-api
57+
path: products/governance-api
58+
tag_length: 8
59+
tag_latest: false
60+
- application: governance-snapshot
61+
image_name: governance-snapshot
62+
path: products/governance-snapshot
63+
tag_length: 8
64+
tag_latest: false
4765
- application: pdt
4866
image_name: pdt
4967
path: products/pdt

.trunk/trunk.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ lint:
3737
paths:
3838
- needing-organisation/**/*
3939
- products/devex/public/*.js
40-
- products/zillion/**
40+
- products/governance-api/**
41+
- products/governance-snapshot/**
42+
- products/zillion/**
4143
- .devcontainer/*
4244
- .devcontainer/**
4345
- .trunk/*out/**

products/governance-api/.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
insert_final_newline = false
14+
trim_trailing_whitespace = false

products/governance-api/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# tmp
2+
.idea
3+
.DS_Store
4+
5+
# lib
6+
node_modules
7+
8+
# build
9+
**/*.d.ts
10+
11+
*.sql
12+
.env

products/governance-api/.sequelizerc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
'config': path.resolve('lib', 'config', 'sequelize.js'),
5+
'migrations-path': path.resolve('migrations')
6+
}

products/governance-api/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:14.17.3
2+
3+
WORKDIR /app
4+
COPY . .
5+
RUN npm install
6+
7+
EXPOSE 3000
8+
9+
ARG SCRIPT="start"
10+
ENV SCRIPT=${SCRIPT}
11+
ENTRYPOINT ["bash", "run.sh"]

products/governance-api/LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './lib/server';

products/governance-api/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: all
2+
all: image/build-and-push
3+
4+
.ONESHELL:
5+
SHELL := /bin/bash
6+
.SHELLFLAGS = -ec
7+
8+
ENVIRONMENT ?= dev
9+
VALID_ENVIRONMENTS := dev stg prd
10+
IMAGE_TAG ?= localhost:5001/snapshot-hub:latest
11+
12+
# Check if the ENVIRONMENT variable is in the list of valid environments
13+
ifeq ($(filter $(ENVIRONMENT),$(VALID_ENVIRONMENTS)),)
14+
$(error Invalid value for ENVIRONMENT. Valid values are dev, stg, or prd.)
15+
endif
16+
17+
## Build and push the Docker image
18+
image/build-and-push:
19+
docker build --build-arg DEPLOY_ENV=${ENVIRONMENT} -t "${IMAGE_TAG}" .
20+
docker push "${IMAGE_TAG}"

products/governance-api/README.md

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# snapshot-hub
2+
3+
REST API for snapshot frontend.
4+
5+
## Installation
6+
7+
```
8+
npm install
9+
```
10+
11+
## Start server
12+
13+
```
14+
npm start
15+
```
16+
17+
### Environment variables
18+
19+
- `PINATA_API_KEY` - API key of [pinata](https://pinata.cloud/).
20+
- `PINATA_SECRET_API_KEY` - SECRET key of [pinata](https://pinata.cloud/).
21+
- `NODE_ENV` - development, test or production
22+
- `POSTGRES_DB` # DataBase name.
23+
- `POSTGRES_PASSWORD` # DataBase password.
24+
- `POSTGRES_USER` # DataBase username.
25+
- `POSTGRES_HOST` # DataBase host for example (127.0.0.1) for production build use 'postgres'.
26+
27+
## Setup database
28+
29+
- sequelize config - `lib/config/sequelize.ts`
30+
31+
## Build docker container
32+
33+
```bash
34+
$ docker-compose build # run building.
35+
$ docker-compose up -d # runing.
36+
```
37+
38+
## Snapshot Spaces Commit
39+
40+
https://github.com/Zilliqa/snapshot-spaces/commit/238e87aad231351a51727b06208ab407f0de1dcc
41+
42+
20220216
43+
44+
## Deploying applications with z
45+
46+
`z` is the one-stop shop for the Zilliqa provisioning and deployment operations. To deploy applications with z ensure the `z`
47+
binary is installed in your operative system PATH environment variable. For more details about `z` please refer to the [documentation](https://github.com/Zilliqa/devops/blob/main/docs/z2.md).
48+
49+
## Deploying applications to staging
50+
51+
To deploy the staging environment we need to clone the devops repository and execute `z` from there:
52+
53+
```sh
54+
git clone https://github.com/Zilliqa/devops.git
55+
cd devops
56+
source setenv
57+
```
58+
59+
### Set the following environment variables
60+
61+
- `Z_ENV` to the path in which your `z.yaml` resides.
62+
- `ZQ_USER` to your username (the bit before `@` in your email address)
63+
- `GITHUB_PAT` (if you are deploying staging or production apps) to a classic PAT with all the repo permissions ticked.
64+
65+
for example:
66+
67+
```sh
68+
export Z_ENV=`pwd`/infra/live/gcp/non-production/prj-d-staging/z_ase1.yaml
69+
export ZQ_USER=<user_id>@zilliqa.com
70+
export GITHUB_PAT=<GITHUB_PAT>
71+
```
72+
73+
### Login to Google Cloud
74+
75+
```sh
76+
z login
77+
```
78+
79+
### Add the application to the staging `z.yaml` file. Skip this step if it is an existing application
80+
81+
1. Create a branch:
82+
83+
```sh
84+
git checkout -b users/<username>/add_governance-api_to_staging_cluster
85+
```
86+
87+
2. In the file `infra/live/gcp/non-production/prj-d-staging/z_ase1.yaml` add the following:
88+
89+
- in `apps` stanza add:
90+
91+
```yaml
92+
clusters:
93+
staging:
94+
apps:
95+
governance-api:
96+
repo: https://github.com/Zilliqa/zilliqa-developer
97+
path: products/governance-api/cd/overlays/staging
98+
track: staging
99+
type: kustomize
100+
```
101+
102+
- in `subdomains` stanza add:
103+
104+
```yaml
105+
infrastructure:
106+
dns:
107+
vars:
108+
subdomains:
109+
governance-api: {}
110+
```
111+
112+
3. Push the changes
113+
114+
```sh
115+
git add .
116+
git commit -m "Add governance-api to staging cluster"
117+
git push origin users/<username>/add_governance-api_to_staging_cluster
118+
```
119+
120+
4. Open a Pull Request to the main branch
121+
122+
5. Apply the changes
123+
124+
```sh
125+
z plan
126+
z apply
127+
```
128+
129+
### Deploy the application
130+
131+
```sh
132+
z app sync --cache-dir=.cache governance-api
133+
```
134+
135+
Verify your application is running correct from the staging URL and with `kubectl` commands (if required).
136+
137+
## Deploying applications to production
138+
139+
To deploy the production environment we need to clone the devops repository and execute `z` from there:
140+
141+
```sh
142+
git clone https://github.com/Zilliqa/devops.git
143+
cd devops
144+
source setenv
145+
```
146+
147+
### Set the following environment variables
148+
149+
- `Z_ENV` to the path in which your `z.yaml` resides.
150+
- `ZQ_USER` to your username (the bit before `@` in your email address)
151+
- `GITHUB_PAT` (if you are deploying staging or production apps) to a classic PAT with all the repo permissions ticked.
152+
153+
for example:
154+
155+
```sh
156+
export Z_ENV=`pwd`/infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml
157+
export ZQ_USER=<user_id>@zilliqa.com
158+
export GITHUB_PAT=<GITHUB_PAT>
159+
```
160+
161+
### Login to Google Cloud
162+
163+
```sh
164+
z login
165+
```
166+
167+
### Add the application to the production `z.yaml` file. Skip this step if it is an existing application
168+
169+
1. Create a branch:
170+
171+
```sh
172+
git checkout -b users/<username>/add_governance-api_to_production_cluster
173+
```
174+
175+
2. In the file `infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml` add the following:
176+
177+
- in `apps` stanza add:
178+
179+
```yaml
180+
clusters:
181+
production:
182+
apps:
183+
governance-api:
184+
repo: https://github.com/Zilliqa/zilliqa-developer
185+
path: products/governance-api/cd/overlays/production
186+
track: production
187+
type: kustomize
188+
```
189+
190+
- in `subdomains` stanza add:
191+
192+
```yaml
193+
infrastructure:
194+
dns:
195+
vars:
196+
subdomains:
197+
governance-api: {}
198+
```
199+
200+
3. Push the changes
201+
202+
```sh
203+
git add .
204+
git commit -m "Add governance-api to production cluster"
205+
git push origin users/<username>/add_governance-api_to_production_cluster
206+
```
207+
208+
4. Open a Pull Request to the main branch
209+
210+
5. Apply the changes
211+
212+
```sh
213+
z plan
214+
z apply
215+
```
216+
217+
### Deploy the application
218+
219+
```sh
220+
z app sync --cache-dir=.cache governance-api
221+
```
222+
223+
Verify your application is running correct from the production URL and with `kubectl` commands (if required).

0 commit comments

Comments
 (0)