summaryrefslogtreecommitdiff
path: root/test/podman_build.bats
blob: 91bb573f8f29e198b1e184827ae8c41e637a1114 (plain)
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
#!/usr/bin/env bats

load helpers

@test "build-from-scratch" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  target=scratch-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} ${BUILDAH_TESTSDIR}/build/from-scratch
  cid=$(buildah from ${target})
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
  [ "$status" -eq 0 ]
}

@test "build-from-multiple-files-one-from" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  target=scratch-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.scratch -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.nofrom
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  cmp $root/Dockerfile1 ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.scratch
  cmp $root/Dockerfile2.nofrom ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.nofrom
  run test -s $root/etc/passwd
  [ "$status" -ne 0 ]
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$status" -eq 0 ]
  [ "$output" = "" ]

  target=alpine-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.alpine -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.nofrom
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  cmp $root/Dockerfile1 ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.alpine
  cmp $root/Dockerfile2.nofrom ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.nofrom
  run test -s $root/etc/passwd
  [ "$status" -eq 0 ]
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$status" -eq 0 ]
  [ "$output" = "" ]
}

@test "build-from-multiple-files-two-froms" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  target=scratch-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.scratch -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.withfrom
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  cmp $root/Dockerfile1 ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.scratch
  cmp $root/Dockerfile2.withfrom ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.withfrom
  run test -s $root/etc/passwd
  [ "$status" -ne 0 ]
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$status" -eq 0 ]
  [ "$output" = "" ]

  target=alpine-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.alpine -f ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.withfrom
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  cmp $root/Dockerfile1 ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.alpine
  cmp $root/Dockerfile2.withfrom ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.withfrom
  run test -s $root/etc/passwd
  [ "$status" -eq 0 ]
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$status" -eq 0 ]
  [ "$output" = "" ]
}

@test "build-preserve-subvolumes" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  # This Dockerfile needs us to be able to handle a working RUN instruction.
  if ! which runc ; then
    skip
  fi
  target=volume-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} ${BUILDAH_TESTSDIR}/build/preserve-volumes
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  test -s $root/vol/subvol/subsubvol/subsubvolfile
  run test -s $root/vol/subvol/subvolfile
  [ "$status" -ne 0 ]
  test -s $root/vol/volfile
  test -s $root/vol/Dockerfile
  test -s $root/vol/Dockerfile2
  run test -s $root/vol/anothervolfile
  [ "$status" -ne 0 ]
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-http-Dockerfile" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  starthttpd ${BUILDAH_TESTSDIR}/build/from-scratch
  target=scratch-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f http://0.0.0.0:${HTTP_SERVER_PORT}/Dockerfile .
  stophttpd
  cid=$(buildah from ${target})
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-http-context-with-Dockerfile" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  starthttpd ${BUILDAH_TESTSDIR}/build/http-context
  target=scratch-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} http://0.0.0.0:${HTTP_SERVER_PORT}/context.tar
  stophttpd
  cid=$(buildah from ${target})
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-http-context-dir-with-Dockerfile-pre" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  starthttpd ${BUILDAH_TESTSDIR}/build/http-context-subdir
  target=scratch-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f context/Dockerfile http://0.0.0.0:${HTTP_SERVER_PORT}/context.tar
  stophttpd
  cid=$(buildah from ${target})
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-http-context-dir-with-Dockerfile-post" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  starthttpd ${BUILDAH_TESTSDIR}/build/http-context-subdir
  target=scratch-image
  podman build http://0.0.0.0:${HTTP_SERVER_PORT}/context.tar --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f context/Dockerfile
  stophttpd
  cid=$(buildah from ${target})
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-git-context" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  # We need git and ssh to be around to handle cloning a repository.
  if ! which git ; then
    skip
  fi
  if ! which ssh ; then
    skip
  fi
  target=giturl-image
  # Any repo should do, but this one is small and is FROM: scratch.
  gitrepo=git://github.com/projectatomic/nulecule-library
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} "${gitrepo}"
  cid=$(buildah from ${target})
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-github-context" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  target=github-image
  # Any repo should do, but this one is small and is FROM: scratch.
  gitrepo=github.com/projectatomic/nulecule-library
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} "${gitrepo}"
  cid=$(buildah from ${target})
  podman rm ${cid}
  buildah --debug=false images -q
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-additional-tags" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  target=scratch-image
  target2=another-scratch-image
  target3=so-many-scratch-images
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -t ${target2} -t ${target3} ${BUILDAH_TESTSDIR}/build/from-scratch
  run buildah --debug=false images
  cid=$(buildah from ${target})
  podman rm ${cid}
  cid=$(buildah from library/${target2})
  podman rm ${cid}
  cid=$(buildah from ${target3}:latest)
  podman rm ${cid}
  podman rmi -f $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-volume-perms" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  # This Dockerfile needs us to be able to handle a working RUN instruction.
  if ! which runc ; then
    skip
  fi
  target=volume-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} ${BUILDAH_TESTSDIR}/build/volume-perms
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  run test -s $root/vol/subvol/subvolfile
  [ "$status" -ne 0 ]
  run stat -c %f $root/vol/subvol
  [ "$output" = 41ed ]
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}

@test "build-from-glob" {
  if ! which buildah ; then
    skip "Buildah not installed"
  fi
  target=alpine-image
  podman build --signature-policy ${BUILDAH_TESTSDIR}/policy.json -t ${target} -f Dockerfile2.glob ${BUILDAH_TESTSDIR}/build/from-multiple-files
  cid=$(buildah from ${target})
  root=$(buildah mount ${cid})
  cmp $root/Dockerfile1.alpine ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile1.alpine
  cmp $root/Dockerfile2.withfrom ${BUILDAH_TESTSDIR}/build/from-multiple-files/Dockerfile2.withfrom
  podman rm ${cid}
  podman rmi $(buildah --debug=false images -q)
  run buildah --debug=false images -q
  [ "$output" = "" ]
}