-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
211 lines (186 loc) · 6.22 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
variables:
AUTO_DEPLOY_IMAGE_VERSION: "v2.104.0"
CI_TEMPLATE_REGISTRY_HOST: registry.gitlab.com
KUBE_CONTEXT: govtool-outcomes-backend
HELM_VERSION: 3.10.2
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DEPLOY_WEBSITE:
value: "true"
description: "Build and deploy outcomes.1694.io"
stages:
- .pre
- test
- build
- preview
- sancho
- mainnet
default:
services:
- name: docker:dind
alias: docker
command: ["--tls=false"]
before_script:
- |
export APP_VERSION=$(awk '/version/{gsub(/("|",)/,"",$2);print $2};' backend/package.json)
export APP_VERSION_AND_BUILD="${APP_VERSION}-${CI_PIPELINE_ID}"
export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE
export CI_APPLICATION_TAG=$APP_VERSION_AND_BUILD
.setup: &setup
- apk add --no-cache ca-certificates curl bash openssl git
- curl -LO https://dl.k8s.io/release/v1.25.9/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/kubectl
- curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 && chmod 700 get_helm.sh && DESIRED_VERSION=v$HELM_VERSION ./get_helm.sh
- kubectl config get-contexts
yarn:
image: node:20.18.0-alpine
stage: .pre
services: []
retry: 1
rules:
- if: '$DEPLOY_WEBSITE == "true"'
before_script:
- apk add --update curl && rm -rf /var/cache/apk/*
script: |-
set -vx
export PATH=$PATH:/usr/local/bin
export NODE_OPTIONS=--max-old-space-size=8192
cd ./backend
yarn install --ignore-engines
yarn run build
cd ../ui
yarn install --ignore-engines
yarn run build
artifacts:
paths:
- ./backend/dist
- ./ui/dist
expire_in: 1 days
test_outcomes:
image: node:20.18.0-alpine
services: []
retry: 1
stage: test
script:
- cd backend
- yarn install --ignore-engines
- NODE_ENV=test yarn test
rules:
- if: '$DEPLOY_WEBSITE == "true"'
allow_failure: true
build_backend:
stage: build
image: docker:24.0.2-git
retry: 1
script:
- |
set -xev
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
echo "Building Dockerfile with tags $CI_APPLICATION_REPOSITORY/outcomes.1694.io:$CI_APPLICATION_TAG and $CI_APPLICATION_REPOSITORY/outcomes.1694.io:latest ..."
docker build --network host -f backend/Dockerfile \
-t "$CI_APPLICATION_REPOSITORY/outcomes.1694.io:$CI_APPLICATION_TAG" \
-t "$CI_APPLICATION_REPOSITORY/outcomes.1694.io:latest" ./backend
docker push "$CI_APPLICATION_REPOSITORY/outcomes.1694.io:$CI_APPLICATION_TAG"
docker push "$CI_APPLICATION_REPOSITORY/outcomes.1694.io:latest"
rules:
- if: '$DEPLOY_WEBSITE == "true"'
build_govtool:
stage: build
image: docker:24.0.2-git
retry: 1
script:
- |
set -xev
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
echo "Building Dockerfile with tags $CI_APPLICATION_REPOSITORY/govtool:$CI_APPLICATION_TAG and $CI_APPLICATION_REPOSITORY/govtool:latest ..."
docker build --network host -f Dockerfile.govtool \
--build-arg CARDANO_NETWORK="$CARDANO_NETWORK" \
-t "$CI_APPLICATION_REPOSITORY/govtool:$CI_APPLICATION_TAG" \
-t "$CI_APPLICATION_REPOSITORY/govtool:latest" .
docker push "$CI_APPLICATION_REPOSITORY/govtool:$CI_APPLICATION_TAG"
docker push "$CI_APPLICATION_REPOSITORY/govtool:latest"
rules:
- if: '$DEPLOY_WEBSITE == "true"'
.outcomes_backend_deployment: &outcomes_backend_deployment
image: "${CI_TEMPLATE_REGISTRY_HOST}/gitlab-org/cluster-integration/auto-deploy-image:${AUTO_DEPLOY_IMAGE_VERSION}"
script:
- *setup
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy create_secret
- |
# Set secrets
cp "$ENV_FILE" ./charts/backend/app_env
cat ./charts/backend/app_env
echo "$INGRESS_HOST" "$NAMESPACE"
DEPLOYMENT_NAME="outcomes-$CI_ENVIRONMENT_SLUG"
echo "Install govtool-outcomes-backend"
helm upgrade $DEPLOYMENT_NAME ./charts/backend \
--install \
--timeout 300s \
--wait \
--atomic \
--namespace="$NAMESPACE" \
--create-namespace \
-f ./charts/values.yaml \
--set namespace=$NAMESPACE \
--set ingress.hosts[0]=$INGRESS_HOST \
--set image.backend.tag=$CI_APPLICATION_TAG \
--set cardano_node[0].tcp_host=$NODE_TCP_HOST \
--set cardano_node[0].tcp_port=$NODE_TCP_PORT
rules:
- if: '$DEPLOY_WEBSITE == "true"'
.outcomes_govtool_deployment: &outcomes_govtool_deployment
image: "${CI_TEMPLATE_REGISTRY_HOST}/gitlab-org/cluster-integration/auto-deploy-image:${AUTO_DEPLOY_IMAGE_VERSION}"
script:
- *setup
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy create_secret
- |
DEPLOYMENT_NAME="govtool-frontend-$CI_ENVIRONMENT_SLUG"
helm upgrade $DEPLOYMENT_NAME ./charts/govtool \
--install \
--timeout 300s \
--wait \
--atomic \
--namespace="$NAMESPACE" \
--create-namespace \
-f ./charts/values.yaml \
--set namespace=$NAMESPACE \
--set image.govtool.tag=$CI_APPLICATION_TAG \
--set ingress.hosts[0]=$INGRESS_HOST
rules:
- if: '$DEPLOY_WEBSITE == "true"'
outcomes_preview_backend:
<<: *outcomes_backend_deployment
stage: preview
environment:
name: preview
url: https://$CI_PROJECT_PATH_SLUG.$AUTO_DEVOPS_DOMAIN
when: manual
outcomes_preview_govtool:
<<: *outcomes_govtool_deployment
stage: preview
environment:
name: preview
url: https://$CI_PROJECT_PATH_SLUG.$AUTO_DEVOPS_DOMAIN
when: manual
outcomes_mainnet_backend:
<<: *outcomes_backend_deployment
stage: mainnet
rules:
- if: $CI_COMMIT_BRANCH == "beta" || $CI_COMMIT_BRANCH == "main"
environment:
name: mainnet
url: https://$CI_PROJECT_PATH_SLUG.$AUTO_DEVOPS_DOMAIN
when: manual
outcomes_mainnet_govtool:
<<: *outcomes_govtool_deployment
stage: mainnet
rules:
- if: $CI_COMMIT_BRANCH == "beta" || $CI_COMMIT_BRANCH == "main"
environment:
name: mainnet
url: https://$CI_PROJECT_PATH_SLUG.$AUTO_DEVOPS_DOMAIN
when: manual