Skip to content

Commit

Permalink
Merge pull request #2 from AdRoll/add-no-wait-feature
Browse files Browse the repository at this point in the history
Add a flag not to wait until the service is ready
  • Loading branch information
odarbelaeze authored Mar 10, 2022
2 parents 657eee3 + e24a0a0 commit bb616fb
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 61 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ USAGE:
ecs-deploy [options] <cluster> <service>
VERSION:
1.0.0
1.1.0
GLOBAL OPTIONS:
--updates FILE, -u FILE Use an input FILE to describe service updates (default: stdin)
--timeout DURATION, -t DURATION Wait this DURATION for the service to be correctly updated (default: 5m0s)
--no-color, -n Disable colored output (default: false)
--no-wait, -w Disable waiting for updates to be completed. (default: false)
--dry, -d Don't deploy just show what would change in the remote service (default: false)
--help, -h show help (default: false)
--version, -v print the version (default: false)
```
Expand Down
7 changes: 6 additions & 1 deletion action/ecs-deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ECSDeployTaskConfig interface {
}

// ECSDeploy deploy an ecs service
func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, timeout time.Duration, config ECSDeployTaskConfig, dryRun bool) error {
func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, timeout time.Duration, config ECSDeployTaskConfig, dryRun bool, noWait bool) error {
if len(clusterName) == 0 {
return errors.New("cluster was not provided")
}
Expand Down Expand Up @@ -92,6 +92,11 @@ func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, t
return err
}

if noWait {
log.Println("Not waiting for your service to reflect changes, check the console please :D")
return nil
}

log.Println("Waiting for the service to reflect the new changes...")
if originalErr := client.WaitUntilGood(newService, &timeout); originalErr != nil {
log.Println(color.RedString("There was an error updating the service :", originalErr.Error()))
Expand Down
60 changes: 53 additions & 7 deletions action/ecs-deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func Test_ECSDeploy_NoArgs(t *testing.T) {
err := ECSDeploy("", "", nil, time.Nanosecond, nil, false)
err := ECSDeploy("", "", nil, time.Nanosecond, nil, false, false)
assert.Error(t, err)
}

Expand Down Expand Up @@ -61,7 +61,53 @@ func Test_ECSDeploy_TruePath(t *testing.T) {

//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false)
err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false, false)
require.NoError(t, err)
}

func Test_ECSDeploy_NoWait(t *testing.T) {
const clusterName = "clusterA"
const serviceName = "serviceA"

family := "test-family"
serviceTaskArn := "test-family:0"
taskArn := "test-family:1"
timeout := time.Nanosecond
service := &ecssdk.Service{
TaskDefinition: &serviceTaskArn,
}
oldTask := &ecssdk.TaskDefinition{}
taskCopy := &ecssdk.RegisterTaskDefinitionInput{}
newTask := &ecssdk.RegisterTaskDefinitionInput{
ContainerDefinitions: make([]*ecssdk.ContainerDefinition, 0),
Family: &family,
}
newTaskDefinition := &ecssdk.TaskDefinition{
TaskDefinitionArn: &taskArn,
}
newService := &ecssdk.Service{}
diff := &ecs.TaskConfigDiff{}
oldCpu := "1"
newCpu := "10"
diff.ChangeCPU(&oldCpu, &newCpu)

//#region mock
c := gomock.NewController(t)

client := mock.NewMockECSDeployClient(c)
client.EXPECT().GetService(clusterName, serviceName).Return(service, nil).Times(1)
client.EXPECT().LooksGood(service).Return(true, nil).Times(1)
client.EXPECT().CopyTaskDefinition(service).Return(taskCopy, oldTask, nil).Times(1)
client.EXPECT().RegisterTaskDefinition(newTask).Return(newTaskDefinition, nil).Times(1)
client.EXPECT().UpdateTaskDefinition(service, newTaskDefinition).Return(newService, nil).Times(1)
client.EXPECT().WaitUntilGood(newService, &timeout).Return(nil).Times(0)

cfg := mock.NewMockECSDeployTaskConfig(c)
cfg.EXPECT().ApplyTo(taskCopy).Return(newTask, diff).Times(1)

//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false, true)
require.NoError(t, err)
}

Expand Down Expand Up @@ -99,7 +145,7 @@ func Test_ECSDeploy_DryRunPath(t *testing.T) {

//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, true)
err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, true, false)
require.NoError(t, err)
}

Expand Down Expand Up @@ -136,7 +182,7 @@ func Test_ECSDeploy_RollbackPath(t *testing.T) {

//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false)
err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false, false)
require.NoError(t, err)
}

Expand All @@ -157,7 +203,7 @@ func Test_ECSDeploy_GetServiceError(t *testing.T) {
cfg := mock.NewMockECSDeployTaskConfig(c)
//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false)
err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false, false)
require.Equal(t, expectedError, err)
}

Expand All @@ -179,7 +225,7 @@ func Test_ECSDeploy_LooksGoodError(t *testing.T) {
cfg := mock.NewMockECSDeployTaskConfig(c)
//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false)
err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false, false)
require.Equal(t, expectedError, err)
}

Expand All @@ -202,6 +248,6 @@ func Test_ECSDeploy_CopyTaskDefinitionError(t *testing.T) {
cfg := mock.NewMockECSDeployTaskConfig(c)
//#endregion

err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false)
err := ECSDeploy(clusterName, serviceName, client, timeout, cfg, false, false)
require.Equal(t, expectedError, err)
}
101 changes: 51 additions & 50 deletions action/mock/ecs-deploy_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
app := &cli.App{
Name: "ecs-ship",
Usage: "Deploy your aws ecs services.",
Version: "1.0.0",
Version: "1.1.0",
UseShortOptionHandling: true,
ArgsUsage: "<cluster> <service>",
UsageText: "ecs-deploy [options] <cluster> <service>",
Expand All @@ -45,6 +45,12 @@ func main() {
Usage: "Disable colored output",
Required: false,
},
&cli.BoolFlag{
Name: "no-wait",
Aliases: []string{"w"},
Usage: "Disable waiting for updates to be completed.",
Required: false,
},
&cli.BoolFlag{
Name: "dry",
Aliases: []string{"d"},
Expand Down Expand Up @@ -78,7 +84,7 @@ func main() {
}

client := ecs.BuildDefaultClient()
return action.ECSDeploy(cluster, service, client, ctx.Duration("timeout"), &cfg, ctx.Bool("dry"))
return action.ECSDeploy(cluster, service, client, ctx.Duration("timeout"), &cfg, ctx.Bool("dry"), ctx.Bool("no-wait"))
},
}

Expand Down

0 comments on commit bb616fb

Please sign in to comment.