1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <euank@euank.com>
This commit is contained in:
Euan 2015-01-24 13:08:47 -08:00 committed by euank
parent 990a3e30fa
commit d477d42dd3
2 changed files with 39 additions and 5 deletions

View file

@ -3,7 +3,6 @@ package graph
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -71,14 +70,13 @@ func (s *TagStore) newManifest(localName, remoteName, tag string) ([]byte, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
if layer.Config == nil {
return nil, errors.New("Missing layer configuration")
}
manifest.Architecture = layer.Architecture manifest.Architecture = layer.Architecture
manifest.FSLayers = make([]*registry.FSLayer, 0, 4) manifest.FSLayers = make([]*registry.FSLayer, 0, 4)
manifest.History = make([]*registry.ManifestHistory, 0, 4) manifest.History = make([]*registry.ManifestHistory, 0, 4)
var metadata runconfig.Config var metadata runconfig.Config
metadata = *layer.Config if layer.Config != nil {
metadata = *layer.Config
}
for ; layer != nil; layer, err = layer.GetParent() { for ; layer != nil; layer, err = layer.GetParent() {
if err != nil { if err != nil {

View file

@ -2,10 +2,14 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os"
"os/exec" "os/exec"
"strings" "strings"
"testing" "testing"
"time" "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 // pulling an image from the central registry should work
@ -80,3 +84,35 @@ func TestPushInterrupt(t *testing.T) {
logDone("push - interrupted") 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")
}