mirror of
https://github.com/containers/podman.git
synced 2026-07-08 22:35:01 -04:00
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>
This commit is contained in:
@@ -1547,8 +1547,11 @@ func (s *PodmanSessionIntegration) jq(jqCommand string) (string, error) {
|
||||
}
|
||||
|
||||
func (p *PodmanTestIntegration) buildImage(dockerfile, imageName string, layers string, label string, extraOptions []string) string {
|
||||
dockerfilePath := filepath.Join(p.TempDir, "Dockerfile-"+stringid.GenerateRandomID())
|
||||
err := os.WriteFile(dockerfilePath, []byte(dockerfile), 0o755)
|
||||
buildDir := filepath.Join(p.TempDir, "build"+stringid.GenerateRandomID())
|
||||
err := os.Mkdir(buildDir, 0o755)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
dockerfilePath := filepath.Join(buildDir, "Dockerfile-"+stringid.GenerateRandomID())
|
||||
err = os.WriteFile(dockerfilePath, []byte(dockerfile), 0o644)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
cmd := []string{"build", "--pull-never", "--layers=" + layers, "--file", dockerfilePath}
|
||||
if label != "" {
|
||||
@@ -1560,7 +1563,7 @@ func (p *PodmanTestIntegration) buildImage(dockerfile, imageName string, layers
|
||||
if len(extraOptions) > 0 {
|
||||
cmd = append(cmd, extraOptions...)
|
||||
}
|
||||
cmd = append(cmd, p.TempDir)
|
||||
cmd = append(cmd, buildDir)
|
||||
session := p.Podman(cmd)
|
||||
session.Wait(240)
|
||||
Expect(session).Should(Exit(0), fmt.Sprintf("BuildImage session output: %q", session.OutputToString()))
|
||||
|
||||
@@ -10,12 +10,17 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
. "go.podman.io/podman/v6/test/utils"
|
||||
"go.podman.io/storage/pkg/stringid"
|
||||
)
|
||||
|
||||
func buildDataVolumeImage(pTest *PodmanTestIntegration, image, data, dest string) {
|
||||
buildDir := filepath.Join(pTest.TempDir, "build"+stringid.GenerateRandomID())
|
||||
err := os.Mkdir(buildDir, 0o755)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Create a dummy file for data volume
|
||||
dummyFile := filepath.Join(pTest.TempDir, data)
|
||||
err := os.WriteFile(dummyFile, []byte(data), 0o644)
|
||||
dummyFile := filepath.Join(buildDir, data)
|
||||
err = os.WriteFile(dummyFile, []byte(data), 0o644)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Create a data volume container image but no CMD binary in it
|
||||
@@ -23,7 +28,11 @@ func buildDataVolumeImage(pTest *PodmanTestIntegration, image, data, dest string
|
||||
CMD doesnotexist.sh
|
||||
ADD %s %s/
|
||||
VOLUME %s/`, data, dest, dest)
|
||||
pTest.BuildImage(containerFile, image, "false")
|
||||
|
||||
containerFilePath := filepath.Join(buildDir, "Containerfile")
|
||||
err = os.WriteFile(containerFilePath, []byte(containerFile), 0o644)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pTest.PodmanExitCleanly("build", "--pull-never", "-q", "-t", image, "--layers=false", "--file", containerFilePath)
|
||||
}
|
||||
|
||||
func createContainersConfFile(pTest *PodmanTestIntegration) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"go.podman.io/common/pkg/sysinfo"
|
||||
"go.podman.io/podman/v6/pkg/util"
|
||||
. "go.podman.io/podman/v6/test/utils"
|
||||
"go.podman.io/storage/pkg/stringid"
|
||||
)
|
||||
|
||||
var _ = Describe("Podman pod create", func() {
|
||||
@@ -175,8 +176,12 @@ var _ = Describe("Podman pod create", func() {
|
||||
|
||||
Describe("podman create pod with --hosts-file", func() {
|
||||
BeforeEach(func() {
|
||||
imageHosts := filepath.Join(podmanTest.TempDir, "pause_hosts")
|
||||
err := os.WriteFile(imageHosts, []byte("56.78.12.34 image.example.com"), 0o755)
|
||||
buildDir := filepath.Join(podmanTest.TempDir, "build"+stringid.GenerateRandomID())
|
||||
err := os.Mkdir(buildDir, 0o755)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
imageHosts := filepath.Join(buildDir, "pause_hosts")
|
||||
err = os.WriteFile(imageHosts, []byte("56.78.12.34 image.example.com"), 0o755)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
configHosts := filepath.Join(podmanTest.TempDir, "hosts")
|
||||
@@ -191,11 +196,16 @@ var _ = Describe("Podman pod create", func() {
|
||||
podmanTest.RestartRemoteService()
|
||||
}
|
||||
|
||||
dockerfile := strings.Join([]string{
|
||||
containerfile := strings.Join([]string{
|
||||
`FROM ` + INFRA_IMAGE,
|
||||
`COPY pause_hosts /etc/hosts`,
|
||||
}, "\n")
|
||||
podmanTest.BuildImage(dockerfile, "foobar.com/hosts_test_pause:latest", "false", "--no-hosts")
|
||||
|
||||
containerFilePath := filepath.Join(buildDir, "Containerfile")
|
||||
err = os.WriteFile(containerFilePath, []byte(containerfile), 0o644)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
podmanTest.PodmanExitCleanly("build", "-q", "-t", "foobar.com/hosts_test_pause:latest", "--layers=false", "--no-hosts", buildDir)
|
||||
})
|
||||
|
||||
It("--hosts-file=path", func() {
|
||||
|
||||
@@ -69,11 +69,18 @@ func pullChunkedTests() { // included in pull_test.go, must use a Ginkgo DSL at
|
||||
registryRef: pullChunkedRegistryPrefix + "chunked-normal",
|
||||
dirPath: filepath.Join(imageDir, "chunked-normal"),
|
||||
}
|
||||
|
||||
buildDir := filepath.Join(podmanTest.TempDir, "build")
|
||||
err := os.Mkdir(buildDir, 0o755)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
chunkedNormalContentPath := "chunked-normal-image-content"
|
||||
err := os.WriteFile(filepath.Join(podmanTest.TempDir, chunkedNormalContentPath), fmt.Appendf(nil, "content-%d", rand.Int64()), 0o600)
|
||||
err = os.WriteFile(filepath.Join(buildDir, chunkedNormalContentPath), fmt.Appendf(nil, "content-%d", rand.Int64()), 0o600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
chunkedNormalContainerFile := fmt.Sprintf("FROM scratch\nADD %s /content", chunkedNormalContentPath)
|
||||
podmanTest.BuildImage(chunkedNormalContainerFile, chunkedNormal.localTag(), "true")
|
||||
err = os.WriteFile(filepath.Join(buildDir, "Containerfile"), []byte(chunkedNormalContainerFile), 0o600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
podmanTest.PodmanExitCleanly("build", "-q", "-t", chunkedNormal.localTag(), "--layers=true", buildDir)
|
||||
|
||||
podmanTest.PodmanExitCleanly("push", "-q", "--tls-verify=false", "--force-compression", "--compression-format=zstd:chunked", chunkedNormal.localTag(), chunkedNormal.registryRef)
|
||||
skopeo := SystemExec("skopeo", []string{"copy", "-q", "--preserve-digests", "--all", "--src-tls-verify=false", chunkedNormal.registryRef, "dir:" + chunkedNormal.dirPath})
|
||||
skopeo.WaitWithDefaultTimeout()
|
||||
|
||||
Reference in New Issue
Block a user