Skip to content

Commit

Permalink
examples: demonstrate client-side Build() interface.
Browse files Browse the repository at this point in the history
This is a clone-and-hack of `examples/build-using-dockerfile` which uses the
new `Build()` client method and thus runs as a clientside-frontend.

Signed-off-by: Ian Campbell <ijc@docker.com>
  • Loading branch information
Ian Campbell committed Aug 9, 2018
1 parent f7d84e3 commit 2b47a8e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions examples/build-using-dockerfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/containerd/console"
"github.com/moby/buildkit/client"
dockerfile "github.com/moby/buildkit/frontend/dockerfile/builder"
"github.com/moby/buildkit/util/appcontext"
"github.com/moby/buildkit/util/appdefaults"
"github.com/moby/buildkit/util/progress/progressui"
Expand Down Expand Up @@ -39,6 +40,11 @@ By default, the built image is loaded to Docker.
EnvVar: "BUILDKIT_HOST",
Value: appdefaults.Address,
},
cli.BoolFlag{
Name: "clientside-frontend",
Usage: "run dockerfile frontend client side, rather than builtin to buildkitd",
EnvVar: "CLIENTSIDE_FRONTEND",
},
}
app.Flags = append([]cli.Flag{
cli.StringSliceFlag{
Expand Down Expand Up @@ -83,7 +89,12 @@ func action(clicontext *cli.Context) error {
ch := make(chan *client.SolveStatus)
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
_, err := c.Solve(ctx, nil, *solveOpt, ch)
var err error
if clicontext.Bool("clientside-frontend") {
_, err = c.Build(ctx, *solveOpt, "", dockerfile.Build, ch)
} else {
_, err = c.Solve(ctx, nil, *solveOpt, ch)
}
return err
})
eg.Go(func() error {
Expand Down Expand Up @@ -124,6 +135,10 @@ func newSolveOpt(clicontext *cli.Context, w io.WriteCloser) (*client.SolveOpt, e
"dockerfile": filepath.Dir(file),
}

frontend := "dockerfile.v0" // TODO: use gateway
if clicontext.Bool("clientside-frontend") {
frontend = ""
}
frontendAttrs := map[string]string{
"filename": filepath.Base(file),
}
Expand All @@ -145,7 +160,7 @@ func newSolveOpt(clicontext *cli.Context, w io.WriteCloser) (*client.SolveOpt, e
},
ExporterOutput: w,
LocalDirs: localDirs,
Frontend: "dockerfile.v0", // TODO: use gateway
Frontend: frontend,
FrontendAttrs: frontendAttrs,
}, nil
}
Expand Down

0 comments on commit 2b47a8e

Please sign in to comment.