Browse code

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>

Euan authored on 2015/01/25 06:08:47
Showing 2 changed files
... ...
@@ -3,7 +3,6 @@ package graph
3 3
 import (
4 4
 	"bytes"
5 5
 	"encoding/json"
6
-	"errors"
7 6
 	"fmt"
8 7
 	"io"
9 8
 	"io/ioutil"
... ...
@@ -71,14 +70,13 @@ func (s *TagStore) newManifest(localName, remoteName, tag string) ([]byte, error
71 71
 	if err != nil {
72 72
 		return nil, err
73 73
 	}
74
-	if layer.Config == nil {
75
-		return nil, errors.New("Missing layer configuration")
76
-	}
77 74
 	manifest.Architecture = layer.Architecture
78 75
 	manifest.FSLayers = make([]*registry.FSLayer, 0, 4)
79 76
 	manifest.History = make([]*registry.ManifestHistory, 0, 4)
80 77
 	var metadata runconfig.Config
81
-	metadata = *layer.Config
78
+	if layer.Config != nil {
79
+		metadata = *layer.Config
80
+	}
82 81
 
83 82
 	for ; layer != nil; layer, err = layer.GetParent() {
84 83
 		if err != nil {
... ...
@@ -2,10 +2,14 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"io/ioutil"
6
+	"os"
5 7
 	"os/exec"
6 8
 	"strings"
7 9
 	"testing"
8 10
 	"time"
11
+
12
+	"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
9 13
 )
10 14
 
11 15
 // pulling an image from the central registry should work
... ...
@@ -80,3 +84,35 @@ func TestPushInterrupt(t *testing.T) {
80 80
 
81 81
 	logDone("push - interrupted")
82 82
 }
83
+
84
+func TestPushEmptyLayer(t *testing.T) {
85
+	defer setupRegistry(t)()
86
+	repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
87
+	emptyTarball, err := ioutil.TempFile("", "empty_tarball")
88
+	if err != nil {
89
+		t.Fatalf("Unable to create test file: %v", err)
90
+	}
91
+	tw := tar.NewWriter(emptyTarball)
92
+	err = tw.Close()
93
+	if err != nil {
94
+		t.Fatalf("Error creating empty tarball: %v", err)
95
+	}
96
+	freader, err := os.Open(emptyTarball.Name())
97
+	if err != nil {
98
+		t.Fatalf("Could not open test tarball: %v", err)
99
+	}
100
+
101
+	importCmd := exec.Command(dockerBinary, "import", "-", repoName)
102
+	importCmd.Stdin = freader
103
+	out, _, err := runCommandWithOutput(importCmd)
104
+	if err != nil {
105
+		t.Errorf("import failed with errors: %v, output: %q", err, out)
106
+	}
107
+
108
+	// Now verify we can push it
109
+	pushCmd := exec.Command(dockerBinary, "push", repoName)
110
+	if out, _, err := runCommandWithOutput(pushCmd); err != nil {
111
+		t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
112
+	}
113
+	logDone("push - empty layer config to private registry")
114
+}