/
complex_test.go
227 lines (177 loc) · 8.76 KB
/
complex_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
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
package e2e_build_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/werf/werf/test/pkg/contback"
"github.com/werf/werf/test/pkg/thirdparty/contruntime/manifest"
"github.com/werf/werf/test/pkg/werf"
)
var _ = Describe("Complex build", Label("e2e", "build", "complex"), func() {
DescribeTable("should succeed and produce expected image",
func(withLocalRepo bool, buildahMode string) {
By("initializing")
setupEnv(withLocalRepo, buildahMode)
contRuntime, err := contback.NewContainerBackend(buildahMode)
if err == contback.ErrRuntimeUnavailable {
Skip(err.Error())
} else if err != nil {
Fail(err.Error())
}
By("state0: starting")
{
repoDirname := "repo0"
fixtureRelPath := "complex/state0"
buildReportName := "report0.json"
By("state0: preparing test repo")
SuiteData.InitTestRepo(repoDirname, fixtureRelPath)
By("state0: building images")
werfProject := werf.NewProject(SuiteData.WerfBinPath, SuiteData.GetTestRepoPath(repoDirname))
buildOut, buildReport := werfProject.BuildWithReport(SuiteData.GetBuildReportPath(buildReportName), nil)
Expect(buildOut).To(ContainSubstring("Building stage"))
Expect(buildOut).NotTo(ContainSubstring("Use cache image"))
By("state0: rebuilding same images")
Expect(werfProject.Build(nil)).To(And(
ContainSubstring("Use cache image"),
Not(ContainSubstring("Building stage")),
))
By(`state0: getting built images metadata`)
dockerfileImgCfg := contRuntime.GetImageInspectConfig(buildReport.Images["dockerfile"].DockerImageName)
stapelShellImgCfg := contRuntime.GetImageInspectConfig(buildReport.Images["stapel-shell"].DockerImageName)
By(`state0: checking "dockerfile" image metadata`)
Expect(dockerfileImgCfg.Env).To(ContainElement("COMPOSED_ENV=env-was_changed"))
Expect(dockerfileImgCfg.Labels).To(HaveKeyWithValue("COMPOSED_LABEL", "label-was_changed"))
Expect(dockerfileImgCfg.Shell).To(ContainElements("/bin/sh", "-c"))
Expect(dockerfileImgCfg.User).To(Equal("0:0"))
Expect(dockerfileImgCfg.WorkingDir).To(Equal("/"))
Expect(dockerfileImgCfg.Entrypoint).To(ContainElements("sh", "-ec"))
Expect(dockerfileImgCfg.Cmd).To(ContainElement("tail -f /dev/null"))
Expect(dockerfileImgCfg.Volumes).To(HaveKey("/volume10"))
Expect(dockerfileImgCfg.OnBuild).To(ContainElement("RUN echo onbuild"))
Expect(dockerfileImgCfg.StopSignal).To(Equal("SIGTERM"))
Expect(dockerfileImgCfg.ExposedPorts).To(HaveKey(manifest.Schema2Port("8000/tcp")))
Expect(dockerfileImgCfg.Healthcheck.Test).To(ContainElements("CMD-SHELL", "echo healthcheck10"))
By(`state0: checking "stapel-shell" image metadata`)
Expect(stapelShellImgCfg.Env).To(ContainElement("ENV_NAME=env-value"))
Expect(stapelShellImgCfg.Labels).To(HaveKeyWithValue("LABEL_NAME", "label-value"))
Expect(stapelShellImgCfg.User).To(Equal("0:0"))
Expect(stapelShellImgCfg.WorkingDir).To(Equal("/app"))
Expect(stapelShellImgCfg.Entrypoint).To(ContainElements("sh", "-ec"))
Expect(stapelShellImgCfg.Cmd).To(ContainElement("sleep infinity"))
Expect(stapelShellImgCfg.Volumes).To(HaveKey("/volume20"))
Expect(stapelShellImgCfg.ExposedPorts).To(HaveKey(manifest.Schema2Port("8010/tcp")))
Expect(stapelShellImgCfg.Healthcheck.Test).To(ContainElements("CMD-SHELL", "echo healthcheck20"))
By(`state0: checking "dockerfile" image content`)
contRuntime.ExpectCmdsToSucceed(
buildReport.Images["dockerfile"].DockerImageName,
"test -f /app/added/file1",
"echo 'file1content' | diff /app/added/file1 -",
"test -f /app/added/file2",
"echo 'file2content' | diff /app/added/file2 -",
"test -f /app/copied/file1",
"echo 'file1content' | diff /app/copied/file1 -",
"test -f /app/copied/file2",
"echo 'file2content' | diff /app/copied/file2 -",
"test -f /helloworld.tgz",
"tar xOf /helloworld.tgz | grep -qF 'Hello World!'",
"test -f /created-by-run-state0",
"test -d /volume10/should-exist-in-volume",
)
By(`state0: checking "stapel-shell" image content`)
contRuntime.ExpectCmdsToSucceed(
buildReport.Images["stapel-shell"].DockerImageName,
"test -f /app/README.md",
"stat -c %u:%g /app/README.md | diff <(echo 1050:1051) -",
"grep -qF 'https://cloud.google.com/appengine/docs/go/#Go_tools' /app/README.md",
"test -f /app/static/index.html",
"stat -c %u:%g /app/static/index.html | diff <(echo 1050:1051) -",
"grep -qF '<title>Hello, world</title>' /app/static/index.html",
"test -f /app/static/style.css",
"stat -c %u:%g /app/static/style.css | diff <(echo 1050:1051) -",
"grep -qF 'text-align: center;' /app/static/style.css",
"! test -f /app/app.go",
"! test -f /app/static/script.js",
"test -f /triggered-stages",
"stat -c %u:%g /triggered-stages | diff <(echo 0:0) -",
"echo 'beforeInstall\ninstall\nbeforeSetup\nsetup' | diff /triggered-stages -",
"! test -f /tmp_dir/file",
"test -f /basedir/file",
"stat -c %u:%g /basedir/file | diff <(echo 0:0) -",
"echo 'content' | diff /basedir/file -",
"test -f /basedir-imported/file",
"stat -c %u:%g /basedir-imported/file | diff <(echo 1060:1061) -",
"echo 'content' | diff /basedir-imported/file -",
)
}
By("state1: starting")
{
repoDirname := "repo0"
fixtureRelPath := "complex/state1"
buildReportName := "report1.json"
By("state1: changing files in test repo")
SuiteData.UpdateTestRepo(repoDirname, fixtureRelPath)
By("state1: building images")
werfProject := werf.NewProject(SuiteData.WerfBinPath, SuiteData.GetTestRepoPath(repoDirname))
buildOut, buildReport := werfProject.BuildWithReport(SuiteData.GetBuildReportPath(buildReportName), nil)
Expect(buildOut).To(ContainSubstring("Building stage"))
By("state1: rebuilding same images")
Expect(werfProject.Build(nil)).To(And(
ContainSubstring("Use cache image"),
Not(ContainSubstring("Building stage")),
))
By(`state1: getting built images metadata`)
dockerfileImgCfg := contRuntime.GetImageInspectConfig(buildReport.Images["dockerfile"].DockerImageName)
stapelShellImgCfg := contRuntime.GetImageInspectConfig(buildReport.Images["stapel-shell"].DockerImageName)
By(`state1: checking "dockerfile" image metadata`)
Expect(dockerfileImgCfg.Env).To(ContainElement("COMPOSED_ENV=env-was_changed-state1"))
Expect(dockerfileImgCfg.Labels).To(HaveKeyWithValue("COMPOSED_LABEL", "label-was_changed-state1"))
By(`state1: checking "stapel-shell" image metadata`)
Expect(stapelShellImgCfg.Volumes).ToNot(HaveKey("/volume20"))
By(`state1: checking "dockerfile" image content`)
contRuntime.ExpectCmdsToSucceed(
buildReport.Images["dockerfile"].DockerImageName,
"test -f /app/added/file1",
"echo 'file1content-state1' | diff /app/added/file1 -",
"! test -f /app/added/file2",
"test -f /app/added/file3",
"echo 'file3content-state1' | diff /app/added/file3 -",
"test -f /app/copied/file1",
"echo 'file1content-state1' | diff /app/copied/file1 -",
"! test -f /app/copied/file2",
"test -f /app/copied/file3",
"echo 'file3content-state1' | diff /app/copied/file3 -",
"! test -f /helloworld.tgz",
"test -f /created-by-run-state1",
)
By(`state1: checking "stapel-shell" image content`)
contRuntime.ExpectCmdsToSucceed(
buildReport.Images["stapel-shell"].DockerImageName,
"test -f /app/README.md",
"stat -c %u:%g /app/README.md | diff <(echo 1050:1051) -",
"grep -qF 'https://cloud.google.com/sdk/' /app/README.md",
"test -f /app/static/index.html",
"stat -c %u:%g /app/static/index.html | diff <(echo 1050:1051) -",
"grep -qF '<title>Hello, world</title>' /app/static/index.html",
"! test -f /app/static/style.css",
"test -f /app/app.go",
"stat -c %u:%g /app/app.go | diff <(echo 1050:1051) -",
"grep -qF 'package hello' /app/app.go",
"! test -f /app/static/script.js",
"test -f /triggered-stages",
"stat -c %u:%g /triggered-stages | diff <(echo 0:0) -",
"echo 'beforeInstall\ninstall\nbeforeSetup\nsetup' | diff /triggered-stages -",
"! test -f /tmp_dir/file",
"test -f /basedir/file",
"stat -c %u:%g /basedir/file | diff <(echo 0:0) -",
"echo 'content' | diff /basedir/file -",
"test -f /basedir-imported/file",
"stat -c %u:%g /basedir-imported/file | diff <(echo 1060:1061) -",
"echo 'content' | diff /basedir-imported/file -",
)
}
},
Entry("without repo using Docker", false, "docker"),
Entry("with local repo using Docker", true, "docker"),
Entry("with local repo using Native Buildah with rootless isolation", true, "native-rootless"),
Entry("with local repo using Native Buildah with chroot isolation", true, "native-chroot"),
)
})