8
8
"github.com/moby/buildkit/frontend/dockerfile/shell"
9
9
"github.com/moby/buildkit/frontend/dockerui"
10
10
"github.com/moby/buildkit/util/appcontext"
11
+ digest "github.com/opencontainers/go-digest"
11
12
"github.com/stretchr/testify/assert"
12
13
)
13
14
@@ -33,7 +34,7 @@ ENV FOO bar
33
34
COPY f1 f2 /sub/
34
35
RUN ls -l
35
36
`
36
- _ , _ , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
37
+ _ , _ , _ , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
37
38
assert .NoError (t , err )
38
39
39
40
df = `FROM scratch AS foo
@@ -42,7 +43,7 @@ FROM foo
42
43
COPY --from=foo f1 /
43
44
COPY --from=0 f2 /
44
45
`
45
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
46
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
46
47
assert .NoError (t , err )
47
48
48
49
df = `FROM scratch AS foo
@@ -51,14 +52,14 @@ FROM foo
51
52
COPY --from=foo f1 /
52
53
COPY --from=0 f2 /
53
54
`
54
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {
55
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {
55
56
Config : dockerui.Config {
56
57
Target : "Foo" ,
57
58
},
58
59
})
59
60
assert .NoError (t , err )
60
61
61
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {
62
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {
62
63
Config : dockerui.Config {
63
64
Target : "nosuch" ,
64
65
},
@@ -68,21 +69,21 @@ COPY --from=0 f2 /
68
69
df = `FROM scratch
69
70
ADD http://github.com/moby/buildkit/blob/master/README.md /
70
71
`
71
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
72
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
72
73
assert .NoError (t , err )
73
74
74
75
df = `FROM scratch
75
76
COPY http://github.com/moby/buildkit/blob/master/README.md /
76
77
`
77
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
78
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
78
79
assert .EqualError (t , err , "source can't be a URL for COPY" )
79
80
80
81
df = `FROM "" AS foo`
81
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
82
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
82
83
assert .Error (t , err )
83
84
84
85
df = `FROM ${BLANK} AS foo`
85
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
86
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
86
87
assert .Error (t , err )
87
88
}
88
89
@@ -93,7 +94,7 @@ ENV FOO bar
93
94
COPY f1 f2 /sub/
94
95
RUN ls -l
95
96
`
96
- state , _ , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
97
+ state , _ , _ , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
97
98
assert .NoError (t , err )
98
99
99
100
_ , err = state .Marshal (context .TODO ())
@@ -194,7 +195,7 @@ func TestDockerfileCircularDependencies(t *testing.T) {
194
195
df := `FROM busybox AS stage0
195
196
COPY --from=stage0 f1 /sub/
196
197
`
197
- _ , _ , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
198
+ _ , _ , _ , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
198
199
assert .EqualError (t , err , "circular dependency detected on stage: stage0" )
199
200
200
201
// multiple stages with circular dependency
@@ -205,6 +206,21 @@ COPY --from=stage0 f2 /sub/
205
206
FROM busybox AS stage2
206
207
COPY --from=stage1 f2 /sub/
207
208
`
208
- _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
209
+ _ , _ , _ , _ , err = Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
209
210
assert .EqualError (t , err , "circular dependency detected on stage: stage0" )
210
211
}
212
+
213
+ func TestBaseImageConfig (t * testing.T ) {
214
+ df := `FROM --platform=linux/amd64 busybox:1.36.1@sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74 AS foo
215
+ RUN echo foo
216
+
217
+ # the source image of bar is busybox, not foo
218
+ FROM foo AS bar
219
+ RUN echo bar
220
+ `
221
+ _ , _ , baseImg , _ , err := Dockerfile2LLB (appcontext .Context (), []byte (df ), ConvertOpt {})
222
+ assert .NoError (t , err )
223
+ t .Logf ("baseImg=%+v" , baseImg )
224
+ assert .Equal (t , []digest.Digest {"sha256:2e112031b4b923a873c8b3d685d48037e4d5ccd967b658743d93a6e56c3064b9" }, baseImg .RootFS .DiffIDs )
225
+ assert .Equal (t , "2024-01-17 21:49:12 +0000 UTC" , baseImg .Created .String ())
226
+ }
0 commit comments