forked from grafana/oncall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.yml
334 lines (306 loc) · 9.48 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
---
kind: pipeline
type: docker
name: Build and Release
steps:
- name: Build Plugin
image: node:18.16.0-buster
commands:
- apt-get update
- apt-get --assume-yes install jq
- cd grafana-plugin/
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else jq ".version=\"${DRONE_TAG#v}\"" package.json > package.new && mv package.new package.json && jq '.version' package.json; fi
# yamllint enable rule:line-length
- yarn --network-timeout 500000
- yarn build
- ls ./
- name: Sign and Package Plugin
image: node:18.16.0-buster
environment:
GRAFANA_API_KEY:
from_secret: gcom_plugin_publisher_api_key
depends_on:
- Build Plugin
commands:
- apt-get update
- apt-get install zip
- cd grafana-plugin
- yarn sign
- if [ ! -f dist/MANIFEST.txt ]; then echo "Sign failed, MANIFEST.txt not created, aborting." && exit 1; fi
- yarn ci-build:finish
- yarn ci-package
- cd ci/dist
- zip -r grafana-oncall-app.zip ./grafana-oncall-app
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, skipping archive"; else cp grafana-oncall-app.zip grafana-oncall-app-${DRONE_TAG}.zip; fi
# yamllint enable rule:line-length
- name: Publish Plugin to GCS (release)
image: plugins/gcs
settings:
acl: allUsers:READER
source: grafana-plugin/ci/dist/grafana-oncall-app-${DRONE_TAG}.zip
target: grafana-oncall-app/releases/grafana-oncall-app-${DRONE_TAG}.zip
token:
from_secret: gcs_oncall_publisher_key
depends_on:
- Sign and Package Plugin
when:
ref:
- refs/tags/v*.*.*
- name: Lint Backend
image: python:3.11.4
environment:
DJANGO_SETTINGS_MODULE: settings.ci-test
commands:
- pip install $(grep "pre-commit" engine/requirements-dev.txt)
- pre-commit run isort --all-files
- pre-commit run black --all-files
- pre-commit run flake8 --all-files
- name: Unit Test Backend
image: python:3.11.4
environment:
RABBITMQ_URI: amqp://rabbitmq:rabbitmq@rabbit_test:5672
DJANGO_SETTINGS_MODULE: settings.ci-test
SLACK_CLIENT_OAUTH_ID: 1
commands:
- apt-get update && apt-get install -y netcat-traditional
- cd engine/
- pip install -r requirements.txt -r requirements-dev.txt
- ./wait_for_test_mysql_start.sh && pytest
depends_on:
- rabbit_test
- name: Image Tag
image: alpine
commands:
- apk add --no-cache bash git sed
- git fetch origin --tags
- chmod +x ./tools/image-tag.sh
- echo $(./tools/image-tag.sh)
- echo $(./tools/image-tag.sh) > .tags
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else sed "0,/VERSION.*/ s/VERSION.*/VERSION = \"${DRONE_TAG}\"/g" engine/settings/base.py > engine/settings/base.temp && mv engine/settings/base.temp engine/settings/base.py; fi
# yamllint enable rule:line-length
- cat engine/settings/base.py | grep VERSION | head -1
when:
ref:
- refs/heads/dev
- refs/tags/v*.*.*
- name: Build and Push Engine Docker Image Backend to GCR
image: plugins/docker
environment:
# force docker to use buildkit feature, this will skip build stages that aren't required in
# the final image (ie. dev & dev-enterprise)
# https://github.com/docker/cli/issues/1134#issuecomment-406449342
DOCKER_BUILDKIT: 1
settings:
repo: us.gcr.io/kubernetes-dev/oncall
dockerfile: engine/Dockerfile
context: engine/
target: prod
config:
from_secret: gcr_admin
depends_on:
- Lint Backend
- Unit Test Backend
- Image Tag
- name: Build and Push Engine Docker Image Backend to Dockerhub
image: plugins/docker
environment:
# force docker to use buildkit feature, this will skip build stages that aren't required in
# the final image (ie. dev & dev-enterprise)
# https://github.com/docker/cli/issues/1134#issuecomment-406449342
DOCKER_BUILDKIT: 1
settings:
repo: grafana/oncall
dockerfile: engine/Dockerfile
context: engine/
target: prod
password:
from_secret: docker_password
username:
from_secret: docker_username
depends_on:
- Lint Backend
- Unit Test Backend
- Image Tag
when:
ref:
- refs/heads/dev
# Services for Unit Test Backend
services:
- name: rabbit_test
image: rabbitmq:3.12.0
environment:
RABBITMQ_DEFAULT_USER: rabbitmq
RABBITMQ_DEFAULT_PASS: rabbitmq
- name: mysql_test
image: mysql:8.0.32
environment:
MYSQL_DATABASE: oncall_local_dev
MYSQL_ROOT_PASSWORD: local_dev_pwd
trigger:
event:
include:
- tag
- push
- pull_request
ref:
include:
- refs/heads/main
- refs/heads/dev
- refs/tags/v*.*.*
---
kind: pipeline
type: docker
name: OSS plugin release
steps:
- name: build plugin
image: node:18.16.0-buster
commands:
- apt-get update
- apt-get --assume-yes install jq
- cd grafana-plugin/
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else jq ".version=\"${DRONE_TAG#v}\"" package.json > package.new && mv package.new package.json && jq '.version' package.json; fi
# yamllint enable rule:line-length
- yarn --network-timeout 500000
- yarn build
- ls ./
- name: sign and package plugin
image: node:18.16.0-buster
environment:
GRAFANA_API_KEY:
from_secret: gcom_plugin_publisher_api_key
depends_on:
- build plugin
commands:
- apt-get update
- apt-get install zip
- cd grafana-plugin
- yarn sign
- if [ ! -f dist/MANIFEST.txt ]; then echo "Sign failed, MANIFEST.txt not created, aborting." && exit 1; fi
- yarn ci-build:finish
- yarn ci-package
- cd ci/dist
- zip -r grafana-oncall-app.zip ./grafana-oncall-app
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, skipping archive"; else cp grafana-oncall-app.zip grafana-oncall-app-${DRONE_TAG}.zip; fi
# yamllint enable rule:line-length
- name: publish plugin to grafana.com (release)
image: curlimages/curl:7.73.0
environment:
GRAFANA_API_KEY:
from_secret: gcom_plugin_publisher_api_key
commands:
# yamllint disable rule:line-length
- 'curl -f -s -H "Authorization: Bearer $${GRAFANA_API_KEY}" -d "download[any][url]=https://storage.googleapis.com/grafana-oncall-app/releases/grafana-oncall-app-${DRONE_TAG}.zip" -d "download[any][md5]=$$(curl -sL https://storage.googleapis.com/grafana-oncall-app/releases/grafana-oncall-app-${DRONE_TAG}.zip | md5sum | cut -d'' '' -f1)" -d url=https://github.com/grafana/oncall/grafana-plugin https://grafana.com/api/plugins'
# yamllint enable rule:line-length
depends_on:
- sign and package plugin
trigger:
event:
- promote
target:
- oss
ref:
- refs/tags/v*.*.*
---
kind: pipeline
type: docker
name: OSS engine release
steps:
- name: set engine version
image: alpine
commands:
- apk add --no-cache bash sed
# yamllint disable rule:line-length
- if [ -z "$DRONE_TAG" ]; then echo "No tag, not modifying version"; else sed "0,/VERSION.*/ s/VERSION.*/VERSION = \"${DRONE_TAG#v}\"/g" engine/settings/base.py > engine/settings/base.temp && mv engine/settings/base.temp engine/settings/base.py; fi
# yamllint enable rule:line-length
- cat engine/settings/base.py | grep VERSION | head -1
- name: build and push docker image
image: thegeeklab/drone-docker-buildx:24.1.0
# From the docs (https://drone-plugin-index.geekdocs.de/plugins/drone-docker-buildx/) regarding privileged=true:
#
# Be aware that the this plugin requires privileged capabilities, otherwise the integrated
# Docker daemon is not able to start.
privileged: true
settings:
repo: grafana/oncall
tags: latest,${DRONE_TAG}
platforms: linux/arm64/v8,linux/amd64
dockerfile: engine/Dockerfile
target: prod
context: engine/
password:
from_secret: docker_password
username:
from_secret: docker_username
depends_on:
- set engine version
trigger:
event:
- promote
target:
- oss
ref:
- refs/tags/v*.*.*
---
# Secret for pulling docker images.
kind: secret
name: dockerconfigjson
get:
path: secret/data/common/gcr
name: .dockerconfigjson
---
# Secret for pushing docker images.
kind: secret
name: gcr_admin
get:
path: infra/data/ci/gcr-admin
name: .dockerconfigjson
---
# Slack webhook
get:
name: slack-plugin
path: infra/data/ci/oncall/drone
kind: secret
name: slack_webhook
---
# GCOM plugin publisher
get:
name: gcom-plugin-publisher
path: infra/data/ci/oncall/drone
kind: secret
name: gcom_plugin_publisher_api_key
---
# GCS bucket
get:
name: gcs-oncall-drone-publisher
path: infra/data/ci/oncall/drone
kind: secret
name: gcs_oncall_publisher_key
---
# Dockerhub
get:
name: username
path: infra/data/ci/docker_hub
kind: secret
name: docker_username
---
get:
name: password
path: infra/data/ci/docker_hub
kind: secret
name: docker_password
---
# Drone
get:
name: machine-user-token
path: infra/data/ci/drone
kind: secret
name: drone_token
---
kind: signature
hmac: 8b387638ef35f86ed9f8c8c964726e0ae703beb7d0f18e053b5041ab8ee9bed2
...