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