Skip to content

Commit

Permalink
Ensure all attributes are registered, especially execution and task r…
Browse files Browse the repository at this point in the history
…oles
  • Loading branch information
qbart committed Dec 29, 2022
1 parent fd1c6d7 commit 7b66d30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions awscmd/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ type OuputEcsDeploy struct {
MonitoredDeploymentID string
}

func EcsDeploy(ctx context.Context, input *InputEcsDeploy) (*OuputEcsDeploy, error) {
func EcsDeploy(ctx context.Context, input *InputEcsDeploy, w io.Writer) (*OuputEcsDeploy, error) {
sess, err := NewSession(input.Region)
if err != nil {
return nil, err
}
svc := ecs.New(sess)

// 1. fetch running task
fmt.Fprintf(w, "Fetching service definition\n")
serviceOut, err := svc.DescribeServicesWithContext(ctx, &ecs.DescribeServicesInput{
Cluster: aws.String(input.Cluster),
Services: []*string{aws.String(input.Service)},
Expand All @@ -55,6 +56,7 @@ func EcsDeploy(ctx context.Context, input *InputEcsDeploy) (*OuputEcsDeploy, err
}

// 2. build new task definition
fmt.Fprintf(w, "Fetching task definition\n")
taskDefinitionOut, err := svc.DescribeTaskDefinitionWithContext(ctx, &ecs.DescribeTaskDefinitionInput{
TaskDefinition: taskDefinition,
})
Expand All @@ -66,16 +68,32 @@ func EcsDeploy(ctx context.Context, input *InputEcsDeploy) (*OuputEcsDeploy, err
}

// 3. register new task revision
fmt.Fprintf(w, "Registering new task revision with new docker image\n")
registerOut, err := svc.RegisterTaskDefinitionWithContext(ctx, &ecs.RegisterTaskDefinitionInput{
ContainerDefinitions: containerDefinitions,
Family: taskDefinitionOut.TaskDefinition.Family,
ContainerDefinitions: containerDefinitions,
Cpu: taskDefinitionOut.TaskDefinition.Cpu,
EphemeralStorage: taskDefinitionOut.TaskDefinition.EphemeralStorage,
ExecutionRoleArn: taskDefinitionOut.TaskDefinition.ExecutionRoleArn,
Family: taskDefinitionOut.TaskDefinition.Family,
InferenceAccelerators: taskDefinitionOut.TaskDefinition.InferenceAccelerators,
IpcMode: taskDefinitionOut.TaskDefinition.IpcMode,
Memory: taskDefinitionOut.TaskDefinition.Memory,
NetworkMode: taskDefinitionOut.TaskDefinition.NetworkMode,
PidMode: taskDefinitionOut.TaskDefinition.PidMode,
PlacementConstraints: taskDefinitionOut.TaskDefinition.PlacementConstraints,
ProxyConfiguration: taskDefinitionOut.TaskDefinition.ProxyConfiguration,
RequiresCompatibilities: taskDefinitionOut.TaskDefinition.RequiresCompatibilities,
RuntimePlatform: taskDefinitionOut.TaskDefinition.RuntimePlatform,
TaskRoleArn: taskDefinitionOut.TaskDefinition.TaskRoleArn,
Volumes: taskDefinitionOut.TaskDefinition.Volumes,
})
if err != nil {
return nil, fmt.Errorf("Failed to register new task revision: %w", err)
}
arn := registerOut.TaskDefinition.TaskDefinitionArn

// 4. update ecs service with new task arn
fmt.Fprintf(w, "Updating service\n")
updateOut, err := svc.UpdateServiceWithContext(ctx, &ecs.UpdateServiceInput{
Cluster: aws.String(input.Cluster),
Service: aws.String(input.Service),
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func main() {
Service: c.String("service"),
DockerImage: c.String("docker-image"),
}
out, err := awscmd.EcsDeploy(context.TODO(), input)
out, err := awscmd.EcsDeploy(context.TODO(), input, c.App.Writer)
if out != nil {
fmt.Fprintf(
c.App.Writer,
Expand Down

0 comments on commit 7b66d30

Please sign in to comment.