Skip to content

Commit

Permalink
Merge pull request #207 from depot/feat/depot-target-build-arg
Browse files Browse the repository at this point in the history
feat: send build target to buildkitd
  • Loading branch information
goller authored Oct 23, 2023
2 parents ae91490 + a07bdbb commit 1f8252a
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 541 deletions.
1 change: 1 addition & 0 deletions pkg/buildx/build/depot.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func BuildxOpts(opts map[string]dockerbuild.Options) map[string]Options {
}
}
}
opt.BuildArgs["DEPOT_TARGET"] = k

for _, e := range opt.Exports {
if e.Type == "image" {
Expand Down
15 changes: 2 additions & 13 deletions pkg/buildx/commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/depot/cli/pkg/buildx/build"
"github.com/depot/cli/pkg/buildx/builder"
"github.com/depot/cli/pkg/dockerfile"
"github.com/depot/cli/pkg/helpers"
"github.com/depot/cli/pkg/load"
depotprogress "github.com/depot/cli/pkg/progress"
Expand Down Expand Up @@ -84,15 +83,6 @@ func RunBake(dockerCli command.Cli, in BakeOptions, validator BakeValidator) (er
progress.Write(printer, "[depot] build: "+in.buildURL, func() error { return err })
}

// Upload dockerfile to API.
uploader := dockerfile.NewUploader(in.buildID, in.token)
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
uploader.Run(ctx2)
wg.Done()
}()

contextPathHash, _ := os.Getwd()
builderOpts := append([]builder.Option{builder.WithName(in.builder),
builder.WithContextPathHash(contextPathHash)}, in.builderOptions...)
Expand Down Expand Up @@ -148,9 +138,8 @@ func RunBake(dockerCli command.Cli, in BakeOptions, validator BakeValidator) (er
return wrapBuildError(err, true)
}

linter := NewLinter(NewLintFailureMode(in.lint, in.lintFailOn), clients, buildxNodes)
dockerfileHandlers := build.NewDockerfileHandlers(uploader, linter)
resp, err := build.DepotBuild(ctx, buildxNodes, buildOpts, dockerClient, dockerConfigDir, buildxprinter, dockerfileHandlers)
linter := NewLinter(printer, NewLintFailureMode(in.lint, in.lintFailOn), clients, buildxNodes)
resp, err := build.DepotBuild(ctx, buildxNodes, buildOpts, dockerClient, dockerConfigDir, buildxprinter, linter)
if err != nil {
if errors.Is(err, LintFailed) {
linter.Print(os.Stderr, in.progress)
Expand Down
15 changes: 2 additions & 13 deletions pkg/buildx/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/depot/cli/pkg/buildx/builder"
"github.com/depot/cli/pkg/ci"
"github.com/depot/cli/pkg/cmd/docker"
"github.com/depot/cli/pkg/dockerfile"
"github.com/depot/cli/pkg/helpers"
"github.com/depot/cli/pkg/load"
depotprogress "github.com/depot/cli/pkg/progress"
Expand Down Expand Up @@ -219,15 +218,6 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.No
progress.Write(printer, "[depot] build: "+depotOpts.buildURL, func() error { return err })
}

// Upload dockerfile to API.
uploader := dockerfile.NewUploader(depotOpts.buildID, depotOpts.token)
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
uploader.Run(ctx2)
wg.Done()
}()

var (
pullOpts map[string]load.PullOptions
// Only used for failures to pull images.
Expand Down Expand Up @@ -270,10 +260,9 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.No
dockerClient := dockerutil.NewClient(dockerCli)
dockerConfigDir := confutil.ConfigDir(dockerCli)

linter := NewLinter(NewLintFailureMode(depotOpts.lint, depotOpts.lintFailOn), clients, buildxNodes)
dockerfileHandlers := depotbuild.NewDockerfileHandlers(uploader, linter)
linter := NewLinter(printer, NewLintFailureMode(depotOpts.lint, depotOpts.lintFailOn), clients, buildxNodes)

resp, err := depotbuild.DepotBuildWithResultHandler(ctx, buildxNodes, opts, dockerClient, dockerConfigDir, buildxprinter, dockerfileHandlers, func(driverIndex int, gotRes *build.ResultContext) {
resp, err := depotbuild.DepotBuildWithResultHandler(ctx, buildxNodes, opts, dockerClient, dockerConfigDir, buildxprinter, linter, func(driverIndex int, gotRes *build.ResultContext) {
mu.Lock()
defer mu.Unlock()
if res == nil || driverIndex < idx {
Expand Down
16 changes: 7 additions & 9 deletions pkg/buildx/commands/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ type Linter struct {
Clients []*client.Client
BuildxNodes []builder.Node

// Our depot progress has special functionality to print and upload lint issues.
printer *depotprogress.Progress

mu sync.Mutex
issues map[string][]client.VertexWarning
}

func NewLinter(failureMode LintFailure, clients []*client.Client, nodes []builder.Node) *Linter {
func NewLinter(printer *depotprogress.Progress, failureMode LintFailure, clients []*client.Client, nodes []builder.Node) *Linter {
return &Linter{
FailureMode: failureMode,
Clients: clients,
BuildxNodes: nodes,
printer: printer,
issues: make(map[string][]client.VertexWarning),
}
}
Expand All @@ -102,12 +106,6 @@ func (l *Linter) Handle(ctx context.Context, target string, driverIndex int, doc
return nil
}

// Our depot progress has special functionality to print and upload lint issues.
printer, ok := p.(*depotprogress.Progress)
if !ok {
return nil
}

// If there is an error parsing the Dockerfile, we'll return it in failure mode;
// otherwise, we'll print it as an error message.
if dockerfile.Err != nil && l.FailureMode != LintNone {
Expand Down Expand Up @@ -144,7 +142,7 @@ func (l *Linter) Handle(ctx context.Context, target string, driverIndex int, doc
}
dgst := digest.Canonical.FromString(identity.NewID())
tm := time.Now()
printer.WriteLint(client.Vertex{Digest: dgst, Name: lintName, Started: &tm}, nil, nil)
l.printer.WriteLint(client.Vertex{Digest: dgst, Name: lintName, Started: &tm}, nil, nil)

output, err := RunHadolint(ctx, l.Clients[driverIndex], l.BuildxNodes[driverIndex].Platforms[0], dockerfile)
if err != nil {
Expand Down Expand Up @@ -278,7 +276,7 @@ func (l *Linter) Handle(ctx context.Context, target string, driverIndex int, doc
lintErr = LintFailed
}

printer.WriteLint(lintResults, statuses, logs)
l.printer.WriteLint(lintResults, statuses, logs)

l.mu.Lock()
defer l.mu.Unlock()
Expand Down
161 changes: 0 additions & 161 deletions pkg/dockerfile/upload.go

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ func (m *mockBuildServiceClient) ReportBuildHealth(context.Context, *connect.Req
return nil, nil
}

func (m *mockBuildServiceClient) ReportBuildContext(context.Context, *connect.Request[cliv1.ReportBuildContextRequest]) (*connect.Response[cliv1.ReportBuildContextResponse], error) {
return nil, nil
}

func (m *mockBuildServiceClient) ListBuilds(context.Context, *connect.Request[cliv1.ListBuildsRequest]) (*connect.Response[cliv1.ListBuildsResponse], error) {
return nil, nil
}
Loading

0 comments on commit 1f8252a

Please sign in to comment.