Skip to content

Commit

Permalink
examples: demonstrate client-side Build() interface.
Browse files Browse the repository at this point in the history
Adds an option/envvar to `examples/build-using-dockerfile` which uses a client
side instance of the dockerfile frontend.

Signed-off-by: Ian Campbell <ijc@docker.com>
  • Loading branch information
Ian Campbell committed Aug 14, 2018
1 parent 22f632f commit 5383270
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: "BUILDKIT_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 5383270

Please sign in to comment.