forked from paritytech/substrate-telemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
242 lines (222 loc) · 8.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
# Gitlab-CI Workflow
# stages:
# build:
# - Runs on commits on master or tags that match the pattern "v[0-9]+\.[0-9]+.*$". (e.g. 1.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:
# Build Variables (Mandatory)
CONTAINER_REPO: ""
DOCKERFILE_DIRECTORY: ""
# Deploy Variables (Mandatory)
HELM_NAMESPACE: "substrate-telemetry"
HELM_RELEASE_NAME: "substrate-telemetry"
HELM_CHART: "parity/substrate-telemetry"
# Deploy Variables (Optional)
HELM_REPO_NAME: "parity"
HELM_REPO_URL: "https://paritytech.github.io/helm-charts/"
HELM_CONFIGMAP_NAME: "helm-custom-values"
HELM_CONFIGMAP_KEYNAME: "values-parity.yaml"
# Manual Variables (Optional)
## Could be used in the webconsole when triggering the pipeline manually
## DO NOT SET THEM IN THIS FILE!! They've been mentioned here only for documentation purposes!
FORCE_DEPLOY: "" # boolean: true or false - triggers the deploy-production stage
FORCE_DOCKER_TAG: "" # choose an existing docker tag to be deployed (e.g. v1.2.3)
BUILDAH_IMAGE: "quay.io/buildah/stable:v1.29"
BUILDAH_COMMAND: "buildah --storage-driver overlay2"
default:
before_script:
- |-
echo defining DOCKER_IMAGE_TAG variable
if [[ $FORCE_DOCKER_TAG ]]; then
export DOCKER_IMAGE_TAG="${FORCE_DOCKER_TAG}"
elif [[ $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
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
stages:
- build
- deploy-commit-to-staging
- deploy-master-to-staging
- deploy-production
# Pipeline Job Templates:
.dockerize: &dockerize
stage: build
image: $BUILDAH_IMAGE
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
- echo ${DOCKER_PASSWORD} |
buildah login --username ${DOCKER_USERNAME} --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
rules:
- if: '$FORCE_DOCKER_TAG'
when: never
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+.*$/' # i.e. v1.0, v2.1rc1
when: always
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: always
tags:
- kubernetes-parity-build
.publish-docker-image-description:
stage: build
image: paritytech/dockerhub-description
before_script:
- echo
variables:
DOCKERHUB_REPOSITORY: parity/substrate-telemetry-$PRODUCT
DOCKER_USERNAME: $Docker_Hub_User_Parity
DOCKER_PASSWORD: $Docker_Hub_Pass_Parity
README_FILEPATH: $CI_PROJECT_DIR/$PRODUCT/Dockerfile.README.md
rules:
- if: $CI_COMMIT_REF_NAME == "master"
changes:
- $PRODUCT/Dockerfile.README.md
script:
- cd / && sh entrypoint.sh
tags:
- kubernetes-parity-build
.deploy: &deploy
image: paritytech/kubetools:3.5.3
script:
- |-
echo generating an empty custom-values.yaml file
touch custom-values.yaml
- |-
echo fetching the custom values file from the configmap if HELM_CONFIGMAP_NAME is specified
if [[ $HELM_CONFIGMAP_NAME ]]; then
# escape dot characters
HELM_CONFIGMAP_KEYNAME=`echo $HELM_CONFIGMAP_KEYNAME | sed 's/\./\\\./g'`
kubectl get cm $HELM_CONFIGMAP_NAME -n $HELM_NAMESPACE -o jsonpath="{.data.$HELM_CONFIGMAP_KEYNAME}" \
> custom-values.yaml
fi
- |-
echo adding the helm repository if HELM_REPO_URL is specified
if [[ $HELM_REPO_URL ]]; then
helm repo add $HELM_REPO_NAME $HELM_REPO_URL
helm repo update
fi
- echo installing the helm chart
- helm upgrade
--install
--atomic
--timeout 300s
--namespace $HELM_NAMESPACE
--values custom-values.yaml
--set image.backend.repository="${CONTAINER_REPO_BACKEND}"
--set image.backend.tag="${DOCKER_IMAGE_TAG}"
--set image.frontend.repository="${CONTAINER_REPO_FRONTEND}"
--set image.frontend.tag="${DOCKER_IMAGE_TAG}"
${HELM_RELEASE_NAME} ${HELM_CHART}
tags:
- kubernetes-parity-build
# Pipeline Jobs:
build-backend:
variables:
CONTAINER_REPO: "docker.io/parity/substrate-telemetry-backend"
DOCKERFILE_DIRECTORY: "./backend/"
DOCKER_USERNAME: $Docker_Hub_User_Parity
DOCKER_PASSWORD: $Docker_Hub_Pass_Parity
<<: *dockerize
build-frontend:
variables:
CONTAINER_REPO: "docker.io/parity/substrate-telemetry-frontend"
DOCKERFILE_DIRECTORY: "./frontend/"
DOCKER_USERNAME: $Docker_Hub_User_Parity
DOCKER_PASSWORD: $Docker_Hub_Pass_Parity
<<: *dockerize
publish-backend-docker-image-description:
extends: .publish-docker-image-description
variables:
PRODUCT: backend
SHORT_DESCRIPTION: "substrate-backend Docker Image."
publish-frontend-docker-image-description:
extends: .publish-docker-image-description
variables:
PRODUCT: frontend
SHORT_DESCRIPTION: "substrate-frontend Docker Image."
# Manually build the docker images and deploy some commit to staging.
build-backend-manual:
variables:
CONTAINER_REPO: "docker.io/paritypr/substrate-telemetry-backend"
DOCKERFILE_DIRECTORY: "./backend/"
DOCKER_USERNAME: $PARITYPR_USER
DOCKER_PASSWORD: $PARITYPR_PASS
<<: *dockerize
rules:
- if: '$CI_COMMIT_BRANCH =~ /^[0-9]+/'
when: manual
build-frontend-manual:
variables:
CONTAINER_REPO: "docker.io/paritypr/substrate-telemetry-frontend"
DOCKERFILE_DIRECTORY: "./frontend/"
DOCKER_USERNAME: $PARITYPR_USER
DOCKER_PASSWORD: $PARITYPR_PASS
<<: *dockerize
rules:
- if: '$CI_COMMIT_BRANCH =~ /^[0-9]+/'
when: manual
deploy-commit-to-staging:
variables:
CONTAINER_REPO_BACKEND: "docker.io/paritypr/substrate-telemetry-backend"
CONTAINER_REPO_FRONTEND: "docker.io/paritypr/substrate-telemetry-frontend"
stage: deploy-commit-to-staging
<<: *deploy
environment:
name: parity-stg
rules:
- if: '$CI_COMMIT_BRANCH =~ /^[0-9]+/'
when: manual
# Automatically deploy `master` branch or tag like `v1.0` to staging
deploy-master-to-staging:
variables:
CONTAINER_REPO_BACKEND: "docker.io/parity/substrate-telemetry-backend"
CONTAINER_REPO_FRONTEND: "docker.io/parity/substrate-telemetry-frontend"
stage: deploy-master-to-staging
<<: *deploy
environment:
name: parity-stg
rules:
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+.*$/' # i.e. v1.0, v2.1rc1
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
# Manually deploy a tag like `v1.0` to production
deploy-production:
variables:
CONTAINER_REPO_BACKEND: "docker.io/parity/substrate-telemetry-backend"
CONTAINER_REPO_FRONTEND: "docker.io/parity/substrate-telemetry-frontend"
stage: deploy-production
<<: *deploy
environment:
name: parity-prod
rules:
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+.*$/' # i.e. v1.0, v2.1rc1
when: manual
- if: '$FORCE_DEPLOY == "true"'
when: manual