From d477d42dd3e6a98f82c6ed2abb1dfeeb2782539f Mon Sep 17 00:00:00 2001 From: Euan Date: Sat, 24 Jan 2015 13:08:47 -0800 Subject: [PATCH] Allow empty layer configs in manifests Before the V2 registry changes, images with no config could be pushed. This change fixes a regression that made those images not able to be pushed to a registry. Signed-off-by: Euan Kemp --- graph/manifest.go | 8 +++--- integration-cli/docker_cli_push_test.go | 36 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/graph/manifest.go b/graph/manifest.go index 3d4ab1c5de..18784bb1e0 100644 --- a/graph/manifest.go +++ b/graph/manifest.go @@ -3,7 +3,6 @@ package graph import ( "bytes" "encoding/json" - "errors" "fmt" "io" "io/ioutil" @@ -71,14 +70,13 @@ func (s *TagStore) newManifest(localName, remoteName, tag string) ([]byte, error if err != nil { return nil, err } - if layer.Config == nil { - return nil, errors.New("Missing layer configuration") - } manifest.Architecture = layer.Architecture manifest.FSLayers = make([]*registry.FSLayer, 0, 4) manifest.History = make([]*registry.ManifestHistory, 0, 4) var metadata runconfig.Config - metadata = *layer.Config + if layer.Config != nil { + metadata = *layer.Config + } for ; layer != nil; layer, err = layer.GetParent() { if err != nil { diff --git a/integration-cli/docker_cli_push_test.go b/integration-cli/docker_cli_push_test.go index 484e5db70b..0b2decde70 100644 --- a/integration-cli/docker_cli_push_test.go +++ b/integration-cli/docker_cli_push_test.go @@ -2,10 +2,14 @@ package main import ( "fmt" + "io/ioutil" + "os" "os/exec" "strings" "testing" "time" + + "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" ) // pulling an image from the central registry should work @@ -80,3 +84,35 @@ func TestPushInterrupt(t *testing.T) { logDone("push - interrupted") } + +func TestPushEmptyLayer(t *testing.T) { + defer setupRegistry(t)() + repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL) + emptyTarball, err := ioutil.TempFile("", "empty_tarball") + if err != nil { + t.Fatalf("Unable to create test file: %v", err) + } + tw := tar.NewWriter(emptyTarball) + err = tw.Close() + if err != nil { + t.Fatalf("Error creating empty tarball: %v", err) + } + freader, err := os.Open(emptyTarball.Name()) + if err != nil { + t.Fatalf("Could not open test tarball: %v", err) + } + + importCmd := exec.Command(dockerBinary, "import", "-", repoName) + importCmd.Stdin = freader + out, _, err := runCommandWithOutput(importCmd) + if err != nil { + t.Errorf("import failed with errors: %v, output: %q", err, out) + } + + // Now verify we can push it + pushCmd := exec.Command(dockerBinary, "push", repoName) + if out, _, err := runCommandWithOutput(pushCmd); err != nil { + t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err) + } + logDone("push - empty layer config to private registry") +}