Skip to content

Commit 79e7b0f

Browse files
committed
test/e2e: build in subdirectory
So when running remote and rootless tests the buildImage() thing has one big problem because it used the main test tmpdir as context. However that dir also holds all the image layers with files that are owned by other uids and because podman-remote does not use the userns it cannot read some files and then fails when trying to tar up the context dir. To fix this use an extra sub directory. Now because some tests where using the parent directory to supply context files just switch the callers so they have full control still. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent fd07b9c commit 79e7b0f

4 files changed

Lines changed: 41 additions & 12 deletions

File tree

test/e2e/common_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,8 +1547,11 @@ func (s *PodmanSessionIntegration) jq(jqCommand string) (string, error) {
15471547
}
15481548

15491549
func (p *PodmanTestIntegration) buildImage(dockerfile, imageName string, layers string, label string, extraOptions []string) string {
1550-
dockerfilePath := filepath.Join(p.TempDir, "Dockerfile-"+stringid.GenerateRandomID())
1551-
err := os.WriteFile(dockerfilePath, []byte(dockerfile), 0o755)
1550+
buildDir := filepath.Join(p.TempDir, "build"+stringid.GenerateRandomID())
1551+
err := os.Mkdir(buildDir, 0o755)
1552+
Expect(err).ToNot(HaveOccurred())
1553+
dockerfilePath := filepath.Join(buildDir, "Dockerfile-"+stringid.GenerateRandomID())
1554+
err = os.WriteFile(dockerfilePath, []byte(dockerfile), 0o644)
15521555
Expect(err).ToNot(HaveOccurred())
15531556
cmd := []string{"build", "--pull-never", "--layers=" + layers, "--file", dockerfilePath}
15541557
if label != "" {
@@ -1560,7 +1563,7 @@ func (p *PodmanTestIntegration) buildImage(dockerfile, imageName string, layers
15601563
if len(extraOptions) > 0 {
15611564
cmd = append(cmd, extraOptions...)
15621565
}
1563-
cmd = append(cmd, p.TempDir)
1566+
cmd = append(cmd, buildDir)
15641567
session := p.Podman(cmd)
15651568
session.Wait(240)
15661569
Expect(session).Should(Exit(0), fmt.Sprintf("BuildImage session output: %q", session.OutputToString()))

test/e2e/container_create_volume_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@ import (
1010
. "github.com/onsi/ginkgo/v2"
1111
. "github.com/onsi/gomega"
1212
. "go.podman.io/podman/v6/test/utils"
13+
"go.podman.io/storage/pkg/stringid"
1314
)
1415

1516
func buildDataVolumeImage(pTest *PodmanTestIntegration, image, data, dest string) {
17+
buildDir := filepath.Join(pTest.TempDir, "build"+stringid.GenerateRandomID())
18+
err := os.Mkdir(buildDir, 0o755)
19+
Expect(err).ToNot(HaveOccurred())
20+
1621
// Create a dummy file for data volume
17-
dummyFile := filepath.Join(pTest.TempDir, data)
18-
err := os.WriteFile(dummyFile, []byte(data), 0o644)
22+
dummyFile := filepath.Join(buildDir, data)
23+
err = os.WriteFile(dummyFile, []byte(data), 0o644)
1924
Expect(err).ToNot(HaveOccurred())
2025

2126
// Create a data volume container image but no CMD binary in it
2227
containerFile := fmt.Sprintf(`FROM scratch
2328
CMD doesnotexist.sh
2429
ADD %s %s/
2530
VOLUME %s/`, data, dest, dest)
26-
pTest.BuildImage(containerFile, image, "false")
31+
32+
containerFilePath := filepath.Join(buildDir, "Containerfile")
33+
err = os.WriteFile(containerFilePath, []byte(containerFile), 0o644)
34+
Expect(err).ToNot(HaveOccurred())
35+
pTest.PodmanExitCleanly("build", "--pull-never", "-q", "-t", image, "--layers=false", "--file", containerFilePath)
2736
}
2837

2938
func createContainersConfFile(pTest *PodmanTestIntegration) {

test/e2e/pod_create_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"go.podman.io/common/pkg/sysinfo"
2121
"go.podman.io/podman/v6/pkg/util"
2222
. "go.podman.io/podman/v6/test/utils"
23+
"go.podman.io/storage/pkg/stringid"
2324
)
2425

2526
var _ = Describe("Podman pod create", func() {
@@ -175,8 +176,12 @@ var _ = Describe("Podman pod create", func() {
175176

176177
Describe("podman create pod with --hosts-file", func() {
177178
BeforeEach(func() {
178-
imageHosts := filepath.Join(podmanTest.TempDir, "pause_hosts")
179-
err := os.WriteFile(imageHosts, []byte("56.78.12.34 image.example.com"), 0o755)
179+
buildDir := filepath.Join(podmanTest.TempDir, "build"+stringid.GenerateRandomID())
180+
err := os.Mkdir(buildDir, 0o755)
181+
Expect(err).ToNot(HaveOccurred())
182+
183+
imageHosts := filepath.Join(buildDir, "pause_hosts")
184+
err = os.WriteFile(imageHosts, []byte("56.78.12.34 image.example.com"), 0o755)
180185
Expect(err).ToNot(HaveOccurred())
181186

182187
configHosts := filepath.Join(podmanTest.TempDir, "hosts")
@@ -191,11 +196,16 @@ var _ = Describe("Podman pod create", func() {
191196
podmanTest.RestartRemoteService()
192197
}
193198

194-
dockerfile := strings.Join([]string{
199+
containerfile := strings.Join([]string{
195200
`FROM ` + INFRA_IMAGE,
196201
`COPY pause_hosts /etc/hosts`,
197202
}, "\n")
198-
podmanTest.BuildImage(dockerfile, "foobar.com/hosts_test_pause:latest", "false", "--no-hosts")
203+
204+
containerFilePath := filepath.Join(buildDir, "Containerfile")
205+
err = os.WriteFile(containerFilePath, []byte(containerfile), 0o644)
206+
Expect(err).ToNot(HaveOccurred())
207+
208+
podmanTest.PodmanExitCleanly("build", "-q", "-t", "foobar.com/hosts_test_pause:latest", "--layers=false", "--no-hosts", buildDir)
199209
})
200210

201211
It("--hosts-file=path", func() {

test/e2e/pull_chunked_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ func pullChunkedTests() { // included in pull_test.go, must use a Ginkgo DSL at
6969
registryRef: pullChunkedRegistryPrefix + "chunked-normal",
7070
dirPath: filepath.Join(imageDir, "chunked-normal"),
7171
}
72+
73+
buildDir := filepath.Join(podmanTest.TempDir, "build")
74+
err := os.Mkdir(buildDir, 0o755)
75+
Expect(err).ToNot(HaveOccurred())
7276
chunkedNormalContentPath := "chunked-normal-image-content"
73-
err := os.WriteFile(filepath.Join(podmanTest.TempDir, chunkedNormalContentPath), fmt.Appendf(nil, "content-%d", rand.Int64()), 0o600)
77+
err = os.WriteFile(filepath.Join(buildDir, chunkedNormalContentPath), fmt.Appendf(nil, "content-%d", rand.Int64()), 0o600)
7478
Expect(err).NotTo(HaveOccurred())
7579
chunkedNormalContainerFile := fmt.Sprintf("FROM scratch\nADD %s /content", chunkedNormalContentPath)
76-
podmanTest.BuildImage(chunkedNormalContainerFile, chunkedNormal.localTag(), "true")
80+
err = os.WriteFile(filepath.Join(buildDir, "Containerfile"), []byte(chunkedNormalContainerFile), 0o600)
81+
Expect(err).NotTo(HaveOccurred())
82+
podmanTest.PodmanExitCleanly("build", "-q", "-t", chunkedNormal.localTag(), "--layers=true", buildDir)
83+
7784
podmanTest.PodmanExitCleanly("push", "-q", "--tls-verify=false", "--force-compression", "--compression-format=zstd:chunked", chunkedNormal.localTag(), chunkedNormal.registryRef)
7885
skopeo := SystemExec("skopeo", []string{"copy", "-q", "--preserve-digests", "--all", "--src-tls-verify=false", chunkedNormal.registryRef, "dir:" + chunkedNormal.dirPath})
7986
skopeo.WaitWithDefaultTimeout()

0 commit comments

Comments
 (0)