-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
281 lines (262 loc) · 6.94 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
274
275
276
277
278
279
280
281
variables:
GKE_PROJECT: coinninja01
GKE_INSTANCE: coinninja01
GKE_ZONE: us-central1-c
GKE_APP_TYPE: deployment
GKE_CONTAINER_NAME: blocc
DOCKER_TLS_CERTDIR: ""
stages:
- test
- build
- testing
- production
test:
stage: test
image: golang:1.13-alpine3.10
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .cache
script:
- apk add --update-cache make git protobuf protobuf-dev curl
- mkdir -p .cache
- export GOPATH="$CI_PROJECT_DIR/.cache"
- export GOPRIVATE=git.coinninja.net
- export PATH=$PATH:$GOPATH/bin
- CGO_ENABLED=0 make test
.build: &build
allow_failure: false
services:
- docker:dind
image: docker:stable
before_script:
- export DOCKER_HOST=${CI_SERVICE_HOST:-docker} # Hack to fix kube runner
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build --build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN --pull --tag $CONTAINER_NAME .
- docker push $CONTAINER_NAME
build:branch:
<<: *build
stage: build
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
when: manual
only:
- branches@backend/blocc
except:
- master
- develop
- tags
build:latest:
<<: *build
stage: build
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:latest
only:
- develop@backend/blocc
build:tagged:
<<: *build
stage: build
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags@backend/blocc
except:
- branches
# Common k8s elements
.k8s: &k8s
image: google/cloud-sdk:latest
allow_failure: false
before_script:
- echo -n "${__k8s_prod_sa_key}" | base64 -d > /tmp/key.json
- gcloud auth activate-service-account --key-file /tmp/key.json
- gcloud config set project ${GKE_PROJECT}
- gcloud config set compute/zone ${GKE_ZONE}
- gcloud container clusters get-credentials ${GKE_INSTANCE}
- kubectl config current-context
script: |
export CURRENT_IMAGE=$(kubectl -n ${CI_ENVIRONMENT_SLUG} get ${GKE_APP_TYPE} ${GKE_APP_NAME} -o=jsonpath='{$.spec.template.spec.containers[0].image}')
if [[ "${CURRENT_IMAGE}" != "${CONTAINER_NAME}" ]]; then
echo "current image '${CURRENT_IMAGE}' is not '${CONTAINER_NAME}'"
kubectl -n ${CI_ENVIRONMENT_SLUG} set image ${GKE_APP_TYPE}/${GKE_APP_NAME} ${GKE_CONTAINER_NAME}=${CONTAINER_NAME} --record
else
echo "current image '${CURRENT_IMAGE}' is correct. Patching..."
kubectl --namespace=${CI_ENVIRONMENT_SLUG} patch ${GKE_APP_TYPE} ${GKE_APP_NAME} -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}" --record
fi
kubectl -n ${CI_ENVIRONMENT_SLUG} rollout status ${GKE_APP_TYPE} ${GKE_APP_NAME} -w
development:branch-server:
<<: *k8s
stage: testing
environment:
name: dev
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
GKE_APP_NAME: blocc-server
GKE_PROJECT: coinninja-dev
GKE_INSTANCE: dev-01
when: manual
only:
- branches@backend/blocc
except:
- master
- develop
development:branch-block:
<<: *k8s
stage: testing
environment:
name: indexer
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
GKE_APP_NAME: blocc-btc-block
GKE_PROJECT: coinninja-dev
GKE_INSTANCE: dev-01
when: manual
only:
- branches@backend/blocc
except:
- master
- develop
development:branch-transaction:
<<: *k8s
stage: testing
environment:
name: indexer
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
GKE_APP_NAME: blocc-btc-transaction
GKE_PROJECT: coinninja-dev
GKE_INSTANCE: dev-01
when: manual
only:
- branches@backend/blocc
except:
- master
- develop
development:latest-server:
<<: *k8s
stage: testing
environment:
name: dev
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:latest
GKE_APP_NAME: blocc-server
GKE_PROJECT: coinninja-dev
GKE_INSTANCE: dev-01
when: manual
only:
- develop@backend/blocc
development:latest-block:
<<: *k8s
stage: testing
environment:
name: indexer
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:latest
GKE_APP_NAME: blocc-btc-block
GKE_PROJECT: coinninja-dev
GKE_INSTANCE: dev-01
when: manual
only:
- develop@backend/blocc
development:latest-transaction:
<<: *k8s
stage: testing
environment:
name: indexer
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:latest
GKE_APP_NAME: blocc-btc-transaction
GKE_PROJECT: coinninja-dev
GKE_INSTANCE: dev-01
when: manual
only:
- develop@backend/blocc
testing:branch-server:
<<: *k8s
stage: testing
environment:
name: test
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
GKE_APP_NAME: blocc-server
when: manual
only:
- branches@backend/blocc
except:
- master
- develop
testing:latest-server:
<<: *k8s
stage: testing
environment:
name: test
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:latest
GKE_APP_NAME: blocc-server
when: manual
only:
- develop@backend/blocc
testing:tag-server:
<<: *k8s
stage: testing
environment:
name: test
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
GKE_APP_NAME: blocc-server
when: manual
only:
- tags@backend/blocc
except:
- branches
production:tag-server:
<<: *k8s
stage: production
environment:
name: prod
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
GKE_APP_NAME: blocc-server
when: manual
only:
- tags@backend/blocc
except:
- branches
production:tag-block:
<<: *k8s
stage: production
environment:
name: indexer
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
GKE_APP_NAME: blocc-btc-block
when: manual
only:
- tags@backend/blocc
except:
- branches
production:tag-transaction:
<<: *k8s
stage: production
environment:
name: indexer
url: https://api.${CI_ENVIRONMENT_SLUG}.coinninja.net/api/v1/blocc/version
variables:
CONTAINER_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
GKE_APP_NAME: blocc-btc-transaction
when: manual
only:
- tags@backend/blocc
except:
- branches