forked from genuinetools/img
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_test.go
158 lines (126 loc) · 3.5 KB
/
build_test.go
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
package main
import (
"runtime"
"testing"
)
func TestBuildShCmdJSONEntrypoint(t *testing.T) {
name := "testbuildshcmdjsonentrypoint"
runBuild(t, name, withDockerfile(`
FROM busybox
ENTRYPOINT ["echo"]
CMD echo test
`))
}
func TestBuildEnvironmentReplacementUser(t *testing.T) {
name := "testbuildenvironmentreplacement"
runBuild(t, name, withDockerfile(`
FROM scratch
ENV user foo
USER ${user}
`))
}
func TestBuildEnvironmentReplacementVolume(t *testing.T) {
name := "testbuildenvironmentreplacement"
volumePath := "/quux"
if runtime.GOOS == "windows" {
volumePath = "c:/quux"
}
runBuild(t, name, withDockerfile(`
FROM busybox
ENV volume `+volumePath+`
VOLUME ${volume}
`))
}
func TestBuildEnvironmentReplacementExpose(t *testing.T) {
name := "testbuildenvironmentreplacement"
runBuild(t, name, withDockerfile(`
FROM scratch
ENV port 80
EXPOSE ${port}
ENV ports " 99 100 "
EXPOSE ${ports}
`))
}
func TestBuildEnvironmentReplacementWorkdir(t *testing.T) {
name := "testbuildenvironmentreplacement"
runBuild(t, name, withDockerfile(`
FROM busybox
ENV MYWORKDIR /work
RUN mkdir ${MYWORKDIR}
WORKDIR ${MYWORKDIR}
`))
}
func TestBuildFromScratch(t *testing.T) {
name := "testbuildfromscratch"
runBuild(t, name, withDockerfile(`
FROM scratch
COPY . .
`))
}
func TestBuildDockerfileNotInContext(t *testing.T) {
name := "testbuilddockerfilenotincontext"
run(t, "build", "-t", name, "-f", "testdata/Dockerfile.test-build-dockerfile-not-in-context", "types")
}
func TestBuildDockerfileNotInContextRoot(t *testing.T) {
name := "testbuilddockerfilenotincontextroot"
run(t, "build", "-t", name, "-f", "testdata/Dockerfile.test-build-dockerfile-not-in-context", ".")
}
// Make sure the client exits with the correct exit code.
// https://github.com/genuinetools/img/issues/101
func TestBuildDockerfileFailing(t *testing.T) {
name := "testbuilddockerfilefailing"
args := []string{"build", "-t", name, "-f", "testdata/Dockerfile.test-build-failing", "."}
out, err := doRun(args, nil)
if err == nil {
t.Logf("img %v should have failed but did not: %s", args, out)
t.FailNow()
}
}
// Using apt requires subuid, subgid, setgroups, and networking to be enabled.
// https://github.com/genuinetools/img/issues/96
func TestBuildAPT(t *testing.T) {
name := "testbuildapt"
runBuild(t, name, withDockerfile(`
FROM debian:9-slim
RUN apt update
`))
}
func TestBuildLabels(t *testing.T) {
name := "testbuildlabels"
args := []string{"build", "-t", name, "--label", "cli-label-1=cli1", "--label", "cli-label-2=cli2", "-"}
_, err := doRun(args, withDockerfile(`
FROM scratch as builder
LABEL stage "builder"
FROM scratch
LABEL stage "final"
`))
if err != nil {
t.Logf("img %v failed unexpectedly: %v", args, err)
t.FailNow()
}
}
func TestBuildMultipleTags(t *testing.T) {
names := []string{"testbuildmultipletags", "testbuildmultipletags:v1", "testbuildmultipletagsv1"}
args := []string{"build"}
for _, name := range names {
args = append(args, "-t", name)
}
args = append(args, "-")
_, err := doRun(args, withDockerfile(`
FROM scratch
`))
if err != nil {
t.Logf("img %v failed unexpectedly: %v", args, err)
t.FailNow()
}
}
func TestBuildMultiplePlatforms(t *testing.T) {
args := []string{"build", "--platform", "amd64", "--platform", "linux/arm64,linux/arm/v7", "-t", "testbuildplatforms", "-"}
_, err := doRun(args, withDockerfile(`
FROM alpine
`))
if err != nil {
t.Logf("img %v failed unexpectedly: %v", args, err)
t.FailNow()
}
}