builder: Fix releasing implicit mounts
@@ -20,7 +20,8 @@ type pathCache interface {
// them as contexts
type imageContexts struct {
b *Builder
- list []*imageMount
+ list []*imageMount // indexed list of stages
+ implicitMounts []*imageMount // implicitly mounted images
byName map[string]*imageMount
cache pathCache
}
@@ -75,16 +76,19 @@ func (ic *imageContexts) get(indexOrName string) (*imageMount, error) {
if err != nil {
return nil, errors.Wrapf(err, "invalid from flag value %s", indexOrName)
}
+ ic.implicitMounts = append(ic.implicitMounts, im)
return im, nil
}
func (ic *imageContexts) unmount() (retErr error) {
- for _, im := range ic.list {
+ for _, iml := range append([][]*imageMount{}, ic.list, ic.implicitMounts) {
+ for _, im := range iml {
if err := im.unmount(); err != nil {
logrus.Error(err)
retErr = err
}
}
+ }
for _, im := range ic.byName {
if err := im.unmount(); err != nil {
logrus.Error(err)
