|
@@ -227,27 +227,28 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- // Windows cannot support a container with no base image.
|
|
|
- if name == api.NoBaseImageSpecifier {
|
|
|
- if runtime.GOOS == "windows" {
|
|
|
- return errors.New("Windows does not support FROM scratch")
|
|
|
+ if im, ok := b.imageContexts.byName[name]; ok {
|
|
|
+ if len(im.ImageID()) > 0 {
|
|
|
+ image = im
|
|
|
}
|
|
|
- b.image = ""
|
|
|
- b.noBaseImage = true
|
|
|
} else {
|
|
|
- // TODO: don't use `name`, instead resolve it to a digest
|
|
|
- if !b.options.PullParent {
|
|
|
- image, _ = b.docker.GetImageOnBuild(name)
|
|
|
- // TODO: shouldn't we error out if error is different from "not found" ?
|
|
|
- }
|
|
|
- if image == nil {
|
|
|
+ // Windows cannot support a container with no base image.
|
|
|
+ if name == api.NoBaseImageSpecifier {
|
|
|
+ if runtime.GOOS == "windows" {
|
|
|
+ return errors.New("Windows does not support FROM scratch")
|
|
|
+ }
|
|
|
+ b.image = ""
|
|
|
+ b.noBaseImage = true
|
|
|
+ } else {
|
|
|
var err error
|
|
|
- image, err = b.docker.PullOnBuild(b.clientCtx, name, b.options.AuthConfigs, b.Output)
|
|
|
+ image, err = pullOrGetImage(b, name)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
- b.imageContexts.update(image.ImageID())
|
|
|
+ }
|
|
|
+ if image != nil {
|
|
|
+ b.imageContexts.update(image.ImageID(), image.RunConfig())
|
|
|
}
|
|
|
b.from = image
|
|
|
|
|
@@ -838,9 +839,23 @@ func getShell(c *container.Config) []string {
|
|
|
|
|
|
// mountByRef creates an imageMount from a reference. pulling the image if needed.
|
|
|
func mountByRef(b *Builder, name string) (*imageMount, error) {
|
|
|
+ image, err := pullOrGetImage(b, name)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ im, err := b.imageContexts.new("", false)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ im.id = image.ImageID()
|
|
|
+ return im, nil
|
|
|
+}
|
|
|
+
|
|
|
+func pullOrGetImage(b *Builder, name string) (builder.Image, error) {
|
|
|
var image builder.Image
|
|
|
if !b.options.PullParent {
|
|
|
image, _ = b.docker.GetImageOnBuild(name)
|
|
|
+ // TODO: shouldn't we error out if error is different from "not found" ?
|
|
|
}
|
|
|
if image == nil {
|
|
|
var err error
|
|
@@ -849,10 +864,5 @@ func mountByRef(b *Builder, name string) (*imageMount, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
- im, err := b.imageContexts.new("", false)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- im.id = image.ImageID()
|
|
|
- return im, nil
|
|
|
+ return image, nil
|
|
|
}
|