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