|
@@ -86,21 +86,29 @@ func (s *buildStages) update(imageID string) {
|
|
s.sequence[len(s.sequence)-1].update(imageID)
|
|
s.sequence[len(s.sequence)-1].update(imageID)
|
|
}
|
|
}
|
|
|
|
|
|
-type getAndMountFunc func(string) (builder.Image, builder.ReleaseableLayer, error)
|
|
|
|
|
|
+type getAndMountFunc func(string, bool) (builder.Image, builder.ReleaseableLayer, error)
|
|
|
|
|
|
// imageSources mounts images and provides a cache for mounted images. It tracks
|
|
// imageSources mounts images and provides a cache for mounted images. It tracks
|
|
// all images so they can be unmounted at the end of the build.
|
|
// all images so they can be unmounted at the end of the build.
|
|
type imageSources struct {
|
|
type imageSources struct {
|
|
byImageID map[string]*imageMount
|
|
byImageID map[string]*imageMount
|
|
- withoutID []*imageMount
|
|
|
|
|
|
+ mounts []*imageMount
|
|
getImage getAndMountFunc
|
|
getImage getAndMountFunc
|
|
cache pathCache // TODO: remove
|
|
cache pathCache // TODO: remove
|
|
}
|
|
}
|
|
|
|
|
|
func newImageSources(ctx context.Context, options builderOptions) *imageSources {
|
|
func newImageSources(ctx context.Context, options builderOptions) *imageSources {
|
|
- getAndMount := func(idOrRef string) (builder.Image, builder.ReleaseableLayer, error) {
|
|
|
|
|
|
+ getAndMount := func(idOrRef string, localOnly bool) (builder.Image, builder.ReleaseableLayer, error) {
|
|
|
|
+ pullOption := backend.PullOptionNoPull
|
|
|
|
+ if !localOnly {
|
|
|
|
+ if options.Options.PullParent {
|
|
|
|
+ pullOption = backend.PullOptionForcePull
|
|
|
|
+ } else {
|
|
|
|
+ pullOption = backend.PullOptionPreferLocal
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return options.Backend.GetImageAndReleasableLayer(ctx, idOrRef, backend.GetImageAndLayerOptions{
|
|
return options.Backend.GetImageAndReleasableLayer(ctx, idOrRef, backend.GetImageAndLayerOptions{
|
|
- ForcePull: options.Options.PullParent,
|
|
|
|
|
|
+ PullOption: pullOption,
|
|
AuthConfig: options.Options.AuthConfigs,
|
|
AuthConfig: options.Options.AuthConfigs,
|
|
Output: options.ProgressWriter.Output,
|
|
Output: options.ProgressWriter.Output,
|
|
})
|
|
})
|
|
@@ -112,12 +120,12 @@ func newImageSources(ctx context.Context, options builderOptions) *imageSources
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (m *imageSources) Get(idOrRef string) (*imageMount, error) {
|
|
|
|
|
|
+func (m *imageSources) Get(idOrRef string, localOnly bool) (*imageMount, error) {
|
|
if im, ok := m.byImageID[idOrRef]; ok {
|
|
if im, ok := m.byImageID[idOrRef]; ok {
|
|
return im, nil
|
|
return im, nil
|
|
}
|
|
}
|
|
|
|
|
|
- image, layer, err := m.getImage(idOrRef)
|
|
|
|
|
|
+ image, layer, err := m.getImage(idOrRef, localOnly)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -127,13 +135,7 @@ func (m *imageSources) Get(idOrRef string) (*imageMount, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func (m *imageSources) Unmount() (retErr error) {
|
|
func (m *imageSources) Unmount() (retErr error) {
|
|
- for _, im := range m.byImageID {
|
|
|
|
- if err := im.unmount(); err != nil {
|
|
|
|
- logrus.Error(err)
|
|
|
|
- retErr = err
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- for _, im := range m.withoutID {
|
|
|
|
|
|
+ for _, im := range m.mounts {
|
|
if err := im.unmount(); err != nil {
|
|
if err := im.unmount(); err != nil {
|
|
logrus.Error(err)
|
|
logrus.Error(err)
|
|
retErr = err
|
|
retErr = err
|
|
@@ -146,10 +148,10 @@ func (m *imageSources) Add(im *imageMount) {
|
|
switch im.image {
|
|
switch im.image {
|
|
case nil:
|
|
case nil:
|
|
im.image = &dockerimage.Image{}
|
|
im.image = &dockerimage.Image{}
|
|
- m.withoutID = append(m.withoutID, im)
|
|
|
|
default:
|
|
default:
|
|
m.byImageID[im.image.ImageID()] = im
|
|
m.byImageID[im.image.ImageID()] = im
|
|
}
|
|
}
|
|
|
|
+ m.mounts = append(m.mounts, im)
|
|
}
|
|
}
|
|
|
|
|
|
// imageMount is a reference to an image that can be used as a builder.Source
|
|
// imageMount is a reference to an image that can be used as a builder.Source
|