Skip to content

Commit 2f2702b

Browse files
authored
feat: DEVOPS-1109 move zilliqa isolated server to GCP (#278)
1 parent b49f3e7 commit 2f2702b

30 files changed

+1263
-6
lines changed

.github/workflows/cicd-prd.yml

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
devex-apollo,
2929
eth-spout,
3030
neo-savant,
31+
zilliqa-isolated-server,
3132
]
3233
include:
3334
- application: bluebell-playground
@@ -60,6 +61,11 @@ jobs:
6061
path: products/neo-savant
6162
tag_length: 8
6263
tag_latest: false
64+
- application: zilliqa-isolated-server
65+
image_name: zilliqa-isolated-server
66+
path: products/zilliqa-isolated-server
67+
tag_length: 8
68+
tag_latest: true
6369
env:
6470
DOCKER_DOMAIN: asia-docker.pkg.dev
6571
REGISTRY: asia-docker.pkg.dev/prj-p-devops-services-tvwmrf63/zilliqa-public

.github/workflows/cicd-stg.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ on:
99
push:
1010
branches:
1111
- main
12-
# On released
13-
release:
14-
types: [created]
1512

1613
jobs:
1714
build-docker:
1815
permissions:
1916
id-token: write
2017
contents: write
2118
runs-on: ubuntu-22.04
22-
if: github.actor != 'dependabot[bot]' && github.ref_name == 'main' && github.event_name != 'release'
23-
name: "Build and push images"
19+
if: github.actor != 'dependabot[bot]' && github.ref_name == 'main'
20+
name: "Deploy image"
2421
strategy:
2522
fail-fast: false
2623
matrix:
@@ -78,7 +75,7 @@ jobs:
7875
username: "oauth2accesstoken"
7976
password: "${{ steps.google-auth.outputs.access_token }}"
8077

