-
Notifications
You must be signed in to change notification settings - Fork 758
/
config.bats
392 lines (331 loc) · 15.9 KB
/
config.bats
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
385
386
387
388
389
390
391
392
#!/usr/bin/env bats
load helpers
@test "config-flags-order-verification" {
run_buildah 125 config cnt1 --author=user1
check_options_flag_err "--author=user1"
run_buildah 125 config cnt1 --arch x86_54
check_options_flag_err "--arch"
run_buildah 125 config cnt1 --created-by buildahcli --cmd "/usr/bin/run.sh" --hostname "localhost1"
check_options_flag_err "--created-by"
run_buildah 125 config cnt1 --annotation=service=cache
check_options_flag_err "--annotation=service=cache"
}
@test "config-flags-verification" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --label LABEL $cid
run_buildah config --annotation ANNOTATION $cid
run_buildah 125 config --healthcheck 'AB "CD' $cid
expect_output --substring 'error parsing --healthcheck "AB \\"CD": invalid command line string'
run_buildah 125 config --healthcheck-interval ABCD $cid
expect_output --substring 'error parsing --healthcheck-interval "ABCD": time: invalid duration "?ABCD"?'
run_buildah 125 config --cmd 'AB "CD' $cid
expect_output --substring 'error parsing --cmd "AB \\"CD": invalid command line string'
run_buildah 125 config --env ENV $cid
expect_output --substring 'error setting env "ENV": no value given'
run_buildah 125 config --shell 'AB "CD' $cid
expect_output --substring 'error parsing --shell "AB \\"CD": invalid command line string'
}
function check_matrix() {
local setting=$1
local expect=$2
# matrix test: all permutations of .Docker.* and .OCIv1.* in all image types
for image in docker oci; do
for which in Docker OCIv1; do
run_buildah inspect --type=image --format "{{.$which.$setting}}" scratch-image-$image
expect_output "$expect"
done
done
}
@test "config entrypoint using single element in JSON array (exec form)" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --entrypoint '[ "/ENTRYPOINT" ]' $cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix "Config.Entrypoint" '[/ENTRYPOINT]'
}
@test "config entrypoint using multiple elements in JSON array (exec form)" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --entrypoint '[ "/ENTRYPOINT", "ELEMENT2" ]' $cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Entrypoint' '[/ENTRYPOINT ELEMENT2]'
}
@test "config entrypoint using string (shell form)" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --entrypoint /ENTRYPOINT $cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Entrypoint' '[/bin/sh -c /ENTRYPOINT]'
}
@test "config set empty entrypoint doesn't wipe cmd" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --cmd "command" $cid
run_buildah config --entrypoint "" $cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Cmd' '[command]'
}
@test "config cmd without entrypoint" {
run_buildah from --pull-never --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--cmd COMMAND-OR-ARGS \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Cmd' '[COMMAND-OR-ARGS]'
check_matrix 'Config.Entrypoint' '[]'
}
@test "config entrypoint with cmd" {
run_buildah from --pull-never --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--entrypoint /ENTRYPOINT \
--cmd COMMAND-OR-ARGS \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Cmd' '[COMMAND-OR-ARGS]'
run_buildah from --pull-never --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--entrypoint /ENTRYPOINT \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Cmd' '[]'
run_buildah config \
--entrypoint /ENTRYPOINT \
--cmd COMMAND-OR-ARGS \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Cmd' '[COMMAND-OR-ARGS]'
run_buildah config \
--entrypoint /ENTRYPOINT \
--cmd '[ "/COMMAND", "ARG1", "ARG2"]' \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Config.Cmd' '[/COMMAND ARG1 ARG2]'
}
@test "config remove all" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--port 12345 \
--annotation ANNOTATION=VALUE1,VALUE2 \
--env VARIABLE=VALUE1,VALUE2 \
--volume /VOLUME \
--label LABEL=VALUE \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
run_buildah inspect --type=image --format '{{.ImageAnnotations}}' scratch-image-oci
expect_output "map[ANNOTATION:VALUE1,VALUE2]"
run_buildah inspect --format '{{.ImageAnnotations}}' $cid
expect_output "map[ANNOTATION:VALUE1,VALUE2]"
check_matrix 'Config.ExposedPorts' 'map[12345:{}]'
check_matrix 'Config.Env' '[VARIABLE=VALUE1,VALUE2]'
check_matrix 'Config.Labels.LABEL' 'VALUE'
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--port - \
--annotation - \
--env - \
--volume - \
--label - \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
run_buildah inspect --type=image --format '{{.ImageAnnotations}}' scratch-image-oci
expect_output "map[]"
run_buildah inspect --format '{{.ImageAnnotations}}' $cid
expect_output "map[]"
check_matrix 'Config.ExposedPorts' 'map[]'
check_matrix 'Config.Env' '[]'
check_matrix 'Config.Labels.LABEL' '<no value>'
}
@test "config" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--author TESTAUTHOR \
--created-by COINCIDENCE \
--arch amd64 \
--os linux \
--user likes:things \
--port 12345 \
--env VARIABLE=VALUE1,VALUE2 \
--entrypoint /ENTRYPOINT \
--cmd COMMAND-OR-ARGS \
--comment INFORMATIVE \
--history-comment PROBABLY-EMPTY \
--volume /VOLUME \
--workingdir /tmp \
--label LABEL=VALUE \
--label exec='podman run -it --mount=type=bind,bind-propagation=Z,source=foo,destination=bar /script buz'\
--stop-signal SIGINT \
--annotation ANNOTATION=VALUE1,VALUE2 \
--shell /bin/arbitrarysh \
--domainname mydomain.local \
--hostname cleverhostname \
--healthcheck "CMD /bin/true" \
--healthcheck-start-period 5s \
--healthcheck-interval 6s \
--healthcheck-timeout 7s \
--healthcheck-retries 8 \
--onbuild "RUN touch /foo" \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
check_matrix 'Author' 'TESTAUTHOR'
check_matrix 'Architecture' 'amd64'
check_matrix 'OS' 'linux'
run_buildah inspect --format '{{.ImageCreatedBy}}' $cid
expect_output "COINCIDENCE"
check_matrix 'Config.Cmd' '[COMMAND-OR-ARGS]'
check_matrix 'Config.Entrypoint' '[/bin/sh -c /ENTRYPOINT]'
check_matrix 'Config.Env' '[VARIABLE=VALUE1,VALUE2]'
check_matrix 'Config.ExposedPorts' 'map[12345:{}]'
check_matrix 'Config.Labels.exec' 'podman run -it --mount=type=bind,bind-propagation=Z,source=foo,destination=bar /script buz'
check_matrix 'Config.Labels.LABEL' 'VALUE'
check_matrix 'Config.StopSignal' 'SIGINT'
check_matrix 'Config.User' 'likes:things'
check_matrix 'Config.Volumes' "map[/VOLUME:{}]"
check_matrix 'Config.WorkingDir' '/tmp'
run_buildah inspect --type=image --format '{{(index .Docker.History 0).Comment}}' scratch-image-docker
expect_output "PROBABLY-EMPTY"
run_buildah inspect --type=image --format '{{(index .OCIv1.History 0).Comment}}' scratch-image-docker
expect_output "PROBABLY-EMPTY"
run_buildah inspect --type=image --format '{{(index .Docker.History 0).Comment}}' scratch-image-oci
expect_output "PROBABLY-EMPTY"
run_buildah inspect --type=image --format '{{(index .OCIv1.History 0).Comment}}' scratch-image-oci
expect_output "PROBABLY-EMPTY"
# The following aren't part of the Docker v2 spec, so they're discarded when we save to Docker format.
run_buildah inspect --type=image --format '{{.ImageAnnotations}}' scratch-image-oci
expect_output "map[ANNOTATION:VALUE1,VALUE2]"
run_buildah inspect --format '{{.ImageAnnotations}}' $cid
expect_output "map[ANNOTATION:VALUE1,VALUE2]"
run_buildah inspect --type=image --format '{{.Docker.Comment}}' scratch-image-docker
expect_output "INFORMATIVE"
run_buildah inspect --type=image --format '{{.Docker.Config.Domainname}}' scratch-image-docker
expect_output "mydomain.local"
run_buildah inspect --type=image --format '{{.Docker.Config.Hostname}}' scratch-image-docker
expect_output "cleverhostname"
run_buildah inspect --type=image --format '{{.Docker.Config.Shell}}' scratch-image-docker
expect_output "[/bin/arbitrarysh]"
run_buildah inspect -f '{{.Docker.Config.Healthcheck.Test}}' scratch-image-docker
expect_output "[CMD /bin/true]"
run_buildah inspect -f '{{.Docker.Config.Healthcheck.StartPeriod}}' scratch-image-docker
expect_output "5s"
run_buildah inspect -f '{{.Docker.Config.Healthcheck.Interval}}' scratch-image-docker
expect_output "6s"
run_buildah inspect -f '{{.Docker.Config.Healthcheck.Timeout}}' scratch-image-docker
expect_output "7s"
run_buildah inspect -f '{{.Docker.Config.Healthcheck.Retries}}' scratch-image-docker
expect_output "8"
run_buildah inspect -f '{{.Docker.Config.OnBuild}}' scratch-image-docker
expect_output "[RUN touch /foo]"
rm -rf /VOLUME
}
@test "config env using local environment" {
export foo=bar
run_buildah from --pull-never --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --env 'foo' $cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid env-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid env-image-oci
run_buildah inspect --type=image --format '{{.Docker.Config.Env}}' env-image-docker
expect_output --substring "foo=bar"
run_buildah inspect --type=image --format '{{.OCIv1.Config.Env}}' env-image-docker
expect_output --substring "foo=bar"
}
@test "config env using --env expansion" {
run_buildah from --pull-never --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config --env 'foo=bar' --env 'foo1=bar1' $cid
run_buildah config --env 'combined=$foo/${foo1}' $cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid env-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid env-image-oci
run_buildah inspect --type=image --format '{{.Docker.Config.Env}}' env-image-docker
expect_output --substring "combined=bar/bar1"
run_buildah inspect --type=image --format '{{.OCIv1.Config.Env}}' env-image-docker
expect_output --substring "combined=bar/bar1"
}
@test "user" {
_prefetch alpine
run_buildah from --quiet --pull --signature-policy ${TESTSDIR}/policy.json alpine
cid=$output
run_buildah run $cid grep CapBnd /proc/self/status
bndoutput=$output
run_buildah config --user 1000 $cid
run_buildah run $cid id -u
expect_output "1000"
run_buildah run $cid sh -c "grep CapEff /proc/self/status | cut -f2"
expect_output "0000000000000000"
run_buildah run $cid grep CapBnd /proc/self/status
expect_output "$bndoutput"
}
@test "remove configs using '-' syntax" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah config \
--created-by COINCIDENCE \
--volume /VOLUME \
--env VARIABLE=VALUE1,VALUE2 \
--label LABEL=VALUE \
--port 12345 \
--annotation ANNOTATION=VALUE1,VALUE2 \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
run_buildah inspect --format '{{.ImageCreatedBy}}' $cid
expect_output "COINCIDENCE"
check_matrix 'Config.Volumes' "map[/VOLUME:{}]"
check_matrix 'Config.Env' '[VARIABLE=VALUE1,VALUE2]'
check_matrix 'Config.Labels.LABEL' 'VALUE'
check_matrix 'Config.ExposedPorts' 'map[12345:{}]'
run_buildah inspect --type=image --format '{{.ImageAnnotations}}' scratch-image-oci
expect_output "map[ANNOTATION:VALUE1,VALUE2]"
run_buildah inspect --format '{{.ImageAnnotations}}' $cid
expect_output "map[ANNOTATION:VALUE1,VALUE2]"
run_buildah config \
--created-by COINCIDENCE \
--volume /VOLUME- \
--env VARIABLE- \
--label LABEL- \
--port 12345- \
--annotation ANNOTATION- \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
run_buildah inspect --format '{{.ImageCreatedBy}}' $cid
expect_output "COINCIDENCE"
check_matrix 'Config.Volumes' 'map[]'
check_matrix 'Config.Env' '[]'
check_matrix 'Config.Labels.LABEL' '<no value>'
check_matrix 'Config.ExposedPorts' 'map[]'
run_buildah inspect --type=image --format '{{.ImageAnnotations}}' scratch-image-oci
expect_output "map[]"
run_buildah inspect --format '{{.ImageAnnotations}}' $cid
expect_output "map[]"
run_buildah config \
--created-by COINCIDENCE \
--volume /VOLUME- \
--env VARIABLE=VALUE1,VALUE2 \
--label LABEL=VALUE \
--annotation ANNOTATION=VALUE1,VALUE2 \
$cid
run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker
run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci
run_buildah inspect --format '{{.ImageCreatedBy}}' $cid
expect_output "COINCIDENCE"
check_matrix 'Config.Volumes' "map[]"
}