Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add revision option to deploy command #672

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var cliTests = []struct {
DryRun: false,
DesiredCount: ptr(int32(-1)),
SkipTaskDefinition: false,
Revision: 0,
ForceNewDeployment: false,
Wait: true,
RollbackEvents: "",
Expand All @@ -117,13 +118,14 @@ var cliTests = []struct {
},
{
args: []string{"deploy", "--dry-run", "--tasks=10",
"--skip-task-definition", "--force-new-deployment",
"--skip-task-definition", "--revision=42", "--force-new-deployment",
"--no-wait", "--latest-task-definition"},
sub: "deploy",
subOption: &ecspresso.DeployOption{
DryRun: true,
DesiredCount: ptr(int32(10)),
SkipTaskDefinition: true,
Revision: 42,
ForceNewDeployment: true,
Wait: false,
RollbackEvents: "",
Expand All @@ -140,6 +142,7 @@ var cliTests = []struct {
DryRun: false,
DesiredCount: ptr(int32(-1)),
SkipTaskDefinition: false,
Revision: 0,
ForceNewDeployment: false,
Wait: true,
RollbackEvents: "",
Expand All @@ -156,6 +159,7 @@ var cliTests = []struct {
DryRun: false,
DesiredCount: ptr(int32(-1)),
SkipTaskDefinition: false,
Revision: 0,
ForceNewDeployment: false,
Wait: true,
RollbackEvents: "",
Expand All @@ -179,6 +183,7 @@ var cliTests = []struct {
RollbackEvents: "",
UpdateService: true,
LatestTaskDefinition: false,
Revision: 0,
},
},
{
Expand Down
69 changes: 44 additions & 25 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DeployOption struct {
DryRun bool `help:"dry run" default:"false"`
DesiredCount *int32 `name:"tasks" help:"desired count of tasks" default:"-1"`
SkipTaskDefinition bool `help:"skip register a new task definition" default:"false"`
Revision int64 `help:"revision of the task definition to run when --skip-task-definition" default:"0"`
ForceNewDeployment bool `help:"force a new deployment of the service" default:"false"`
Wait bool `help:"wait for service stable" default:"true" negatable:""`
SuspendAutoScaling *bool `help:"suspend application auto-scaling attached with the ECS service"`
Expand Down Expand Up @@ -99,31 +100,9 @@ func (d *App) Deploy(ctx context.Context, opt DeployOption) error {
return err
}

var tdArn string
if opt.LatestTaskDefinition {
family := strings.Split(arnToName(*sv.TaskDefinition), ":")[0]
var err error
tdArn, err = d.findLatestTaskDefinitionArn(ctx, family)
if err != nil {
return err
}
} else if opt.SkipTaskDefinition {
tdArn = *sv.TaskDefinition
} else {
td, err := d.LoadTaskDefinition(d.config.TaskDefinitionPath)
if err != nil {
return err
}
if opt.DryRun {
d.Log("[INFO] task definition:")
d.OutputJSONForAPI(os.Stderr, td)
} else {
newTd, err := d.RegisterTaskDefinition(ctx, td)
if err != nil {
return err
}
tdArn = *newTd.TaskDefinitionArn
}
tdArn, err := d.taskDefinitionArnForDeploy(ctx, sv, opt)
if err != nil {
return err
}

var count *int32
Expand Down Expand Up @@ -537,3 +516,43 @@ func (d *App) UpdateServiceTags(ctx context.Context, sv *Service, added, updated
}
return nil
}

func (d *App) taskDefinitionArnForDeploy(ctx context.Context, sv *Service, opt DeployOption) (string, error) {
if opt.Revision > 0 {
if opt.LatestTaskDefinition {
return "", ErrConflictOptions("revision and latest-task-definition are exclusive")
}
family := strings.Split(arnToName(*sv.TaskDefinition), ":")[0]
return fmt.Sprintf("%s:%d", family, opt.Revision), nil
}

if opt.LatestTaskDefinition {
family := strings.Split(arnToName(*sv.TaskDefinition), ":")[0]
tdArn, err := d.findLatestTaskDefinitionArn(ctx, family)
if err != nil {
return "", err
}
return tdArn, nil
}

if opt.SkipTaskDefinition {
return *sv.TaskDefinition, nil
}

td, err := d.LoadTaskDefinition(d.config.TaskDefinitionPath)
if err != nil {
return "", err
}

if opt.DryRun {
d.Log("[INFO] task definition:")
d.OutputJSONForAPI(os.Stderr, td)
return "", nil
}

newTd, err := d.RegisterTaskDefinition(ctx, td)
if err != nil {
return "", err
}
return *newTd.TaskDefinitionArn, nil
}
Loading