2018-02-05 16:05:59 -05:00
|
|
|
package dockerfile // import "github.com/docker/docker/builder/dockerfile"
|
2017-04-13 18:44:36 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/builder"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-04-13 18:44:36 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ImageProber exposes an Image cache to the Builder. It supports resetting a
|
|
|
|
// cache.
|
|
|
|
type ImageProber interface {
|
|
|
|
Reset()
|
|
|
|
Probe(parentID string, runConfig *container.Config) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type imageProber struct {
|
|
|
|
cache builder.ImageCache
|
|
|
|
reset func() builder.ImageCache
|
|
|
|
cacheBusted bool
|
|
|
|
}
|
|
|
|
|
2017-08-24 14:48:16 -04:00
|
|
|
func newImageProber(cacheBuilder builder.ImageCacheBuilder, cacheFrom []string, noCache bool) ImageProber {
|
2017-04-13 18:44:36 -04:00
|
|
|
if noCache {
|
|
|
|
return &nopProber{}
|
|
|
|
}
|
|
|
|
|
|
|
|
reset := func() builder.ImageCache {
|
2017-08-24 14:48:16 -04:00
|
|
|
return cacheBuilder.MakeImageCache(cacheFrom)
|
2017-04-13 18:44:36 -04:00
|
|
|
}
|
|
|
|
return &imageProber{cache: reset(), reset: reset}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *imageProber) Reset() {
|
|
|
|
c.cache = c.reset()
|
|
|
|
c.cacheBusted = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Probe checks if cache match can be found for current build instruction.
|
|
|
|
// It returns the cachedID if there is a hit, and the empty string on miss
|
|
|
|
func (c *imageProber) Probe(parentID string, runConfig *container.Config) (string, error) {
|
|
|
|
if c.cacheBusted {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
cacheID, err := c.cache.GetCache(parentID, runConfig)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if len(cacheID) == 0 {
|
|
|
|
logrus.Debugf("[BUILDER] Cache miss: %s", runConfig.Cmd)
|
|
|
|
c.cacheBusted = true
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
logrus.Debugf("[BUILDER] Use cached version: %s", runConfig.Cmd)
|
|
|
|
return cacheID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type nopProber struct{}
|
|
|
|
|
|
|
|
func (c *nopProber) Reset() {}
|
|
|
|
|
|
|
|
func (c *nopProber) Probe(_ string, _ *container.Config) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|