forked from paritytech/substrate-api-sidecar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
273 lines (249 loc) · 9.31 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Gitlab-CI Workflow
# stages:
# build:
# - Runs on commits on master or tags that match the pattern v1.0, v2.1rc1
# deploy-staging:
# - Runs on commits on master or tags that match the pattern v1.0, v2.1rc1 (continues deployment)
# deploy-production:
# - Runs on tags that match the pattern v1.0, v2.1rc1 (manual deployment)
variables:
CONTAINER_REPO: "docker.io/parity/substrate-api-sidecar"
DOCKERFILE_DIRECTORY: "./"
CI_IMAGE: "$BUILDAH_IMAGE" # defined in group variables
BUILDAH_COMMAND: "buildah --storage-driver overlay2"
NODE_IMAGE: "node:18"
BENCHMARK_IMAGE: "paritytech/node-wrk:latest"
default:
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
interruptible: true
before_script:
- |-
if [[ $CI_COMMIT_TAG =~ ^v[0-9]+\.[0-9]+.*$ ]]; then
export DOCKER_IMAGE_TAG="${CI_COMMIT_TAG}"
export BUILD_LATEST_IMAGE="true"
else
export DOCKER_IMAGE_TAG="${CI_COMMIT_SHORT_SHA}-beta"
fi
stages:
- test
- build
- deploy-staging
- deploy-production
- benchmark
- check-benchmark
- push-benchmark
.collect-artifacts: &collect-artifacts
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: on_success
expire_in: 1 days
paths:
- ./artifacts/
.test-refs: &test-refs
rules:
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
.test-refs-manual: &test-refs-manual
rules:
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
when: manual
.publish-refs: &publish-refs
rules:
- if: $CI_PIPELINE_SOURCE == "pipeline"
when: never
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
.dockerize: &dockerize
stage: build
image: $CI_IMAGE
tags:
- kubernetes-parity-build
.kubernetes-env: &kubernetes-env
image: $CI_IMAGE
tags:
- kubernetes-parity-build
.deploy-k8s: &deploy-k8s
image: quay.io/argoproj/argocd:v2.7.9
variables:
ARGOCD_OPTS: --grpc-web --grpc-web-root-path /$DOMAIN
script:
- argocd app list
# app1
- argocd app set $APP1 --helm-set substrate-api-sidecar.image.tag="${DOCKER_IMAGE_TAG}"
- argocd app sync $APP1
- argocd app wait $APP1 --timeout 180
# app2
- argocd app set $APP2 --helm-set substrate-api-sidecar.image.tag="${DOCKER_IMAGE_TAG}"
- argocd app sync $APP2
- argocd app wait $APP2 --timeout 180
tags:
- kubernetes-parity-build
.e2e-template: &e2e-template
stage: test
<<: *kubernetes-env
variables:
CI_IMAGE: $NODE_IMAGE
CHAIN_NAME: ""
CHAIN_URL: ""
script:
- yarn --immutable
- echo "Tests for ${CHAIN_URL}"
- yarn test:latest-e2e-tests --log-level info --chain ${CHAIN_NAME} --local ${CHAIN_URL}
allow_failure: true
e2e-westend:
<<: *e2e-template
variables:
CI_IMAGE: $NODE_IMAGE
CHAIN_NAME: "westend"
CHAIN_URL: "wss://westend-rpc.polkadot.io"
e2e-kusama:
<<: *e2e-template
variables:
CI_IMAGE: $NODE_IMAGE
CHAIN_NAME: "kusama"
CHAIN_URL: "wss://apps-kusama-rpc.polkadot.io"
e2e-polkadot:
<<: *e2e-template
variables:
CI_IMAGE: $NODE_IMAGE
CHAIN_NAME: "polkadot"
CHAIN_URL: "wss://apps-rpc.polkadot.io"
build-docker:
<<: *dockerize
<<: *publish-refs
script:
- echo building "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
- if [[ $BUILD_LATEST_IMAGE ]]; then
$BUILDAH_COMMAND build
--format=docker
--tag "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
--tag "$CONTAINER_REPO:latest" "$DOCKERFILE_DIRECTORY";
else
$BUILDAH_COMMAND build
--format=docker
--tag "$CONTAINER_REPO:$DOCKER_IMAGE_TAG" "$DOCKERFILE_DIRECTORY";
fi
- $BUILDAH_COMMAND info
- echo ${Docker_Hub_Pass_Parity} |
buildah login --username ${Docker_Hub_User_Parity} --password-stdin docker.io
- echo pushing "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
- if [[ $BUILD_LATEST_IMAGE ]]; then
$BUILDAH_COMMAND push --format=v2s2 "$CONTAINER_REPO:$DOCKER_IMAGE_TAG";
$BUILDAH_COMMAND push --format=v2s2 "$CONTAINER_REPO:latest";
else
$BUILDAH_COMMAND push --format=v2s2 "$CONTAINER_REPO:$DOCKER_IMAGE_TAG";
fi
push-docker-image-description:
stage: build
before_script:
- echo
extends:
- .kubernetes-env
variables:
CI_IMAGE: paritytech/dockerhub-description
DOCKERHUB_REPOSITORY: parity/substrate-api-sidecar
DOCKER_USERNAME: $Docker_Hub_User_Parity
DOCKER_PASSWORD: $Docker_Hub_Pass_Parity
README_FILEPATH: $CI_PROJECT_DIR/Dockerfile.README.md
SHORT_DESCRIPTION: "REST service to interact with blockchain nodes built using Substrate's FRAME framework."
rules:
- if: $CI_COMMIT_REF_NAME == "master"
changes:
- Dockerfile.README.md
script:
- cd / && sh entrypoint.sh
# checks that dockerimage can be built without publishing
build-docker-pr:
<<: *dockerize
<<: *test-refs
script:
- echo building "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
- if [[ $BUILD_LATEST_IMAGE ]]; then
$BUILDAH_COMMAND build
--format=docker
--tag "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
--tag "$CONTAINER_REPO:latest" "$DOCKERFILE_DIRECTORY";
else
$BUILDAH_COMMAND build
--format=docker
--tag "$CONTAINER_REPO:$DOCKER_IMAGE_TAG" "$DOCKERFILE_DIRECTORY";
fi
- $BUILDAH_COMMAND info
deploy-staging:
stage: deploy-staging
extends: .deploy-k8s
<<: *publish-refs
environment:
name: parity-stg
variables:
DOMAIN: parity-stg
APP1: substrate-api-sidecar-kusama
APP2: substrate-api-sidecar-polkadot
deploy-production:
stage: deploy-production
extends: .deploy-k8s
environment:
name: parity-chains
variables:
DOMAIN: parity-chains
APP1: substrate-api-sidecar-kusama
APP2: substrate-api-sidecar-polkadot
rules:
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
when: manual
bench-polkadot: &bench-polkadot
stage: benchmark
<<: *kubernetes-env
<<: *collect-artifacts
<<: *publish-refs
variables:
CI_IMAGE: $BENCHMARK_IMAGE
CHAIN_NAME: "polkadot"
CHAIN_URL: "wss://rpc.polkadot.io"
script:
- yarn --immutable
- echo "Benchmarks for ${CHAIN_URL}"
- mkdir -p artifacts
- yarn bench --log-level info --ws-url ${CHAIN_URL}
- mv benchmarks.txt artifacts/
# manual step to run benchmarks in PR pipeline
bench-polkadot-manual-pr:
stage: benchmark
<<: *bench-polkadot
<<: *test-refs-manual
# temporary disabled for collecting results
# check-benchmark:
# stage: check-benchmark
# <<: *publish-refs
# <<: *kubernetes-env
# <<: *collect-artifacts
# needs:
# - job: benchmark
# artifacts: true
# variables:
# GITHUB_REPO: "paritytech/substrate-api-sidecar"
# CI_IMAGE: "paritytech/benchmarks:latest"
# THRESHOLD: 60000
# GITHUB_TOKEN: $GITHUB_PR_TOKEN
# script:
# - export RESULT=$(cat artifacts/result.txt | grep AvgRequestTime | awk '{print $2}')
# - check_single_bench_result -g $GITHUB_REPO
# -c $THRESHOLD
# -v $RESULT
push-benchmark:
stage: push-benchmark
<<: *publish-refs
<<: *kubernetes-env
needs:
- job: bench-polkadot
artifacts: true
variables:
PROMETHEUS_URL: "https://pushgateway.parity-build.parity.io"
CI_IMAGE: "paritytech/benchmarks:latest"
script:
- scripts/ci/benchmarks/push_benchmark_results.sh artifacts/benchmarks.txt