Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d4779a3

Browse files
committedApr 11, 2024·
Don't expand RUN heredocs ourselves, let the shell do it
When handling RUN instructions that use heredoc syntax, don't bother interpolating environment variables and argument values, and let the command that's running handle it. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent 392c64a commit d4779a3

35 files changed

+632
-309
lines changed
 

‎go.mod

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/containers/buildah
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.21.9
46

57
require (
68
github.com/containerd/containerd v1.7.13
@@ -12,9 +14,9 @@ require (
1214
github.com/containers/storage v1.53.0
1315
github.com/cyphar/filepath-securejoin v0.2.4
1416
github.com/docker/distribution v2.8.3+incompatible
15-
github.com/docker/docker v25.0.5+incompatible
17+
github.com/docker/docker v26.0.0+incompatible
1618
github.com/docker/go-units v0.5.0
17-
github.com/fsouza/go-dockerclient v1.10.1
19+
github.com/fsouza/go-dockerclient v1.11.0
1820
github.com/hashicorp/go-multierror v1.1.1
1921
github.com/mattn/go-shellwords v1.0.12
2022
github.com/moby/buildkit v0.12.5
@@ -88,7 +90,7 @@ require (
8890
github.com/godbus/dbus/v5 v5.1.0 // indirect
8991
github.com/gogo/protobuf v1.3.2 // indirect
9092
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
91-
github.com/golang/protobuf v1.5.3 // indirect
93+
github.com/golang/protobuf v1.5.4 // indirect
9294
github.com/google/go-cmp v0.6.0 // indirect
9395
github.com/google/go-containerregistry v0.19.0 // indirect
9496
github.com/google/go-intervals v0.0.2 // indirect
@@ -110,6 +112,7 @@ require (
110112
github.com/miekg/pkcs11 v1.1.1 // indirect
111113
github.com/mistifyio/go-zfs/v3 v3.0.1 // indirect
112114
github.com/mitchellh/mapstructure v1.5.0 // indirect
115+
github.com/moby/docker-image-spec v1.3.1 // indirect
113116
github.com/moby/patternmatcher v0.6.0 // indirect
114117
github.com/moby/sys/mountinfo v0.7.1 // indirect
115118
github.com/moby/sys/sequential v0.5.0 // indirect
@@ -158,3 +161,5 @@ require (
158161
)
159162

160163
replace github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec v1.1.0
164+
165+
replace github.com/openshift/imagebuilder => github.com/nalind/openshift-imagebuilder v0.0.0-20240411201310-a050864f2395

‎go.sum

+44-8
Large diffs are not rendered by default.

‎tests/conformance/conformance_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,13 @@ var internalTestCases = []testCase{
31023102
contextDir: "multistage/copyback",
31033103
dockerUseBuildKit: true,
31043104
},
3105+
3106+
{
3107+
name: "heredoc-quoting",
3108+
dockerfile: "Dockerfile.heredoc-quoting",
3109+
dockerUseBuildKit: true,
3110+
fsSkip: []string{"(dir):etc:(dir):hostname"}, // buildkit does not create a phantom /etc/hostname
3111+
},
31053112
}
31063113

31073114
func TestCommit(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
FROM busybox
2+
ARG argA=argvA
3+
ENV varA=valueA
4+
5+
# An argument, an environment variable, and one set in the heredoc
6+
RUN <<EOF
7+
varB=valueB
8+
touch /run-argA=$argA.unquoted1.txt
9+
touch /run-varA=$varA.unquoted1.txt
10+
touch /run-varB=$varB.unquoted1.txt
11+
EOF
12+
13+
# An argument, an environment variable, and one set in the heredoc
14+
RUN <<EOF
15+
varB=valueB
16+
touch /run-argA="$argA".unquoted2.txt
17+
touch /run-varA="$varA".unquoted2.txt
18+
touch /run-varB="$varB".unquoted2.txt
19+
EOF
20+
21+
# An argument, an environment variable overridden in the heredoc, and one set in the heredoc
22+
RUN <<EOF
23+
varA=valueA2
24+
varB=valueB
25+
touch /run-argA="$argA".unquoted3.txt
26+
touch /run-varA="$varA".unquoted3.txt
27+
touch /run-varB="$varB".unquoted3.txt
28+
EOF
29+
30+
# An overridden argument, an environment variable overridden in the heredoc, and one set in the heredoc
31+
RUN <<EOF
32+
argA=argvA2
33+
varA=valueA2
34+
varB=valueB
35+
touch /run-argA="$argA".unquoted4.txt
36+
touch /run-varA="$varA".unquoted4.txt
37+
touch /run-varB="$varB".unquoted4.txt
38+
EOF
39+
40+
# An argument, an environment variable, and one set in the heredoc
41+
RUN <<"EOF"
42+
varB=valueB
43+
touch /run-argA=$argA.quoted1.txt
44+
touch /run-varA=$varA.quoted1.txt
45+
touch /run-varB=$varB.quoted1.txt
46+
EOF
47+
48+
# An argument, an environment variable, and one set in the heredoc
49+
RUN <<"EOF"
50+
varB=valueB
51+
touch /run-argA="$argA".quoted2.txt
52+
touch /run-varA="$varA".quoted2.txt
53+
touch /run-varB="$varB".quoted2.txt
54+
EOF
55+
56+
# An argument, an environment variable overridden in the heredoc, and one set in the heredoc
57+
RUN <<"EOF"
58+
varA=valueA2
59+
varB=valueB
60+
touch /run-argA="$argA".quoted3.txt
61+
touch /run-varA="$varA".quoted3.txt
62+
touch /run-varB="$varB".quoted3.txt
63+
EOF
64+
65+
# An overridden argument, an environment variable overridden in the heredoc, and one set in the heredoc
66+
RUN <<"EOF"
67+
argA=argvA2
68+
varA=valueA2
69+
varB=valueB
70+
touch /run-argA="$argA".quoted4.txt
71+
touch /run-varA="$varA".quoted4.txt
72+
touch /run-varB="$varB".quoted4.txt
73+
EOF
74+
75+
# An argument, an environment variable, and one set in the heredoc
76+
COPY <<EOF /copy-unquoted1.txt
77+
varB=valueB
78+
touch /argA=$argA
79+
touch /varA=$varA
80+
touch /varB=$varB
81+
EOF
82+
83+
# An argument, an environment variable, and one set in the heredoc
84+
COPY <<EOF /copy-unquoted2.txt
85+
varB=valueB
86+
argA="$argA"
87+
varA="$varA"
88+
varB="$varB"
89+
EOF
90+
91+
# An argument, an environment variable overridden in the heredoc, and one set in the heredoc
92+
COPY <<EOF /copy-unquoted3.txt
93+
varA=valueA2
94+
varB=valueB
95+
argA="$argA"
96+
varA="$varA"
97+
varB="$varB"
98+
EOF
99+
100+
# An overridden argument, an environment variable overridden in the heredoc, and one set in the heredoc
101+
COPY <<EOF /copy-unquoted4.txt
102+
argA=argvA2
103+
varA=valueA2
104+
varB=valueB
105+
argA="$argA"
106+
varA="$varA"
107+
varB="$varB"
108+
EOF
109+
110+
# An argument, an environment variable, and one set in the heredoc
111+
COPY <<"EOF" /copy-quoted1.txt
112+
varB=valueB
113+
argA=$argA
114+
varA=$varA
115+
varB=$varB
116+
EOF
117+
118+
# An argument, an environment variable, and one set in the heredoc
119+
COPY <<"EOF" /copy-quoted2.txt
120+
varB=valueB
121+
argA="$argA"
122+
varA="$varA"
123+
varB="$varB"
124+
EOF
125+
126+
# An argument, an environment variable overridden in the heredoc, and one set in the heredoc
127+
COPY <<"EOF" /copy-quoted3.txt
128+
varA=valueA2
129+
varB=valueB
130+
argA="$argA"
131+
varA="$varA"
132+
varB="$varB"
133+
EOF
134+
135+
# An overridden argument, an environment variable overridden in the heredoc, and one set in the heredoc
136+
COPY <<"EOF" /copy-quoted4.txt
137+
argA=argvA2
138+
varA=valueA2
139+
varB=valueB
140+
argA="$argA"
141+
varA="$varA"
142+
varB="$varB"
143+
EOF
144+
145+
# An argument, an environment variable, and one set in the heredoc
146+
ADD <<EOF /add-unquoted1.txt
147+
varB=valueB
148+
touch /argA=$argA
149+
touch /varA=$varA
150+
touch /varB=$varB
151+
EOF
152+
153+
# An argument, an environment variable, and one set in the heredoc
154+
ADD <<EOF /add-unquoted2.txt
155+
varB=valueB
156+
argA="$argA"
157+
varA="$varA"
158+
varB="$varB"
159+
EOF
160+
161+
# An argument, an environment variable overridden in the heredoc, and one set in the heredoc
162+
ADD <<EOF /add-unquoted3.txt
163+
varA=valueA2
164+
varB=valueB
165+
argA="$argA"
166+
varA="$varA"
167+
varB="$varB"
168+
EOF
169+
170+
# An overridden argument, an environment variable overridden in the heredoc, and one set in the heredoc
171+
ADD <<EOF /add-unquoted4.txt
172+
argA=argvA2
173+
varA=valueA2
174+
varB=valueB
175+
argA="$argA"
176+
varA="$varA"
177+
varB="$varB"
178+
EOF
179+
180+
# An argument, an environment variable, and one set in the heredoc
181+
ADD <<"EOF" /add-quoted1.txt
182+
varB=valueB
183+
argA=$argA
184+
varA=$varA
185+
varB=$varB
186+
EOF
187+
188+
# An argument, an environment variable, and one set in the heredoc
189+
ADD <<"EOF" /add-quoted2.txt
190+
varB=valueB
191+
argA="$argA"
192+
varA="$varA"
193+
varB="$varB"
194+
EOF
195+
196+
# An argument, an environment variable overridden in the heredoc, and one set in the heredoc
197+
ADD <<"EOF" /add-quoted3.txt
198+
varA=valueA2
199+
varB=valueB
200+
argA="$argA"
201+
varA="$varA"
202+
varB="$varB"
203+
EOF
204+
205+
# An overridden argument, an environment variable overridden in the heredoc, and one set in the heredoc
206+
ADD <<"EOF" /add-quoted4.txt
207+
argA=argvA2
208+
varA=valueA2
209+
varB=valueB
210+
argA="$argA"
211+
varA="$varA"
212+
varB="$varB"
213+
EOF
214+
215+
RUN touch -r /etc/passwd /*.txt

‎vendor/github.com/docker/docker/api/common.go

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/swagger.yaml

+9-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/client.go

-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/container/config.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/image/opts.go

+53-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/mount/mount.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/registry/registry.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/types.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/types_deprecated.go

+18-121
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/api/types/versions/README.md

-14
This file was deleted.

‎vendor/github.com/docker/docker/api/types/volume/cluster_volume.go

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/distribution_inspect.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/image_create.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/image_import.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/image_list.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/image_pull.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/image_push.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/image_remove.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/client/interface.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/pkg/homedir/homedir.go

-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/docker/docker/pkg/homedir/homedir_unix.go

-8
This file was deleted.

‎vendor/github.com/docker/docker/pkg/homedir/homedir_windows.go

-6
This file was deleted.

‎vendor/github.com/docker/docker/pkg/system/image_os_deprecated.go

-19
This file was deleted.

‎vendor/github.com/fsouza/go-dockerclient/container.go

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/moby/docker-image-spec/LICENSE

+201
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/openshift/imagebuilder/.travis.yml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/openshift/imagebuilder/dispatchers.go

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/openshift/imagebuilder/dockerclient/client.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/openshift/imagebuilder/imagebuilder.spec

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/modules.txt

+10-7
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ github.com/distribution/reference
324324
github.com/docker/distribution/registry/api/errcode
325325
github.com/docker/distribution/registry/api/v2
326326
github.com/docker/distribution/registry/client/auth/challenge
327-
# github.com/docker/docker v25.0.5+incompatible
327+
# github.com/docker/docker v26.0.0+incompatible
328328
## explicit
329329
github.com/docker/docker/api
330330
github.com/docker/docker/api/types
@@ -346,7 +346,6 @@ github.com/docker/docker/api/types/versions
346346
github.com/docker/docker/api/types/volume
347347
github.com/docker/docker/client
348348
github.com/docker/docker/errdefs
349-
github.com/docker/docker/image/spec/specs-go/v1
350349
github.com/docker/docker/internal/multierror
351350
github.com/docker/docker/pkg/archive
352351
github.com/docker/docker/pkg/homedir
@@ -375,8 +374,8 @@ github.com/felixge/httpsnoop
375374
# github.com/fsnotify/fsnotify v1.7.0
376375
## explicit; go 1.17
377376
github.com/fsnotify/fsnotify
378-
# github.com/fsouza/go-dockerclient v1.10.1
379-
## explicit; go 1.20
377+
# github.com/fsouza/go-dockerclient v1.11.0
378+
## explicit; go 1.21
380379
github.com/fsouza/go-dockerclient
381380
# github.com/go-jose/go-jose/v3 v3.0.3
382381
## explicit; go 1.12
@@ -439,8 +438,8 @@ github.com/gogo/protobuf/proto
439438
# github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
440439
## explicit
441440
github.com/golang/groupcache/lru
442-
# github.com/golang/protobuf v1.5.3
443-
## explicit; go 1.9
441+
# github.com/golang/protobuf v1.5.4
442+
## explicit; go 1.17
444443
github.com/golang/protobuf/proto
445444
# github.com/google/go-cmp v0.6.0
446445
## explicit; go 1.13
@@ -539,6 +538,9 @@ github.com/moby/buildkit/frontend/dockerfile/command
539538
github.com/moby/buildkit/frontend/dockerfile/parser
540539
github.com/moby/buildkit/frontend/dockerfile/shell
541540
github.com/moby/buildkit/util/stack
541+
# github.com/moby/docker-image-spec v1.3.1
542+
## explicit; go 1.18
543+
github.com/moby/docker-image-spec/specs-go/v1
542544
# github.com/moby/patternmatcher v0.6.0
543545
## explicit; go 1.19
544546
github.com/moby/patternmatcher
@@ -639,7 +641,7 @@ github.com/opencontainers/selinux/go-selinux
639641
github.com/opencontainers/selinux/go-selinux/label
640642
github.com/opencontainers/selinux/pkg/pwalk
641643
github.com/opencontainers/selinux/pkg/pwalkdir
642-
# github.com/openshift/imagebuilder v1.2.6
644+
# github.com/openshift/imagebuilder v1.2.6 => github.com/nalind/openshift-imagebuilder v0.0.0-20240411201310-a050864f2395
643645
## explicit; go 1.19
644646
github.com/openshift/imagebuilder
645647
github.com/openshift/imagebuilder/dockerclient
@@ -1008,3 +1010,4 @@ tags.cncf.io/container-device-interface/pkg/parser
10081010
## explicit; go 1.19
10091011
tags.cncf.io/container-device-interface/specs-go
10101012
# github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec v1.1.0
1013+
# github.com/openshift/imagebuilder => github.com/nalind/openshift-imagebuilder v0.0.0-20240411201310-a050864f2395

0 commit comments

Comments
 (0)
Please sign in to comment.