Skip to content

Commit

Permalink
add log lines for building multiple targets
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Suraci <[email protected]>
Co-authored-by: Taylor Silva <[email protected]>
  • Loading branch information
vito and taylorsilva committed Jan 7, 2021
1 parent 02d8430 commit 25121ea
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package task

import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -63,6 +64,7 @@ func Build(buildkitd *Buildkitd, outputsDir string, req Request) (Response, erro
}

var builds [][]string
var targets []string
var imagePaths []string

for _, t := range cfg.AdditionalTargets {
Expand All @@ -85,6 +87,7 @@ func Build(buildkitd *Buildkitd, outputsDir string, req Request) (Response, erro
}

builds = append(builds, targetArgs)
targets = append(targets, t)
}

finalTargetDir := filepath.Join(outputsDir, "image")
Expand All @@ -104,18 +107,28 @@ func Build(buildkitd *Buildkitd, outputsDir string, req Request) (Response, erro
}

builds = append(builds, buildctlArgs)
targets = append(targets, "")

for _, args := range builds {
logrus.WithFields(logrus.Fields{
"buildctl-args": args,
}).Debug("building")
for i, args := range builds {
if i > 0 {
fmt.Fprintln(os.Stderr)
}

targetName := targets[i]
if targetName == "" {
logrus.Info("building image")
} else {
logrus.Infof("building target '%s'", targetName)
}

if _, err := os.Stat(filepath.Join(cacheDir, "index.json")); err == nil {
args = append(args,
"--import-cache", "type=local,src="+cacheDir,
)
}

logrus.Debugf("running buildctl %s", strings.Join(args, " "))

err = buildctl(buildkitd.Addr, os.Stdout, args...)
if err != nil {
return Response{}, errors.Wrap(err, "build")
Expand Down

0 comments on commit 25121ea

Please sign in to comment.