2015-09-02 20:56:01 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-12-18 19:03:38 -05:00
|
|
|
"encoding/json"
|
2015-09-02 20:56:01 -04:00
|
|
|
"fmt"
|
2015-12-18 19:03:38 -05:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2015-08-25 17:23:52 -04:00
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2015-09-02 20:56:01 -04:00
|
|
|
|
2015-12-18 19:03:38 -05:00
|
|
|
"github.com/docker/distribution"
|
|
|
|
"github.com/docker/distribution/manifest"
|
|
|
|
"github.com/docker/distribution/manifest/manifestlist"
|
|
|
|
"github.com/docker/distribution/manifest/schema2"
|
2017-03-23 13:35:22 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
2019-08-05 10:37:47 -04:00
|
|
|
digest "github.com/opencontainers/go-digest"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/icmd"
|
2015-09-02 20:56:01 -04:00
|
|
|
)
|
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
// testPullImageWithAliases pulls a specific image tag and verifies that any aliases (i.e., other
|
2015-09-02 20:56:01 -04:00
|
|
|
// tags for the same image) are not also pulled down.
|
|
|
|
//
|
|
|
|
// Ref: docker/docker#8141
|
2019-09-09 17:05:55 -04:00
|
|
|
func testPullImageWithAliases(c *testing.T) {
|
2015-09-02 20:56:01 -04:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
2018-05-19 07:38:54 -04:00
|
|
|
var repos []string
|
2015-09-02 20:56:01 -04:00
|
|
|
for _, tag := range []string{"recent", "fresh"} {
|
|
|
|
repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tag and push the same image multiple times.
|
|
|
|
for _, repo := range repos {
|
|
|
|
dockerCmd(c, "tag", "busybox", repo)
|
|
|
|
dockerCmd(c, "push", repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear local images store.
|
|
|
|
args := append([]string{"rmi"}, repos...)
|
|
|
|
dockerCmd(c, args...)
|
|
|
|
|
|
|
|
// Pull a single tag and verify it doesn't bring down all aliases.
|
|
|
|
dockerCmd(c, "pull", repos[0])
|
|
|
|
dockerCmd(c, "inspect", repos[0])
|
|
|
|
for _, repo := range repos[1:] {
|
2015-10-09 21:09:53 -04:00
|
|
|
_, _, err := dockerCmdWithError("inspect", repo)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", "Image %v shouldn't have been pulled down", repo)
|
2015-09-02 20:56:01 -04:00
|
|
|
}
|
|
|
|
}
|
2015-08-25 17:23:52 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPullImageWithAliases(c *testing.T) {
|
2015-12-18 18:06:23 -05:00
|
|
|
testPullImageWithAliases(c)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) TestPullImageWithAliases(c *testing.T) {
|
2019-06-17 17:50:31 -04:00
|
|
|
testPullImageWithAliases(c)
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
// testConcurrentPullWholeRepo pulls the same repo concurrently.
|
2019-09-09 17:05:55 -04:00
|
|
|
func testConcurrentPullWholeRepo(c *testing.T) {
|
2015-08-25 17:23:52 -04:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
2018-05-19 07:38:54 -04:00
|
|
|
var repos []string
|
2015-08-25 17:23:52 -04:00
|
|
|
for _, tag := range []string{"recent", "fresh", "todays"} {
|
|
|
|
repo := fmt.Sprintf("%v:%v", repoName, tag)
|
2017-03-23 13:35:22 -04:00
|
|
|
buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(`
|
2015-08-25 17:23:52 -04:00
|
|
|
FROM busybox
|
|
|
|
ENTRYPOINT ["/bin/echo"]
|
|
|
|
ENV FOO foo
|
|
|
|
ENV BAR bar
|
|
|
|
CMD echo %s
|
2017-01-16 05:30:14 -05:00
|
|
|
`, repo)))
|
2015-08-25 17:23:52 -04:00
|
|
|
dockerCmd(c, "push", repo)
|
|
|
|
repos = append(repos, repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear local images store.
|
|
|
|
args := append([]string{"rmi"}, repos...)
|
|
|
|
dockerCmd(c, args...)
|
|
|
|
|
|
|
|
// Run multiple re-pulls concurrently
|
|
|
|
numPulls := 3
|
2020-02-25 17:13:25 -05:00
|
|
|
results := make(chan error, numPulls)
|
2015-08-25 17:23:52 -04:00
|
|
|
|
|
|
|
for i := 0; i != numPulls; i++ {
|
|
|
|
go func() {
|
2017-01-05 06:38:34 -05:00
|
|
|
result := icmd.RunCommand(dockerBinary, "pull", "-a", repoName)
|
|
|
|
results <- result.Error
|
2015-08-25 17:23:52 -04:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// These checks are separate from the loop above because the check
|
|
|
|
// package is not goroutine-safe.
|
|
|
|
for i := 0; i != numPulls; i++ {
|
|
|
|
err := <-results
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "concurrent pull failed with error: %v", err)
|
2015-08-25 17:23:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure all tags were pulled successfully
|
|
|
|
for _, repo := range repos {
|
|
|
|
dockerCmd(c, "inspect", repo)
|
|
|
|
out, _ := dockerCmd(c, "run", "--rm", repo)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo)
|
2015-08-25 17:23:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:58:46 -04:00
|
|
|
func (s *DockerRegistrySuite) TestConcurrentPullWholeRepo(c *testing.T) {
|
2015-12-18 18:06:23 -05:00
|
|
|
testConcurrentPullWholeRepo(c)
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:58:46 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) TestConcurrentPullWholeRepo(c *testing.T) {
|
2019-06-17 17:50:31 -04:00
|
|
|
testConcurrentPullWholeRepo(c)
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
// testConcurrentFailingPull tries a concurrent pull that doesn't succeed.
|
2019-09-09 17:05:55 -04:00
|
|
|
func testConcurrentFailingPull(c *testing.T) {
|
2015-08-25 17:23:52 -04:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
|
|
|
// Run multiple pulls concurrently
|
|
|
|
numPulls := 3
|
2020-02-25 17:13:25 -05:00
|
|
|
results := make(chan error, numPulls)
|
2015-08-25 17:23:52 -04:00
|
|
|
|
|
|
|
for i := 0; i != numPulls; i++ {
|
|
|
|
go func() {
|
2017-01-05 06:38:34 -05:00
|
|
|
result := icmd.RunCommand(dockerBinary, "pull", repoName+":asdfasdf")
|
|
|
|
results <- result.Error
|
2015-08-25 17:23:52 -04:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// These checks are separate from the loop above because the check
|
|
|
|
// package is not goroutine-safe.
|
|
|
|
for i := 0; i != numPulls; i++ {
|
|
|
|
err := <-results
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", "expected pull to fail")
|
2015-08-25 17:23:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:58:46 -04:00
|
|
|
func (s *DockerRegistrySuite) TestConcurrentFailingPull(c *testing.T) {
|
2015-12-18 18:06:23 -05:00
|
|
|
testConcurrentFailingPull(c)
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:58:46 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) TestConcurrentFailingPull(c *testing.T) {
|
2019-06-17 17:50:31 -04:00
|
|
|
testConcurrentFailingPull(c)
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
// testConcurrentPullMultipleTags pulls multiple tags from the same repo
|
2015-08-25 17:23:52 -04:00
|
|
|
// concurrently.
|
2019-09-09 17:05:55 -04:00
|
|
|
func testConcurrentPullMultipleTags(c *testing.T) {
|
2015-08-25 17:23:52 -04:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
2018-05-19 07:38:54 -04:00
|
|
|
var repos []string
|
2015-08-25 17:23:52 -04:00
|
|
|
for _, tag := range []string{"recent", "fresh", "todays"} {
|
|
|
|
repo := fmt.Sprintf("%v:%v", repoName, tag)
|
2017-03-23 13:35:22 -04:00
|
|
|
buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(`
|
2015-08-25 17:23:52 -04:00
|
|
|
FROM busybox
|
|
|
|
ENTRYPOINT ["/bin/echo"]
|
|
|
|
ENV FOO foo
|
|
|
|
ENV BAR bar
|
|
|
|
CMD echo %s
|
2017-01-16 05:30:14 -05:00
|
|
|
`, repo)))
|
2015-08-25 17:23:52 -04:00
|
|
|
dockerCmd(c, "push", repo)
|
|
|
|
repos = append(repos, repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear local images store.
|
|
|
|
args := append([]string{"rmi"}, repos...)
|
|
|
|
dockerCmd(c, args...)
|
|
|
|
|
|
|
|
// Re-pull individual tags, in parallel
|
2020-02-25 17:13:25 -05:00
|
|
|
results := make(chan error, len(repos))
|
2015-08-25 17:23:52 -04:00
|
|
|
|
|
|
|
for _, repo := range repos {
|
|
|
|
go func(repo string) {
|
2017-01-05 06:38:34 -05:00
|
|
|
result := icmd.RunCommand(dockerBinary, "pull", repo)
|
|
|
|
results <- result.Error
|
2015-08-25 17:23:52 -04:00
|
|
|
}(repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
// These checks are separate from the loop above because the check
|
|
|
|
// package is not goroutine-safe.
|
|
|
|
for range repos {
|
|
|
|
err := <-results
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "concurrent pull failed with error: %v", err)
|
2015-08-25 17:23:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure all tags were pulled successfully
|
|
|
|
for _, repo := range repos {
|
|
|
|
dockerCmd(c, "inspect", repo)
|
|
|
|
out, _ := dockerCmd(c, "run", "--rm", repo)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo)
|
2015-08-25 17:23:52 -04:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 17:20:54 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(c *testing.T) {
|
2015-12-18 18:06:23 -05:00
|
|
|
testConcurrentPullMultipleTags(c)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) TestConcurrentPullMultipleTags(c *testing.T) {
|
2019-06-17 17:50:31 -04:00
|
|
|
testConcurrentPullMultipleTags(c)
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
// testPullIDStability verifies that pushing an image and pulling it back
|
2015-11-18 17:20:54 -05:00
|
|
|
// preserves the image ID.
|
2019-09-09 17:05:55 -04:00
|
|
|
func testPullIDStability(c *testing.T) {
|
2015-11-18 17:20:54 -05:00
|
|
|
derivedImage := privateRegistryURL + "/dockercli/id-stability"
|
|
|
|
baseImage := "busybox"
|
|
|
|
|
2017-03-23 13:35:22 -04:00
|
|
|
buildImageSuccessfully(c, derivedImage, build.WithDockerfile(fmt.Sprintf(`
|
2015-11-18 17:20:54 -05:00
|
|
|
FROM %s
|
|
|
|
ENV derived true
|
|
|
|
ENV asdf true
|
|
|
|
RUN dd if=/dev/zero of=/file bs=1024 count=1024
|
|
|
|
CMD echo %s
|
2017-01-16 05:30:14 -05:00
|
|
|
`, baseImage, derivedImage)))
|
2015-11-18 17:20:54 -05:00
|
|
|
|
2017-01-16 05:30:14 -05:00
|
|
|
originalID := getIDByName(c, derivedImage)
|
2015-11-18 17:20:54 -05:00
|
|
|
dockerCmd(c, "push", derivedImage)
|
|
|
|
|
|
|
|
// Pull
|
|
|
|
out, _ := dockerCmd(c, "pull", derivedImage)
|
|
|
|
if strings.Contains(out, "Pull complete") {
|
|
|
|
c.Fatalf("repull redownloaded a layer: %s", out)
|
|
|
|
}
|
|
|
|
|
2017-01-16 05:30:14 -05:00
|
|
|
derivedIDAfterPull := getIDByName(c, derivedImage)
|
2015-11-18 17:20:54 -05:00
|
|
|
|
|
|
|
if derivedIDAfterPull != originalID {
|
|
|
|
c.Fatal("image's ID unexpectedly changed after a repush/repull")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the image runs correctly
|
|
|
|
out, _ = dockerCmd(c, "run", "--rm", derivedImage)
|
|
|
|
if strings.TrimSpace(out) != derivedImage {
|
|
|
|
c.Fatalf("expected %s; got %s", derivedImage, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm that repushing and repulling does not change the computed ID
|
|
|
|
dockerCmd(c, "push", derivedImage)
|
|
|
|
dockerCmd(c, "rmi", derivedImage)
|
|
|
|
dockerCmd(c, "pull", derivedImage)
|
|
|
|
|
2017-01-16 05:30:14 -05:00
|
|
|
derivedIDAfterPull = getIDByName(c, derivedImage)
|
2015-11-18 17:20:54 -05:00
|
|
|
|
|
|
|
if derivedIDAfterPull != originalID {
|
|
|
|
c.Fatal("image's ID unexpectedly changed after a repush/repull")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the image still runs
|
|
|
|
out, _ = dockerCmd(c, "run", "--rm", derivedImage)
|
|
|
|
if strings.TrimSpace(out) != derivedImage {
|
|
|
|
c.Fatalf("expected %s; got %s", derivedImage, out)
|
|
|
|
}
|
|
|
|
}
|
2015-12-21 18:42:04 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPullIDStability(c *testing.T) {
|
2015-12-18 18:06:23 -05:00
|
|
|
testPullIDStability(c)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *testing.T) {
|
2019-06-17 17:50:31 -04:00
|
|
|
testPullIDStability(c)
|
|
|
|
}
|
|
|
|
|
2016-03-15 14:10:03 -04:00
|
|
|
// #21213
|
2019-09-09 17:05:55 -04:00
|
|
|
func testPullNoLayers(c *testing.T) {
|
2016-03-15 14:10:03 -04:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL)
|
|
|
|
|
2017-03-23 13:35:22 -04:00
|
|
|
buildImageSuccessfully(c, repoName, build.WithDockerfile(`
|
2016-03-15 14:10:03 -04:00
|
|
|
FROM scratch
|
2017-01-16 05:30:14 -05:00
|
|
|
ENV foo bar`))
|
2016-03-15 14:10:03 -04:00
|
|
|
dockerCmd(c, "push", repoName)
|
|
|
|
dockerCmd(c, "rmi", repoName)
|
|
|
|
dockerCmd(c, "pull", repoName)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPullNoLayers(c *testing.T) {
|
2016-03-15 14:10:03 -04:00
|
|
|
testPullNoLayers(c)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) TestPullNoLayers(c *testing.T) {
|
2019-06-17 17:50:31 -04:00
|
|
|
testPullNoLayers(c)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) {
|
2015-11-25 18:38:33 -05:00
|
|
|
testRequires(c, NotArm)
|
2015-12-18 19:03:38 -05:00
|
|
|
pushDigest, err := setupImage(c)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "error setting up image")
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
// Inject a manifest list into the registry
|
|
|
|
manifestList := &manifestlist.ManifestList{
|
|
|
|
Versioned: manifest.Versioned{
|
|
|
|
SchemaVersion: 2,
|
|
|
|
MediaType: manifestlist.MediaTypeManifestList,
|
|
|
|
},
|
|
|
|
Manifests: []manifestlist.ManifestDescriptor{
|
|
|
|
{
|
|
|
|
Descriptor: distribution.Descriptor{
|
|
|
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
|
|
|
Size: 3253,
|
|
|
|
MediaType: schema2.MediaTypeManifest,
|
|
|
|
},
|
|
|
|
Platform: manifestlist.PlatformSpec{
|
|
|
|
Architecture: "bogus_arch",
|
|
|
|
OS: "bogus_os",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Descriptor: distribution.Descriptor{
|
|
|
|
Digest: pushDigest,
|
|
|
|
Size: 3253,
|
|
|
|
MediaType: schema2.MediaTypeManifest,
|
|
|
|
},
|
|
|
|
Platform: manifestlist.PlatformSpec{
|
|
|
|
Architecture: runtime.GOARCH,
|
|
|
|
OS: runtime.GOOS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
manifestListJSON, err := json.MarshalIndent(manifestList, "", " ")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "error marshalling manifest list")
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
manifestListDigest := digest.FromBytes(manifestListJSON)
|
|
|
|
hexDigest := manifestListDigest.Hex()
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
registryV2Path := s.reg.Path()
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
// Write manifest list to blob store
|
|
|
|
blobDir := filepath.Join(registryV2Path, "blobs", "sha256", hexDigest[:2], hexDigest)
|
|
|
|
err = os.MkdirAll(blobDir, 0755)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "error creating blob dir")
|
2015-12-18 19:03:38 -05:00
|
|
|
blobPath := filepath.Join(blobDir, "data")
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(blobPath, manifestListJSON, 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "error writing manifest list")
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
// Add to revision store
|
|
|
|
revisionDir := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "revisions", "sha256", hexDigest)
|
|
|
|
err = os.Mkdir(revisionDir, 0755)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, err == nil, "error creating revision dir")
|
2015-12-18 19:03:38 -05:00
|
|
|
revisionPath := filepath.Join(revisionDir, "link")
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(revisionPath, []byte(manifestListDigest.String()), 0644)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, err == nil, "error writing revision link")
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
// Update tag
|
|
|
|
tagPath := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "tags", "latest", "current", "link")
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(tagPath, []byte(manifestListDigest.String()), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "error writing tag link")
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
// Verify that the image can be pulled through the manifest list.
|
|
|
|
out, _ := dockerCmd(c, "pull", repoName)
|
|
|
|
|
|
|
|
// The pull output includes "Digest: <digest>", so find that
|
|
|
|
matches := digestRegex.FindStringSubmatch(out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out))
|
2015-12-18 19:03:38 -05:00
|
|
|
pullDigest := matches[1]
|
|
|
|
|
|
|
|
// Make sure the pushed and pull digests match
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Equal(c, manifestListDigest.String(), pullDigest)
|
2015-12-18 19:03:38 -05:00
|
|
|
|
|
|
|
// Was the image actually created?
|
|
|
|
dockerCmd(c, "inspect", repoName)
|
|
|
|
|
|
|
|
dockerCmd(c, "rmi", repoName)
|
|
|
|
}
|
2016-02-07 19:55:17 -05:00
|
|
|
|
2016-05-30 06:47:49 -04:00
|
|
|
// #23100
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithScheme(c *testing.T) {
|
2016-05-30 06:47:49 -04:00
|
|
|
osPath := os.Getenv("PATH")
|
|
|
|
defer os.Setenv("PATH", osPath)
|
|
|
|
|
|
|
|
workingDir, err := os.Getwd()
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
|
|
|
|
|
|
|
|
os.Setenv("PATH", testPath)
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
tmp, err := os.MkdirTemp("", "integration-cli-")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
|
|
|
|
externalAuthConfig := `{ "credsStore": "shell-test" }`
|
|
|
|
|
|
|
|
configPath := filepath.Join(tmp, "config.json")
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(configPath, []byte(externalAuthConfig), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-05-30 06:47:49 -04:00
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
|
2016-05-30 06:47:49 -04:00
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
b, err := os.ReadFile(configPath)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:07:46 -04:00
|
|
|
assert.Assert(c, !strings.Contains(string(b), "\"auth\":"))
|
2016-05-30 06:47:49 -04:00
|
|
|
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
|
|
|
|
dockerCmd(c, "--config", tmp, "push", repoName)
|
|
|
|
|
|
|
|
dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), "https://"+privateRegistryURL)
|
2016-05-30 06:47:49 -04:00
|
|
|
dockerCmd(c, "--config", tmp, "pull", repoName)
|
|
|
|
|
|
|
|
// likewise push should work
|
|
|
|
repoName2 := fmt.Sprintf("%v/dockercli/busybox:nocreds", privateRegistryURL)
|
|
|
|
dockerCmd(c, "tag", repoName, repoName2)
|
|
|
|
dockerCmd(c, "--config", tmp, "push", repoName2)
|
|
|
|
|
|
|
|
// logout should work w scheme also because it will be stripped
|
|
|
|
dockerCmd(c, "--config", tmp, "logout", "https://"+privateRegistryURL)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *testing.T) {
|
2016-02-07 19:55:17 -05:00
|
|
|
osPath := os.Getenv("PATH")
|
|
|
|
defer os.Setenv("PATH", osPath)
|
|
|
|
|
|
|
|
workingDir, err := os.Getwd()
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-02-07 19:55:17 -05:00
|
|
|
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-02-07 19:55:17 -05:00
|
|
|
testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
|
|
|
|
|
|
|
|
os.Setenv("PATH", testPath)
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
tmp, err := os.MkdirTemp("", "integration-cli-")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-02-07 19:55:17 -05:00
|
|
|
|
|
|
|
externalAuthConfig := `{ "credsStore": "shell-test" }`
|
|
|
|
|
|
|
|
configPath := filepath.Join(tmp, "config.json")
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(configPath, []byte(externalAuthConfig), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-02-07 19:55:17 -05:00
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
|
2016-02-07 19:55:17 -05:00
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
b, err := os.ReadFile(configPath)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:07:46 -04:00
|
|
|
assert.Assert(c, !strings.Contains(string(b), "\"auth\":"))
|
2016-02-07 19:55:17 -05:00
|
|
|
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
|
|
|
|
dockerCmd(c, "--config", tmp, "push", repoName)
|
|
|
|
|
|
|
|
dockerCmd(c, "--config", tmp, "pull", repoName)
|
|
|
|
}
|
2016-05-02 18:23:22 -04:00
|
|
|
|
2016-05-19 18:52:42 -04:00
|
|
|
// TestRunImplicitPullWithNoTag should pull implicitly only the default tag (latest)
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *testing.T) {
|
2016-05-02 18:23:22 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
repo := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
repoTag1 := fmt.Sprintf("%v:latest", repo)
|
|
|
|
repoTag2 := fmt.Sprintf("%v:t1", repo)
|
|
|
|
// tag the image and upload it to the private registry
|
|
|
|
dockerCmd(c, "tag", "busybox", repoTag1)
|
|
|
|
dockerCmd(c, "tag", "busybox", repoTag2)
|
|
|
|
dockerCmd(c, "push", repo)
|
|
|
|
dockerCmd(c, "rmi", repoTag1)
|
|
|
|
dockerCmd(c, "rmi", repoTag2)
|
|
|
|
|
2017-01-17 21:08:31 -05:00
|
|
|
out, _ := dockerCmd(c, "run", repo)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Unable to find image '%s:latest' locally", repo)))
|
2016-05-02 18:23:22 -04:00
|
|
|
// There should be only one line for repo, the one with repo:latest
|
2017-01-17 21:08:31 -05:00
|
|
|
outImageCmd, _ := dockerCmd(c, "images", repo)
|
2016-05-02 18:23:22 -04:00
|
|
|
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(splitOutImageCmd), 2)
|
2016-05-02 18:23:22 -04:00
|
|
|
}
|