Browse code

Use constant instead of "scratch"

Move NoBaseImageSpecifier to a common spot and then use it instead of
"scratch" in a couple of places.

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/12/31 22:57:58
Showing 4 changed files
... ...
@@ -584,7 +584,7 @@ func rewriteDockerfileFrom(dockerfileName string, translator func(reference.Name
584 584
 		line := scanner.Text()
585 585
 
586 586
 		matches := dockerfileFromLinePattern.FindStringSubmatch(line)
587
-		if matches != nil && matches[1] != "scratch" {
587
+		if matches != nil && matches[1] != api.NoBaseImageSpecifier {
588 588
 			// Replace the line with a resolved "FROM repo@digest"
589 589
 			ref, err := reference.ParseNamed(matches[1])
590 590
 			if err != nil {
... ...
@@ -25,6 +25,10 @@ const (
25 25
 
26 26
 	// DefaultDockerfileName is the Default filename with Docker commands, read by docker build
27 27
 	DefaultDockerfileName string = "Dockerfile"
28
+
29
+	// NoBaseImageSpecifier is the symbol used by the FROM
30
+	// command to specify that no base image is to be used.
31
+	NoBaseImageSpecifier string = "scratch"
28 32
 )
29 33
 
30 34
 // byPortInfo is a temporary type used to sort types.Port by its fields
... ...
@@ -17,6 +17,7 @@ import (
17 17
 	"strings"
18 18
 
19 19
 	"github.com/Sirupsen/logrus"
20
+	"github.com/docker/docker/api"
20 21
 	"github.com/docker/docker/api/types/container"
21 22
 	"github.com/docker/docker/api/types/strslice"
22 23
 	"github.com/docker/docker/builder"
... ...
@@ -27,12 +28,6 @@ import (
27 27
 	"github.com/docker/go-connections/nat"
28 28
 )
29 29
 
30
-const (
31
-	// NoBaseImageSpecifier is the symbol used by the FROM
32
-	// command to specify that no base image is to be used.
33
-	NoBaseImageSpecifier string = "scratch"
34
-)
35
-
36 30
 // dispatch with no layer / parsing. This is effectively not a command.
37 31
 func nullDispatch(b *Builder, args []string, attributes map[string]bool, original string) error {
38 32
 	return nil
... ...
@@ -199,7 +194,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
199 199
 	name := args[0]
200 200
 
201 201
 	// Windows cannot support a container with no base image.
202
-	if name == NoBaseImageSpecifier {
202
+	if name == api.NoBaseImageSpecifier {
203 203
 		if runtime.GOOS == "windows" {
204 204
 			return fmt.Errorf("Windows does not support FROM scratch")
205 205
 		}
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"strings"
7 7
 
8 8
 	"github.com/Sirupsen/logrus"
9
+	"github.com/docker/docker/api"
9 10
 	"github.com/docker/docker/api/types"
10 11
 	"github.com/docker/docker/daemon/events"
11 12
 	"github.com/docker/docker/distribution/metadata"
... ...
@@ -191,8 +192,8 @@ func validateRepoName(name string) error {
191 191
 	if name == "" {
192 192
 		return fmt.Errorf("Repository name can't be empty")
193 193
 	}
194
-	if name == "scratch" {
195
-		return fmt.Errorf("'scratch' is a reserved name")
194
+	if name == api.NoBaseImageSpecifier {
195
+		return fmt.Errorf("'%s' is a reserved name", api.NoBaseImageSpecifier)
196 196
 	}
197 197
 	return nil
198 198
 }