Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ func (p Plugin) Exec() error {
cmds = append(cmds, commandVersion()) // docker version
cmds = append(cmds, commandInfo()) // docker info

// pre-pull cache images
for _, img := range p.Build.CacheFrom {
cmds = append(cmds, commandPull(img))
if wantPrepull(p) {
// pre-pull cache images
for _, img := range p.Build.CacheFrom {
cmds = append(cmds, commandPull(img))
}
} else {
fmt.Println("Detected Buildkit with inline cache, will not pre-pull cache image.")
}

cmds = append(cmds, commandBuild(p.Build)) // docker build
Expand Down Expand Up @@ -227,6 +231,22 @@ func (p Plugin) Exec() error {
return nil
}

// helper function to determine if we should prepull a cache image
func wantPrepull(p Plugin) bool {
var inlineCache = false
for _, v := range p.Build.Args {
if v == "BUILDKIT_INLINE_CACHE=1" {
inlineCache = true
break
}
}

// if we have both buildkit and buildkit inline cache available, then
// that is preferable to prepulling a cache image, for more details:
// https://github.com/drone-plugins/drone-docker/pull/360
return os.Getenv("DOCKER_BUILDKIT") != "1" || !inlineCache
}

// helper function to create the docker login command.
func commandLogin(login Login) *exec.Cmd {
if login.Email != "" {
Expand Down