-
Notifications
You must be signed in to change notification settings - Fork 3
/
.drone.jsonnet
384 lines (350 loc) · 10.4 KB
/
.drone.jsonnet
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
// this file is based on the one from grafana/phlare
local dockerGoImage = 'golang:1.20.4';
local dockerNodeImage = 'node:20-bullseye';
local dockerGrafanaPluginCIImage = 'grafana/grafana-plugin-ci-e2e:latest';
local step(name, commands, image=dockerGoImage) = {
name: name,
commands: commands,
image: image,
};
local pipeline(name, steps=[], services=[]) = {
kind: 'pipeline',
type: 'docker',
name: name,
services: services,
steps: [step('runner identification', ['echo $DRONE_RUNNER_NAME'], 'alpine')] + steps,
trigger+: {
ref+: [
'refs/heads/main',
'refs/pull/**',
'refs/tags/v*.*.*',
'refs/tags/weekly-f*',
],
},
};
local mainOnly = {
when: {
ref+: [
'refs/heads/main',
'refs/pull/2/head',
],
},
};
local mainOrReleaseOnly = {
when: {
ref+: [
'refs/heads/main',
'refs/pull/2/head',
'refs/tags/v*.*.*',
'refs/tags/weekly-f*',
],
},
};
local releaseOnly = {
when: {
event: ['tag'],
ref+: [
'refs/tags/v*.*.*',
'refs/tags/weekly-f*',
],
},
};
local nonReleaseOnly = {
when: {
event: {
exclude: ['tag'],
},
},
};
local cronOnly = {
when: {
event: ['cron'],
},
};
local prOnly = {
when: {
event: {
include: ['pull_request'],
},
},
};
// promoteOnly triggers pipelines only on promotion. Various deployment steps
// are tagged with this, so that we can optionally tell Drone to
// deploy to different environments by promoting a build.
//
// This can be achieved by running:
//
// drone build promote grafana/pyroscope-app-plugin <build> <target>
//
// after setting up your Drone CLI following the instructions at
// https://drone.grafana.net/account, or by using the 'Promote' option
// of a successful build of 'main' in the Drone UI and specifying
// the target.
//
// For deployments, the target name is the wave name, e.g. 'ops', 'prod', etc.
local promoteOnly(target) = {
trigger: { event: ['promote'], target: [target] },
};
local vault_secret(name, vault_path, key) = {
kind: 'secret',
name: name,
get: {
path: vault_path,
name: key,
},
};
local uploadStep = function(platform)
step('publish platform specific (' + platform + ') zip to GCS with tag', [], 'plugins/gcs') + {
depends_on: [
'package and sign',
'generate tags',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}-' + platform + '.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-${DRONE_TAG}-' + platform + '.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + releaseOnly;
// NB: Former deployStep() replaced by argo-workflows api call using argo-cli container
// as `argoWorkflowStep('phlare-cd', 'deploy-<wave>-envs')`, with <wave> in ['dev', 'ops', 'prod'] see:
// - https://argo-workflows.grafana.net/workflow-templates/phlare-cd
// built from https://github.com/grafana/deployment_tools/tree/master/ksonnet/environments/phlare-cd
// - https://argo-workflows.grafana.net/workflows/phlare-cd
// for the actual workflows runs
local argoWorkflowStep(namespace, name) = {
name: 'launch %s workflow' % name,
image: 'us.gcr.io/kubernetes-dev/drone/plugins/argo-cli',
settings: {
namespace: namespace,
token: {
from_secret: 'argo_token',
},
log_level: 'debug',
command: if name == 'deploy-plugin-dev' then
'submit --from workflowtemplate/%(name)s --name %(name)s-${DRONE_COMMIT} --parameter plugintag=${DRONE_COMMIT}' % { name: name }
else
'submit --from workflowtemplate/%(name)s --name %(name)s-${DRONE_TAG} --parameter plugintag=${DRONE_TAG}' % { name: name },
add_ci_labels: true,
},
depends_on: [
'generate tags',
],
};
local deployStep(envsGroup) = argoWorkflowStep('phlare-cd', 'deploy-plugin-%s' % envsGroup);
local generateTagsStep(depends_on=[]) = step('generate tags', [
'git fetch origin --tags',
'git status --porcelain --untracked-files=no',
'git diff --no-ext-diff --quiet', // fail if the workspace has modified files
]) + { depends_on: depends_on };
// Main array of drone pipelines
[
pipeline('build packages', [
generateTagsStep(),
step('install dependencies', [
'yarn install --immutable',
], image=dockerNodeImage),
step('build frontend packages', [
'export NODE_ENV=production',
'echo "export const GIT_COMMIT = \'${DRONE_COMMIT}\';" > src/version.ts',
'./scripts/replace-package-json-version ${DRONE_TAG}',
'yarn build',
], image=dockerNodeImage) + {
depends_on: [
'install dependencies',
],
},
step('package and sign', [
'apt update',
'apt install zip',
'./scripts/package-and-sign ${DRONE_BUILD_NUMBER}',
], image=dockerNodeImage) + {
environment: {
GRAFANA_ACCESS_POLICY_TOKEN: {
from_secret: 'GRAFANA_ACCESS_POLICY_TOKEN',
},
},
depends_on: [
'build frontend packages',
],
} + mainOrReleaseOnly,
step('publish zip to GCS', [], image='plugins/gcs') + {
depends_on: [
'package and sign',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + releaseOnly,
step('publish zip to GCS with commit SHA', [], image='plugins/gcs') + {
depends_on: [
'package and sign',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-${DRONE_COMMIT}.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + releaseOnly,
step('publish zip to GCS with latest-dev', [], image='plugins/gcs') + {
depends_on: [
'package and sign',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-edge.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + mainOnly,
step('publish zip to GCS with dev-tag', [], image='plugins/gcs') + {
depends_on: [
'package and sign',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-${DRONE_COMMIT}.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + mainOnly,
step('publish zip to GCS with latest', [], image='plugins/gcs') + {
depends_on: [
'package and sign',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-latest.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + releaseOnly,
step('publish zip to GCS with tag', [], image='plugins/gcs') + {
depends_on: [
'package and sign',
'generate tags',
],
settings: {
acl: 'allUsers:READER',
source: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
target: 'grafana-pyroscope-app/releases/grafana-pyroscope-app-${DRONE_TAG}.zip',
token: {
from_secret: 'gcs_service_account_key',
},
},
} + releaseOnly,
step('publish release to Github', [], image='plugins/github-release') + {
settings: {
api_key: {
from_secret: 'gh_token',
},
files: 'grafana-pyroscope-app-${DRONE_BUILD_NUMBER}.zip',
title: '${DRONE_TAG}', // v1.2.3
},
depends_on: [
'generate tags',
'package and sign',
],
} + releaseOnly,
step('publish to grafana.com', [
'apt update',
'apt install -y curl',
'./scripts/publish-plugin ${DRONE_BUILD_NUMBER} ${DRONE_TAG}',
], image=dockerGrafanaPluginCIImage) + {
environment: {
GCOM_TOKEN: {
from_secret: 'gcom_publish_token',
},
},
depends_on: [
'generate tags',
'package and sign',
],
} + releaseOnly,
]),
pipeline('deploy dev', [
generateTagsStep(),
deployStep('dev'),
]) + {
image_pull_secrets: ['gcr_reader'],
depends_on: [
'build packages',
],
trigger+: {
ref: [
'refs/heads/main',
],
},
},
pipeline('weekly deploy ops', [
generateTagsStep(),
deployStep('ops'),
]) + {
depends_on: [
'build packages',
],
image_pull_secrets: ['gcr_reader'],
trigger+: { ref: ['refs/tags/weekly-f*'] },
},
pipeline('weekly deploy prod', [
generateTagsStep(),
deployStep('prod'),
]) + {
depends_on: [
'build packages',
],
image_pull_secrets: ['gcr_reader'],
trigger+: { ref: ['refs/tags/weekly-f*'] },
},
pipeline('deploy ops', [
generateTagsStep(),
deployStep('ops'),
]) + { depends_on: [
'build packages',
] } + promoteOnly('ops') + {
image_pull_secrets: ['gcr_reader'],
trigger+: { ref: ['refs/tags/*'] },
},
pipeline('deploy prod', [
generateTagsStep(),
deployStep('prod'),
]) + { depends_on: [
'build packages',
] } + promoteOnly('prod') + {
image_pull_secrets: ['gcr_reader'],
trigger+: { ref: ['refs/tags/*'] },
},
pipeline('deploy opsprod', [
generateTagsStep(),
deployStep('ops'),
deployStep('prod'),
]) + { depends_on: [
'build packages',
] } + promoteOnly('opsprod') + {
image_pull_secrets: ['gcr_reader'],
trigger+: { ref: ['refs/tags/*'] },
},
vault_secret('dockerconfigjson', 'infra/data/ci/gcr-admin', '.dockerconfigjson'),
vault_secret('gcr_reader', 'secret/data/common/gcr', '.dockerconfigjson'),
vault_secret('gcs_service_account_key', 'infra/data/ci/drone-plugins', 'gcp_key'),
vault_secret('gh_token', 'infra/data/ci/github/grafanabot', 'pat'),
vault_secret('slack_webhook', 'infra/data/ci/slack_webhooks', 'slack-plugin'),
vault_secret('argo_token', 'infra/data/ci/argo-workflows/trigger-service-account', 'token'),
vault_secret('gcom_publish_token', 'infra/data/ci/drone-plugins', 'gcom_publish_token'),
]