Skip to content

Commit

Permalink
Add a --local-only flag to the flyctl deploy command
Browse files Browse the repository at this point in the history
Fixes #237
  • Loading branch information
codepope committed Jul 15, 2020
1 parent 533d52e commit 0b60360
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
21 changes: 17 additions & 4 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func newDeployCommand() *Command {
Name: "remote-only",
Description: "Perform builds remotely without using the local docker daemon",
})
cmd.AddBoolFlag(BoolFlagOpts{
Name: "local-only",
Description: "Only perform builds locally using the local docker daemon",
})
cmd.AddStringFlag(StringFlagOpts{
Name: "strategy",
Description: "The strategy for replacing running instances. Options are canary, rolling, or immediate. Default is canary",
Expand Down Expand Up @@ -166,8 +170,7 @@ func runDeploy(commandContext *cmdctx.CmdContext) error {
//fmt.Printf("Deploy source directory '%s'\n", cc.WorkingDir)
commandContext.Statusf("flyctl", cmdctx.SINFO, "Deploy source directory '%s'\n", commandContext.WorkingDir)

if op.DockerAvailable() {
//fmt.Println("Docker daemon available, performing local build...")
if op.DockerAvailable() && !op.RemoteOnly() {
commandContext.Status("flyctl", cmdctx.SDETAIL, "Docker daemon available, performing local build...")

if commandContext.AppConfig.HasBuilder() {
Expand Down Expand Up @@ -207,8 +210,18 @@ func runDeploy(commandContext *cmdctx.CmdContext) error {
}

} else {
//fmt.Println("Docker daemon unavailable, performing remote build...")
commandContext.Status("flyctl", cmdctx.SINFO, "Docker daemon unavailable, performing remote build...")
if !op.DockerAvailable() {
if op.LocalOnly() {
return fmt.Errorf("Docker daemon unavailable: Local-only set so cannot use to remote build")
}
commandContext.Status("flyctl", cmdctx.SINFO, "Docker daemon unavailable: Performing remote build...")
} else {
if op.RemoteOnly() {
commandContext.Status("flyctl", cmdctx.SINFO, "Remote-only set: performing remote build...")
} else {
commandContext.Status("flyctl", cmdctx.SINFO, "Docker daemon available: Still performing remote build...")
}
}

build, err := op.StartRemoteBuild(commandContext.WorkingDir, commandContext.AppConfig, dockerfilePath, buildArgs)
if err != nil {
Expand Down
25 changes: 19 additions & 6 deletions docker/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type DeployOperation struct {
appName string
appConfig *flyctl.AppConfig
imageTag string
remoteOnly bool
localOnly bool
}

func NewDeployOperation(ctx context.Context, cmdContext *cmdctx.CmdContext) (*DeployOperation, error) {
Expand All @@ -37,6 +39,7 @@ func NewDeployOperation(ctx context.Context, cmdContext *cmdctx.CmdContext) (*De

//squash:=cmdContext.Config.GetBool("squash")
remoteOnly := cmdContext.Config.GetBool("remote-only")
localOnly := cmdContext.Config.GetBool("local-only")

imageLabel, _ := cmdContext.Config.GetString("image-label")

Expand All @@ -48,9 +51,15 @@ func NewDeployOperation(ctx context.Context, cmdContext *cmdctx.CmdContext) (*De
appName: cmdContext.AppName,
appConfig: cmdContext.AppConfig,
imageTag: newDeploymentTag(cmdContext.AppName, imageLabel),
localOnly: localOnly,
remoteOnly: remoteOnly,
}

op.dockerAvailable = !remoteOnly && op.dockerClient.Check(ctx) == nil
op.dockerAvailable = op.dockerClient.Check(ctx) == nil

if localOnly && remoteOnly {
return nil, fmt.Errorf("Both --local-only and --remote-only are set - select only one")
}

return op, nil
}
Expand All @@ -66,6 +75,14 @@ func (op *DeployOperation) DockerAvailable() bool {
return op.dockerAvailable
}

func (op *DeployOperation) LocalOnly() bool {
return op.localOnly
}

func (op *DeployOperation) RemoteOnly() bool {
return op.remoteOnly
}

type DeploymentStrategy string

const (
Expand Down Expand Up @@ -93,8 +110,6 @@ func (op *DeployOperation) ValidateConfig() (*api.AppConfig, error) {
op.appConfig = flyctl.NewAppConfig()
}

//printHeader("Validating app configuration")

parsedConfig, err := op.apiClient.ParseConfig(op.appName, op.appConfig.Definition)
if err != nil {
return parsedConfig, err
Expand All @@ -106,15 +121,13 @@ func (op *DeployOperation) ValidateConfig() (*api.AppConfig, error) {

op.appConfig.Definition = parsedConfig.Definition

//fmt.Println("-->", "done")

return parsedConfig, nil
}

func (op *DeployOperation) ResolveImage(ctx context.Context, commandContext *cmdctx.CmdContext, imageRef string) (*Image, error) {
commandContext.Status("flyctl", "Resolving image")

if op.DockerAvailable() {
if op.DockerAvailable() && !op.RemoteOnly() {
imgSummary, err := op.dockerClient.findImage(ctx, imageRef)
if err != nil {
return nil, err
Expand Down

0 comments on commit 0b60360

Please sign in to comment.