github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/push_test.go (about) 1 // +build !remoteclient 2 3 package integration 4 5 import ( 6 "fmt" 7 "os" 8 "path/filepath" 9 "strings" 10 11 "github.com/containers/libpod/pkg/rootless" 12 . "github.com/containers/libpod/test/utils" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("Podman push", func() { 18 var ( 19 tempdir string 20 err error 21 podmanTest *PodmanTestIntegration 22 ) 23 24 BeforeEach(func() { 25 tempdir, err = CreateTempDirInTempDir() 26 if err != nil { 27 os.Exit(1) 28 } 29 podmanTest = PodmanTestCreate(tempdir) 30 podmanTest.Setup() 31 podmanTest.RestoreAllArtifacts() 32 }) 33 34 AfterEach(func() { 35 podmanTest.Cleanup() 36 f := CurrentGinkgoTestDescription() 37 processTestResult(f) 38 39 }) 40 41 It("podman push to containers/storage", func() { 42 session := podmanTest.PodmanNoCache([]string{"push", ALPINE, "containers-storage:busybox:test"}) 43 session.WaitWithDefaultTimeout() 44 Expect(session.ExitCode()).To(Equal(0)) 45 46 session = podmanTest.PodmanNoCache([]string{"rmi", ALPINE}) 47 session.WaitWithDefaultTimeout() 48 Expect(session.ExitCode()).To(Equal(0)) 49 }) 50 51 It("podman push to dir", func() { 52 bbdir := filepath.Join(podmanTest.TempDir, "busybox") 53 session := podmanTest.PodmanNoCache([]string{"push", "--remove-signatures", ALPINE, 54 fmt.Sprintf("dir:%s", bbdir)}) 55 session.WaitWithDefaultTimeout() 56 Expect(session.ExitCode()).To(Equal(0)) 57 }) 58 59 It("podman push to local registry", func() { 60 if podmanTest.Host.Arch == "ppc64le" { 61 Skip("No registry image for ppc64le") 62 } 63 if rootless.IsRootless() { 64 podmanTest.RestoreArtifact(registry) 65 } 66 lock := GetPortLock("5000") 67 defer lock.Unlock() 68 session := podmanTest.PodmanNoCache([]string{"run", "-d", "--name", "registry", "-p", "5000:5000", registry, "/entrypoint.sh", "/etc/docker/registry/config.yml"}) 69 session.WaitWithDefaultTimeout() 70 Expect(session.ExitCode()).To(Equal(0)) 71 72 if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) { 73 Skip("Can not start docker registry.") 74 } 75 76 push := podmanTest.PodmanNoCache([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) 77 push.WaitWithDefaultTimeout() 78 Expect(push.ExitCode()).To(Equal(0)) 79 80 // Test --digestfile option 81 push2 := podmanTest.PodmanNoCache([]string{"push", "--tls-verify=false", "--digestfile=/tmp/digestfile.txt", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) 82 push2.WaitWithDefaultTimeout() 83 fi, err := os.Lstat("/tmp/digestfile.txt") 84 Expect(err).To(BeNil()) 85 Expect(fi.Name()).To(Equal("digestfile.txt")) 86 Expect(push2.ExitCode()).To(Equal(0)) 87 }) 88 89 It("podman push to local registry with authorization", func() { 90 SkipIfRootless() 91 if podmanTest.Host.Arch == "ppc64le" { 92 Skip("No registry image for ppc64le") 93 } 94 authPath := filepath.Join(podmanTest.TempDir, "auth") 95 os.Mkdir(authPath, os.ModePerm) 96 os.MkdirAll("/etc/containers/certs.d/localhost:5000", os.ModePerm) 97 defer os.RemoveAll("/etc/containers/certs.d/localhost:5000") 98 99 cwd, _ := os.Getwd() 100 certPath := filepath.Join(cwd, "../", "certs") 101 102 if IsCommandAvailable("getenforce") { 103 ge := SystemExec("getenforce", []string{}) 104 Expect(ge.ExitCode()).To(Equal(0)) 105 if ge.OutputToString() == "Enforcing" { 106 se := SystemExec("setenforce", []string{"0"}) 107 Expect(se.ExitCode()).To(Equal(0)) 108 defer func() { 109 se2 := SystemExec("setenforce", []string{"1"}) 110 Expect(se2.ExitCode()).To(Equal(0)) 111 }() 112 } 113 } 114 lock := GetPortLock("5000") 115 defer lock.Unlock() 116 session := podmanTest.PodmanNoCache([]string{"run", "--entrypoint", "htpasswd", registry, "-Bbn", "podmantest", "test"}) 117 session.WaitWithDefaultTimeout() 118 Expect(session.ExitCode()).To(Equal(0)) 119 120 f, _ := os.Create(filepath.Join(authPath, "htpasswd")) 121 defer f.Close() 122 123 f.WriteString(session.OutputToString()) 124 f.Sync() 125 126 session = podmanTest.PodmanNoCache([]string{"run", "-d", "-p", "5000:5000", "--name", "registry", "-v", 127 strings.Join([]string{authPath, "/auth"}, ":"), "-e", "REGISTRY_AUTH=htpasswd", "-e", 128 "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm", "-e", "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", 129 "-v", strings.Join([]string{certPath, "/certs"}, ":"), "-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt", 130 "-e", "REGISTRY_HTTP_TLS_KEY=/certs/domain.key", registry}) 131 session.WaitWithDefaultTimeout() 132 Expect(session.ExitCode()).To(Equal(0)) 133 134 if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) { 135 Skip("Can not start docker registry.") 136 } 137 138 session = podmanTest.PodmanNoCache([]string{"logs", "registry"}) 139 session.WaitWithDefaultTimeout() 140 141 push := podmanTest.PodmanNoCache([]string{"push", "--creds=podmantest:test", ALPINE, "localhost:5000/tlstest"}) 142 push.WaitWithDefaultTimeout() 143 Expect(push).To(ExitWithError()) 144 145 push = podmanTest.PodmanNoCache([]string{"push", "--creds=podmantest:test", "--tls-verify=false", ALPINE, "localhost:5000/tlstest"}) 146 push.WaitWithDefaultTimeout() 147 Expect(push.ExitCode()).To(Equal(0)) 148 149 setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), "/etc/containers/certs.d/localhost:5000/ca.crt"}) 150 Expect(setup.ExitCode()).To(Equal(0)) 151 152 push = podmanTest.PodmanNoCache([]string{"push", "--creds=podmantest:wrongpasswd", ALPINE, "localhost:5000/credstest"}) 153 push.WaitWithDefaultTimeout() 154 Expect(push).To(ExitWithError()) 155 156 push = podmanTest.PodmanNoCache([]string{"push", "--creds=podmantest:test", "--cert-dir=fakedir", ALPINE, "localhost:5000/certdirtest"}) 157 push.WaitWithDefaultTimeout() 158 Expect(push).To(ExitWithError()) 159 160 push = podmanTest.PodmanNoCache([]string{"push", "--creds=podmantest:test", ALPINE, "localhost:5000/defaultflags"}) 161 push.WaitWithDefaultTimeout() 162 Expect(push.ExitCode()).To(Equal(0)) 163 }) 164 165 It("podman push to docker-archive", func() { 166 tarfn := filepath.Join(podmanTest.TempDir, "alp.tar") 167 session := podmanTest.PodmanNoCache([]string{"push", ALPINE, 168 fmt.Sprintf("docker-archive:%s:latest", tarfn)}) 169 session.WaitWithDefaultTimeout() 170 Expect(session.ExitCode()).To(Equal(0)) 171 }) 172 173 It("podman push to docker daemon", func() { 174 setup := SystemExec("bash", []string{"-c", "systemctl status docker 2>&1"}) 175 176 if setup.LineInOutputContains("Active: inactive") { 177 setup = SystemExec("systemctl", []string{"start", "docker"}) 178 defer func() { 179 stop := SystemExec("systemctl", []string{"stop", "docker"}) 180 Expect(stop.ExitCode()).To(Equal(0)) 181 }() 182 } else if setup.ExitCode() != 0 { 183 Skip("Docker is not available") 184 } 185 186 session := podmanTest.PodmanNoCache([]string{"push", ALPINE, "docker-daemon:alpine:podmantest"}) 187 session.WaitWithDefaultTimeout() 188 Expect(session.ExitCode()).To(Equal(0)) 189 190 check := SystemExec("docker", []string{"images", "--format", "{{.Repository}}:{{.Tag}}"}) 191 Expect(check.ExitCode()).To(Equal(0)) 192 Expect(check.OutputToString()).To(ContainSubstring("alpine:podmantest")) 193 194 clean := SystemExec("docker", []string{"rmi", "alpine:podmantest"}) 195 Expect(clean.ExitCode()).To(Equal(0)) 196 }) 197 198 It("podman push to oci-archive", func() { 199 tarfn := filepath.Join(podmanTest.TempDir, "alp.tar") 200 session := podmanTest.PodmanNoCache([]string{"push", ALPINE, 201 fmt.Sprintf("oci-archive:%s:latest", tarfn)}) 202 session.WaitWithDefaultTimeout() 203 Expect(session.ExitCode()).To(Equal(0)) 204 }) 205 206 It("podman push to docker-archive no reference", func() { 207 tarfn := filepath.Join(podmanTest.TempDir, "alp.tar") 208 session := podmanTest.PodmanNoCache([]string{"push", ALPINE, 209 fmt.Sprintf("docker-archive:%s", tarfn)}) 210 session.WaitWithDefaultTimeout() 211 Expect(session.ExitCode()).To(Equal(0)) 212 }) 213 214 It("podman push to oci-archive no reference", func() { 215 ociarc := filepath.Join(podmanTest.TempDir, "alp-oci") 216 session := podmanTest.PodmanNoCache([]string{"push", ALPINE, 217 fmt.Sprintf("oci-archive:%s", ociarc)}) 218 219 session.WaitWithDefaultTimeout() 220 Expect(session.ExitCode()).To(Equal(0)) 221 }) 222 223 })