forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrone.jsonnet
313 lines (297 loc) · 7.71 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
local apps = ['loki', 'loki-canary', 'logcli'];
local archs = ['amd64', 'arm64', 'arm'];
local build_image_version = std.extVar('__build-image-version');
local condition(verb) = {
tagMain: {
ref: {
[verb]:
[
'refs/heads/main',
'refs/heads/k??',
'refs/tags/v*',
],
},
},
};
local pipeline(name) = {
kind: 'pipeline',
name: name,
steps: [],
};
local run(name, commands) = {
name: name,
image: 'grafana/loki-build-image:%s' % build_image_version,
commands: commands,
};
local make(target, container=true) = run(target, [
'make ' + (if !container then 'BUILD_IN_CONTAINER=false ' else '') + target,
]);
local docker(arch, app) = {
name: '%s-image' % if $.settings.dry_run then 'build-' + app else 'publish-' + app,
image: 'plugins/docker',
settings: {
repo: 'grafana/%s' % app,
dockerfile: 'cmd/%s/Dockerfile' % app,
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
dry_run: false,
},
};
local clients_docker(arch, app) = {
name: '%s-image' % if $.settings.dry_run then 'build-' + app else 'publish-' + app,
image: 'plugins/docker',
settings: {
repo: 'grafana/%s' % app,
dockerfile: 'clients/cmd/%s/Dockerfile' % app,
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
dry_run: false,
},
};
local arch_image(arch, tags='') = {
platform: {
os: 'linux',
arch: arch,
},
steps: [{
name: 'image-tag',
image: 'alpine',
commands: [
'apk add --no-cache bash git',
'git fetch origin --tags',
'echo $(./tools/image-tag)-%s > .tags' % arch,
] + if tags != '' then ['echo ",%s" >> .tags' % tags] else [],
}],
};
local promtail_win() = pipeline('promtail-windows') {
platform: {
os: 'windows',
arch: 'amd64',
version: '1809',
},
steps: [{
name: 'test',
image: 'golang:windowsservercore-1809',
commands: [
'go test .\\clients\\pkg\\promtail\\targets\\windows\\... -v',
],
}],
};
local fluentbit() = pipeline('fluent-bit-amd64') + arch_image('amd64', 'latest,main') {
steps+: [
// dry run for everything that is not tag or main
clients_docker('amd64', 'fluent-bit') {
depends_on: ['image-tag'],
when: condition('exclude').tagMain,
settings+: {
dry_run: true,
repo: 'grafana/fluent-bit-plugin-loki',
},
},
] + [
// publish for tag or main
clients_docker('amd64', 'fluent-bit') {
depends_on: ['image-tag'],
when: condition('include').tagMain,
settings+: {
repo: 'grafana/fluent-bit-plugin-loki',
},
},
],
depends_on: ['check'],
};
local fluentd() = pipeline('fluentd-amd64') + arch_image('amd64', 'latest,main') {
steps+: [
// dry run for everything that is not tag or main
clients_docker('amd64', 'fluentd') {
depends_on: ['image-tag'],
when: condition('exclude').tagMain,
settings+: {
dry_run: true,
repo: 'grafana/fluent-plugin-loki',
},
},
] + [
// publish for tag or main
clients_docker('amd64', 'fluentd') {
depends_on: ['image-tag'],
when: condition('include').tagMain,
settings+: {
repo: 'grafana/fluent-plugin-loki',
},
},
],
depends_on: ['check'],
};
local logstash() = pipeline('logstash-amd64') + arch_image('amd64', 'latest,main') {
steps+: [
// dry run for everything that is not tag or main
clients_docker('amd64', 'logstash') {
depends_on: ['image-tag'],
when: condition('exclude').tagMain,
settings+: {
dry_run: true,
repo: 'grafana/logstash-output-loki',
},
},
] + [
// publish for tag or main
clients_docker('amd64', 'logstash') {
depends_on: ['image-tag'],
when: condition('include').tagMain,
settings+: {
repo: 'grafana/logstash-output-loki',
},
},
],
depends_on: ['check'],
};
local promtail(arch) = pipeline('promtail-' + arch) + arch_image(arch) {
steps+: [
// dry run for everything that is not tag or main
clients_docker(arch, 'promtail') {
depends_on: ['image-tag'],
when: condition('exclude').tagMain,
settings+: {
dry_run: true,
build_args: ['TOUCH_PROTOS=1'],
},
}
] + [
// publish for tag or main
clients_docker(arch, 'promtail') {
depends_on: ['image-tag'],
when: condition('include').tagMain,
settings+: {
build_args: ['TOUCH_PROTOS=1'],
},
}
],
depends_on: ['check'],
};
local multiarch_image(arch) = pipeline('docker-' + arch) + arch_image(arch) {
steps+: [
// dry run for everything that is not tag or main
docker(arch, app) {
depends_on: ['image-tag'],
when: condition('exclude').tagMain,
settings+: {
dry_run: true,
build_args: ['TOUCH_PROTOS=1'],
},
}
for app in apps
] + [
// publish for tag or main
docker(arch, app) {
depends_on: ['image-tag'],
when: condition('include').tagMain,
settings+: {
build_args: ['TOUCH_PROTOS=1'],
},
}
for app in apps
],
depends_on: ['check'],
};
local manifest(apps) = pipeline('manifest') {
steps: std.foldl(
function(acc, app) acc + [{
name: 'manifest-' + app,
image: 'plugins/manifest',
settings: {
// the target parameter is abused for the app's name,
// as it is unused in spec mode. See docker-manifest.tmpl
target: app,
spec: '.drone/docker-manifest.tmpl',
ignore_missing: false,
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
},
depends_on: ['clone'] + (
// Depend on the previous app, if any.
if std.length(acc) > 0
then [acc[std.length(acc) - 1].name]
else []
),
}],
apps,
[],
),
depends_on: [
'docker-%s' % arch
for arch in archs
] + [
'promtail-%s' % arch
for arch in archs
],
};
[
pipeline('check') {
workspace: {
base: '/src',
path: 'loki',
},
steps: [
make('test', container=false) { depends_on: ['clone'] },
make('lint', container=false) { depends_on: ['clone'] },
make('check-generated-files', container=false) { depends_on: ['clone'] },
make('check-mod', container=false) { depends_on: ['clone', 'test', 'lint'] },
],
},
] + [
multiarch_image(arch)
for arch in archs
] + [
promtail(arch) + (
// When we're building Promtail for ARM, we want to use Dockerfile.arm32 to fix
// a problem with the published Drone image. See Dockerfile.arm32 for more
// information.
//
// This is really really hacky and a better more permanent solution will be to use
// buildkit.
if arch == 'arm'
then {
steps: [
step + (
if std.objectHas(step, 'settings') && step.settings.dockerfile == 'clients/cmd/promtail/Dockerfile'
then {
settings+: {
dockerfile: 'clients/cmd/promtail/Dockerfile.arm32',
},
}
else {}
)
for step in super.steps
],
}
else {}
)
for arch in archs
] +[
fluentbit(),
fluentd(),
logstash(),
] + [
manifest(['promtail', 'loki', 'loki-canary']) {
trigger: condition('include').tagMain,
},
] + [
pipeline('deploy') {
trigger: condition('include').tagMain,
depends_on: ['manifest'],
steps: [
{
name: 'trigger',
image: 'grafana/loki-build-image:%s' % build_image_version,
environment: {
CIRCLE_TOKEN: { from_secret: 'circle_token' },
},
commands: [
'./tools/deploy.sh',
],
depends_on: ['clone'],
},
],
},
] + [promtail_win()]