Skip to content

Commit

Permalink
add no-cache and build-target flags to build command, hidden for now
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed May 4, 2021
1 parent 13cf2a2 commit 27bbfad
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type StringFlagOpts struct {
Description string
Default string
EnvName string
Hidden bool
}

// BoolFlagOpts - options for boolean flags
Expand All @@ -68,7 +69,9 @@ func (c *Command) AddStringFlag(options StringFlagOpts) {
fullName := namespace(c.Command) + "." + options.Name
c.Flags().StringP(options.Name, options.Shorthand, options.Default, options.Description)

err := viper.BindPFlag(fullName, c.Flags().Lookup(options.Name))
flag := c.Flags().Lookup(options.Name)
flag.Hidden = options.Hidden
err := viper.BindPFlag(fullName, flag)
checkErr(err)

if options.EnvName != "" {
Expand Down
12 changes: 12 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func newDeployCommand(client *client.Client) *Command {
Name: "image-label",
Description: "Image label to use when tagging and pushing to the fly registry. Defaults to \"deployment-{timestamp}\".",
})
cmd.AddStringFlag(StringFlagOpts{
Name: "build-target",
Description: "Set the target build stage to build if the Dockerfile has more than one stage",
Hidden: true,
})
cmd.AddBoolFlag(BoolFlagOpts{
Name: "no-cache",
Description: "Do not use the cache when building the image",
Hidden: true,
})

cmd.Command.Args = cobra.MaximumNArgs(1)

Expand Down Expand Up @@ -152,6 +162,8 @@ func runDeploy(cmdCtx *cmdctx.CmdContext) error {
AppConfig: cmdCtx.AppConfig,
Publish: !cmdCtx.Config.GetBool("build-only"),
ImageLabel: cmdCtx.Config.GetString("image-label"),
Target: cmdCtx.Config.GetString("build-target"),
NoCache: cmdCtx.Config.GetBool("no-cache"),
}
if dockerfilePath := cmdCtx.Config.GetString("dockerfile"); dockerfilePath != "" {
dockerfilePath, err := filepath.Abs(dockerfilePath)
Expand Down
9 changes: 6 additions & 3 deletions internal/build/imgsrc/dockerfile_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ func normalizeBuildArgsForDocker(appConfig *flyctl.AppConfig, extra map[string]s

func runClassicBuild(ctx context.Context, streams *iostreams.IOStreams, docker *dockerclient.Client, r io.ReadCloser, opts ImageOptions, dockerfilePath string, buildArgs map[string]*string) (imageID string, err error) {
options := types.ImageBuildOptions{
Tags: []string{opts.Tag},
BuildArgs: buildArgs,
// NoCache: true,
Tags: []string{opts.Tag},
BuildArgs: buildArgs,
AuthConfigs: authConfigs(),
Platform: "linux/amd64",
Dockerfile: dockerfilePath,
Target: opts.Target,
NoCache: opts.NoCache,
}

resp, err := docker.ImageBuild(ctx, r, options)
Expand Down Expand Up @@ -246,6 +247,8 @@ func runBuildKitBuild(ctx context.Context, streams *iostreams.IOStreams, docker
BuildID: buildID,
Platform: "linux/amd64",
Dockerfile: dockerfilePath,
Target: opts.Target,
NoCache: opts.NoCache,
}

return func() error {
Expand Down
2 changes: 2 additions & 0 deletions internal/build/imgsrc/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type ImageOptions struct {
ImageLabel string
Publish bool
Tag string
Target string
NoCache bool
}

type RefOptions struct {
Expand Down

0 comments on commit 27bbfad

Please sign in to comment.