forked from paritytech/substrate-telemetry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
181 lines (166 loc) · 6.26 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
# 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)
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: quay.io/buildah/stable
script:
- |-
echo building "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
if [[ $BUILD_LATEST_IMAGE ]]; then
buildah bud \
--format=docker \
--tag "$CONTAINER_REPO:$DOCKER_IMAGE_TAG" \
--tag "$CONTAINER_REPO:latest" "$DOCKERFILE_DIRECTORY"
else
buildah bud \
--format=docker \
--tag "$CONTAINER_REPO:$DOCKER_IMAGE_TAG" "$DOCKERFILE_DIRECTORY"
fi
- 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 push --format=v2s2 "$CONTAINER_REPO:$DOCKER_IMAGE_TAG"
buildah push --format=v2s2 "$CONTAINER_REPO:latest"
else
buildah 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
.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/"
<<: *dockerize
build-frontend:
variables:
CONTAINER_REPO: "docker.io/parity/substrate-telemetry-frontend"
DOCKERFILE_DIRECTORY: "./frontend/"
<<: *dockerize
# Manually build the docker images and deploy some commit to staging.
deploy-commit-to-staging:
variables:
CONTAINER_REPO_BACKEND: "docker.io/parity/substrate-telemetry-backend"
CONTAINER_REPO_FRONTEND: "docker.io/parity/substrate-telemetry-frontend"
stage: deploy-commit-to-staging
<<: *deploy
environment:
name: parity-stg
when: manual
# Autoamtically 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