-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.yml
272 lines (234 loc) · 9.17 KB
/
.drone.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
# -----------------------------------------------------------------------------
# SETTINGS
# -----------------------------------------------------------------------------
# Drone matrix: Additional ENV vars for substitution - http://docs.drone.io/matrix-builds/
# Will be evaluated BEFORE the YAML is parsed, ONLY strings allowed, NO substitutions ${XXX} here.
matrix:
include:
- BUILD_ENV: all
# The name of the k8s namespaces that these pipelines will target.
K8S_DEPLOY_NS_DEV: customer-product-dev # TODO: Change me
K8S_DEPLOY_NS_STAGING: customer-product-staging # TODO: Change me
K8S_DEPLOY_NS_PROD: customer-product-prod # TODO: Change me
# YAML Configuration anchors - https://learnxinyminutes.com/docs/yaml/
# Will be evaluated WHILE the YAML is parsed, any valid yaml allowed, substitutions ${XXX} allowed.
alias:
# The image will be tagged with this, pushed to gcr and referenced with this key in the k8s deployment
- &IMAGE_DEPLOY_TAG ${DRONE_COMMIT_SHA}
# The full uniquely tagged image names
- &IMAGE_RUNNER_ID ${DRONE_REPO,,}-${BUILD_ENV}:${DRONE_COMMIT_SHA}
- &IMAGE_BUILDER_ID ${DRONE_REPO,,}-${BUILD_ENV}:${DRONE_COMMIT_SHA}-builder
# Defines which branches will trigger a docker image push our Google Cloud Registry (tags are always published)
- &GCR_PUBLISH_BRANCHES [dev, staging, main]
# Docker registry publish default settings
- &GCR_REGISTRY_SETTINGS
image: plugins/gcr
repo: a3cloud-192413/${DRONE_REPO,,}-${BUILD_ENV}
registry: eu.gcr.io
secrets:
- source: AAA_GCR_SERVICE_ACCOUNT_JSON
target: google_credentials
volumes: # mount needed to push the already build container
- /var/run/docker.sock:/var/run/docker.sock
# As this is a multistage build, we define here what we are going to push
target: runner
# local short-time-cache: don't cleanup any image layers after pushing
purge: false
# force compress of docker build context
compress: true
# Deployment default settings
- &K8S_DEPLOY_SETTINGS
image: eu.gcr.io/a3cloud-192413/aw/aaa-drone-kubernetes:latest
pull: true
secrets:
- source: AAA_K8S_SERVER
target: KUBERNETES_SERVER
- source: AAA_K8S_SERVICE_ACCOUNT_CRT
target: KUBERNETES_CERT
- source: AAA_K8S_SERVICE_ACCOUNT_TOKEN
target: KUBERNETES_TOKEN
- source: AAA_GCR_SERVICE_ACCOUNT_JSON
target: GCR_SERVICE_ACCOUNT
deployment: webapp
repo: eu.gcr.io/a3cloud-192413/${DRONE_REPO,,}-${BUILD_ENV}
container: [webapp]
tag: *IMAGE_DEPLOY_TAG
gcr_service_account_email: drone-ci-a3cloud@a3cloud-192413.iam.gserviceaccount.com
mgmt_repo: https://git.allaboutapps.at/scm/aw/a3cloud-mgmt.git
mgmt_git_email: infrastructure+drone@allaboutapps.at
# Which build events should trigger the main pipeline (defaults to all)
- &BUILD_EVENTS [push, pull_request, tag]
# Pipeline merge helper: only execute if build event received
- &WHEN_BUILD_EVENT
when:
event: *BUILD_EVENTS
- &DOCKER_BUILD_SETTINGS_RUNNER
image: docker:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
IMAGE_TAG: *IMAGE_RUNNER_ID
commands:
- |
docker build -t $${IMAGE_TAG} . --build-arg VITE_COMMIT_HASH=${DRONE_BRANCH}_${DRONE_COMMIT_SHA:0:10}
- &DOCKER_BUILD_SETTINGS_BUILDER
image: docker:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
IMAGE_TAG: *IMAGE_BUILDER_ID
commands:
- |
docker build --target builder -t $${IMAGE_TAG} . --build-arg VITE_COMMIT_HASH=${DRONE_BRANCH}_${DRONE_COMMIT_SHA:0:10}
# The actual pipeline building our product
pipeline:
# ---------------------------------------------------------------------------
# PRE BUILD
# ---------------------------------------------------------------------------
"docker build (target builder)":
group: pre-build
<<: *DOCKER_BUILD_SETTINGS_BUILDER
when:
event: *BUILD_EVENTS
# ---------------------------------------------------------------------------
# BUILD
# ---------------------------------------------------------------------------
"docker build (target runner)":
group: build
<<: *DOCKER_BUILD_SETTINGS_RUNNER
when:
event: *BUILD_EVENTS
# ---------------------------------------------------------------------------
# CHECK
# ---------------------------------------------------------------------------
"lint":
group: check
image: *IMAGE_BUILDER_ID
commands:
- cd /app
- yarn lint
<<: *WHEN_BUILD_EVENT
# ---------------------------------------------------------------------------
# TEST COMPONENTS
# ---------------------------------------------------------------------------
"test:components":
group: test
image: *IMAGE_BUILDER_ID
commands:
- cd /app
- yarn test:ci
<<: *WHEN_BUILD_EVENT
# ---------------------------------------------------------------------------
# TEST E2E
# ---------------------------------------------------------------------------
# If you enable E2E tests don't forget to also uncomment the line in the Dockerfile
# which installs the Cypress dependencies.
# "test:e2e":
# group: test
# image: *IMAGE_BUILDER_ID
# commands:
# - cd /app
# - yarn test:e2e
# <<: *WHEN_BUILD_EVENT
# ---------------------------------------------------------------------------
# PUBLISH
# ---------------------------------------------------------------------------
# Built a branch? Push to cloud registry
"publish ${DRONE_BRANCH}_${DRONE_COMMIT_SHA:0:10}":
group: publish
<<: *GCR_REGISTRY_SETTINGS
tags:
- build_${DRONE_BUILD_NUMBER}
- ${DRONE_BRANCH}_${DRONE_COMMIT_SHA:0:10}
- *IMAGE_DEPLOY_TAG
- latest
- ${DRONE_BRANCH}
- '${DRONE_COMMIT_SHA:0:10}'
when:
branch: *GCR_PUBLISH_BRANCHES
event: *BUILD_EVENTS
# Built a tag? Push to cloud registry
"publish tag_${DRONE_COMMIT_SHA:0:10}":
group: publish
<<: *GCR_REGISTRY_SETTINGS
tags:
- build_${DRONE_BUILD_NUMBER}
- tag_${DRONE_COMMIT_SHA:0:10}
- *IMAGE_DEPLOY_TAG
- latest
- ${DRONE_TAG}
- '${DRONE_COMMIT_SHA:0:10}'
when:
event: tag
# ---------------------------------------------------------------------------
# DEPLOYMENT
# ---------------------------------------------------------------------------
# -----------------
# DEPLOYMENT DEV --
# -----------------
# autodeploy if it hits the branch
"deploy ${DRONE_COMMIT_SHA:0:10} to ${K8S_DEPLOY_NS_DEV} (auto)":
<<: *K8S_DEPLOY_SETTINGS
namespace: ${K8S_DEPLOY_NS_DEV}
mgmt_deployment_yaml: namespaces/${K8S_DEPLOY_NS_DEV}/webapp.deployment.yaml
when:
branch: dev
event: *BUILD_EVENTS
# promote dev through "drone deploy <repo> <build> <env>" or "woodpecker-cli deploy <repo> <build> <env>"
"deploy ${DRONE_COMMIT_SHA:0:10} to ${K8S_DEPLOY_NS_DEV} (promote)":
<<: *K8S_DEPLOY_SETTINGS
namespace: ${K8S_DEPLOY_NS_DEV}
mgmt_deployment_yaml: namespaces/${K8S_DEPLOY_NS_DEV}/webapp.deployment.yaml
when:
environment: ${BUILD_ENV}
event: deployment
# ---------------------
# DEPLOYMENT STAGING --
# ---------------------
# autodeploy if it hits the branch
"deploy ${DRONE_COMMIT_SHA:0:10} to ${K8S_DEPLOY_NS_STAGING} (auto)":
<<: *K8S_DEPLOY_SETTINGS
namespace: ${K8S_DEPLOY_NS_STAGING}
mgmt_deployment_yaml: namespaces/${K8S_DEPLOY_NS_STAGING}/webapp.deployment.yaml
when:
branch: staging
event: *BUILD_EVENTS
# promote staging through "drone deploy <repo> <build> <env>" or "woodpecker-cli deploy <repo> <build> <env>"
"deploy ${DRONE_COMMIT_SHA:0:10} to ${K8S_DEPLOY_NS_STAGING} (promote)":
<<: *K8S_DEPLOY_SETTINGS
namespace: ${K8S_DEPLOY_NS_STAGING}
mgmt_deployment_yaml: namespaces/${K8S_DEPLOY_NS_STAGING}/webapp.deployment.yaml
when:
environment: ${BUILD_ENV}
event: deployment
# ------------------
# DEPLOYMENT PROD --
# ------------------
# Note: Normally we don't autodeploy production for security reasons.
# If you want to autodeploy prod make sure to discuss this with the team first.
#
# autodeploy if it hits the branch
# "deploy ${DRONE_COMMIT_SHA:0:10} to ${K8S_DEPLOY_NS_PROD} (auto)":
# <<: *K8S_DEPLOY_SETTINGS
# namespace: ${K8S_DEPLOY_NS_PROD}
# mgmt_deployment_yaml: namespaces/${K8S_DEPLOY_NS_PROD}/webapp.deployment.yaml
# when:
# branch: staging
# event: *BUILD_EVENTS
# promote production through "drone deploy <repo> <build> <env>" or "woodpecker-cli deploy <repo> <build> <env>"
"deploy ${DRONE_COMMIT_SHA:0:10} to ${K8S_DEPLOY_NS_PROD} (promote)":
<<: *K8S_DEPLOY_SETTINGS
namespace: ${K8S_DEPLOY_NS_PROD}
mgmt_deployment_yaml: namespaces/${K8S_DEPLOY_NS_PROD}/webapp.deployment.yaml
when:
environment: ${BUILD_ENV}
event: deployment
# Long living services where the startup order does not matter (otherwise use detach: true)
services:
# ---------------------------------------------------------------------------
# SERVICES
# ---------------------------------------------------------------------------
"env":
image: alpine
commands:
- "env | sort"