81-
- name: Get tag version staging - staging
78+
- name: Get tag version - staging
8279
id: set-tag
8380
uses: Zilliqa/gh-actions-workflows/actions/generate-tag@v1
8481
with:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
downloads
3+
persistence
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#FROM 648273915458.dkr.ecr.us-west-2.amazonaws.com/zilliqa:7186a35
2+
FROM zilliqa/zilliqa:v9.2.6
3+
ARG SOURCE_DIR=/zilliqa
4+
5+
WORKDIR ${SOURCE_DIR}
6+
7+
RUN mkdir -p /zilliqa/logs
8+
COPY boot.json ./boot.json
9+
COPY constants.xml ./constants.xml
10+
COPY dsnodes.xml ./dsnodes.xml
11+
COPY validate.sh ./validate.sh
12+
COPY run.sh ./run.sh
13+
EXPOSE 5555
14+
15+
ARG MODE=""
16+
ENV MODE=${MODE}
17+
ENTRYPOINT ["bash", "run.sh"]
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: all
2+
all: image/build-and-push
3+
4+
.ONESHELL:
5+
SHELL := /bin/bash
6+
.SHELLFLAGS = -ec
7+
8+
IMAGE_TAG ?= localhost:5001/zilliqa-isolated-server:latest
9+
10+
## Build and push the Docker image
11+
image/build-and-push:
12+
docker pull nginx:latest
13+
docker tag nginx:latest $(shell echo ${IMAGE_TAG} | sed 's/zilliqa-isolated-server/nginx/')
14+
docker push $(shell echo ${IMAGE_TAG} | sed 's/zilliqa-isolated-server/nginx/')
15+
docker build -t "${IMAGE_TAG}" .
16+
docker push "${IMAGE_TAG}"
+273
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
# Dockerized Zilliqa Isolated Server
2+
3+
## Prerequisites
4+
5+
### Local Build
6+
7+
Docker installed, please follow the steps [here](https://docs.docker.com/get-docker/).
8+
9+
## Administration
10+
11+
### Building Isolated Server Container
12+
13+
#### Local Build
14+
15+
The isolated server can be built locally via the following command: <br />
16+
`docker build -t isolated-server:1.0 .` <br />
17+
there will be an image named isolated-server:1.0 built.
18+
19+
---
20+
21+
### Running Isolated Server Container
22+
23+
#### Local Run
24+
25+
There are a few methods to configure and run the isolated server, all of them requiring augmentations to the docker run command.
26+
27+
##### Running the isolated server as is:
28+
29+
```
30+
docker run -d -p 5555:5555 \
31+
--name isolated-server \
32+
isolated-server:1.0
33+
```
34+
35+
And the api will be available at `http://localhost:5555` <br />
36+
The above command will launch a clean state isolated server with ephermeral storage and seeding all the default accounts via `boot.json`.
37+
38+
---
39+
40+
##### Running the isolated server with persistence
41+
42+
Enabling non-ephermeral persistence can be done by mounting a volume onto the container via the following argument `-v $(pwd)/persistence:/zilliqa/persistence`.
43+
44+
Do note however, there is now two different docker run commands. The first one is required on all **first** launch of Isolated Server with persistence storage.
45+
46+
```
47+
docker run -d -p 5555:5555 \
48+
-v $(pwd)/persistence:/zilliqa/persistence \
49+
--name isolated-server \
50+
isolated-server:1.0
51+
```
52+
53+
The following command must be run on all subsequent Isolated Server container launches. Note the addition of a new argument `--env MODE="load"`. This environment variable forces the Isolated Server to launch while attempting to load persistence from the container directory: `/zilliqa/persistence`.
54+
55+
```
56+
docker run -d -p 5555:5555 \
57+
-v $(pwd)/persistence:/zilliqa/persistence \
58+
--env MODE="load" \
59+
--name isolated-server \
60+
isolated-server:1.0
61+
```
62+
63+
---
64+
65+
##### Running the isolated server with manual block increase
66+
67+
Enabling manual mode can be done by the following command.
68+
69+
If manual mode is enabled, the following api call is available `IncreaseBlocknum`
70+
71+
Do note however, if you run in manual mode, persistence storage is not supported.
72+
73+
```
74+
docker run -d -p 5555:5555 \
75+
--env MANUAL_MODE="true" \
76+
--name isolated-server \
77+
isolated-server:1.0
78+
```
79+
80+
---
81+
82+
##### Additional Run Arguments
83+
84+
The Isolated Server run script also supports modifications to the following parameters
85+
| environment variable | default value | description |
86+
|---|---|---|
87+
|$T|5000|The time before progressing each block in Isolated Server.
88+
|$UUID|uuid|The uuid that's used as a verification for pausing and unpausing the Isolated server.
89+
90+
Docker run command overriding the 2 variables:
91+
92+
```
93+
docker run -d -p 5555:5555 \
94+
--env T="2000" \
95+
--env UUID="randomstring" \
96+
--name isolated-server \
97+
isolated-server:1.0
98+
```
99+
100+
---
101+
102+
##### Stopping the Isolated Server
103+
104+
```
105+
docker stop isolated-server
106+
```
107+
108+
##### Removing the Stopped Isolated Server
109+
110+
```
111+
docker rm isolated-server
112+
```
113+
114+
---
115+
116+
##### Available APIs
117+
118+
- `CreateTransaction` : Input a transaction json payload
119+
- `GetLatestTxBlock` : Get the information on the latest tx block, not available in manual mode.
120+
- `IncreaseBlocknum` : Increase the blocknum by a given input, only available in manual mode.
121+
- `GetSmartContractSubState` : Get the state of a smart contract
122+
- `GetSmartContractCode` : Get code at a given address
123+
- `GetMinimumGasPrice` : Get the minimum gas price
124+
- `SetMinimumGasPrice`: Set the minimum gas price
125+
- `GetBalance`: Get balance and nonce of a account
126+
- `GetSmartContracts`: get smart contract for an address
127+
- `GetNetworkID`: get the network ID of the isolated server
128+
- `GetSmartContractInit` : get init json for a SC.
129+
- `GetTransaction `: Get Transaction info by hash
130+
131+
- `CheckPause`: Checks if the Isolated Server is paused. Requires UUID
132+
- `TogglePause`: Toggles the Isolated Server between pause and unpause state. Requires UUID.
133+
134+
## Deploying applications with z
135+
136+
`z` is the one-stop shop for the Zilliqa provisioning and deployment operations. To deploy applications with z ensure the `z`
137+
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).
138+
139+
## Deploying applications to localdev
140+
141+
To deploy the localdev/development environment go to the project folder in the zilliqa-internal repository:
142+
143+
```sh
144+
cd ./products/zilliqa-isolated-server
145+
```
146+
147+
The `./products/zilliqa-isolated-server/z.yaml` contains all the relevant configurations for the development environment.
148+
Now set the following environment variables to reference the project's `z.yaml` file:
149+
150+
- `Z_ENV` to the path in which your `z.yaml` resides.
151+
- `ZQ_USER` to your username (the bit before `@` in your email address)
152+
153+
for example:
154+
155+
```sh
156+
export Z_ENV=z.yaml
157+
export ZQ_USER=<user_id>@zilliqa.com
158+
```
159+
160+
Create the local kind cluster (if not created previously):
161+
162+
```sh
163+
z local create
164+
```
165+
166+
Build and push the images:
167+
168+
```sh
169+
make image/build-and-push
170+
```
171+
172+
And deploy the application to your local cluster with:
173+
174+
```sh
175+
z app sync
176+
```
177+
178+
Verify your application is running correct from the `http://localhost` URL and with `kubectl` commands (if required).
179+
180+
## Deploying applications to production
181+
182+
To deploy the production environment we need to clone the devops repository and execute `z` from there:
183+
184+
```sh
185+
git clone https://github.com/Zilliqa/devops.git
186+
cd devops
187+
source setenv
188+
```
189+
190+
### Set the following environment variables (production)
191+
192+
- `Z_ENV` to the path in which your `z.yaml` resides.
193+
- `ZQ_USER` to your username (the bit before `@` in your email address)
194+
- `GITHUB_PAT` (if you are deploying staging or production apps) to a classic PAT with all the repo permissions ticked.
195+
196+
for example:
197+
198+
```sh
199+
export Z_ENV=`pwd`/infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml
200+
export ZQ_USER=<user_id>@zilliqa.com
201+
export GITHUB_PAT=<GITHUB_PAT>
202+
```
203+
204+
### Login to Google Cloud (production)
205+
206+
```sh
207+
z login
208+
```
209+
210+
### Login to 1password (production)
211+
212+
```sh
213+
eval $(op signin)
214+
```
215+
216+
### Add the application to the production `z.yaml` file. Skip this step if it is an existing application
217+
218+
1. Create a branch:
219+
220+
```sh
221+
git checkout -b users/<username>/add_zilliqa_isolated_-_server_to_production_cluster
222+
```
223+
224+
2. In the file `infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml` add the following:
225+
226+
- in `apps` stanza add:
227+
228+
```yaml
229+
clusters:
230+
production:
231+
apps:
232+
zilliqa-isolated-server:
233+
repo: https://github.com/Zilliqa/zilliqa-developer
234+
path: products/zilliqa-isolated-server/cd/overlays/production
235+
registry: public
236+
track: production
237+
type: kustomize
238+
```
239+
240+
- in `subdomains` stanza add:
241+
242+
```yaml
243+
infrastructure:
244+
dns:
245+
vars:
246+
subdomains:
247+
zilliqa-isolated-server: {}
248+
```
249+
250+
3. Push the changes
251+
252+
```sh
253+
git add .
254+
git commit -m "Add zilliqa-isolated-server to production cluster"
255+
git push origin users/<username>/add_zilliqa_isolated_server_to_production_cluster
256+
```
257+
258+
4. Open a Pull Request to the main branch
259+
260+
5. Apply the changes
261+
262+
```sh
263+
z plan
264+
z apply
265+
```
266+
267+
### Deploy the application (production)
268+
269+
```sh
270+
z app sync --cache-dir=.cache zilliqa-isolated-server
271+
```
272+
273+
Verify your application is running correct from the staging URL and with `kubectl` commands (if required).

0 commit comments

Comments
 (0)