aws / containers-roadmap

This is the public roadmap for AWS container services (ECS, ECR, Fargate, and EKS).
https://aws.amazon.com/about-aws/whats-new/containers/
Other
5.21k stars 317 forks source link

[ECS] [request]: Add ability to update task definition #2058

Open tim-finnigan opened 1 year ago

tim-finnigan commented 1 year ago

Please see https://github.com/aws/aws-sdk/issues/406 for background and discussion.


Community Note

Tell us about your request What do you want us to build?

Which service(s) is this request for? ECS [edited]

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard? What outcome are you trying to achieve, ultimately, and why is it hard/impossible to do right now? What is the impact of not having this problem solved? The more details you can provide, the better we'll be able to understand and solve the problem.

Are you currently working around this issue? How are you currently solving this problem?

Additional context Anything else we should know?

Attachments If you think you might have additional information that you'd like to include via an attachment, please do - we'll take a look. (Remember to remove any personally-identifiable information.)

jlbutler commented 1 year ago

I've tagged this ECS and edited the issue for service to improve tracking.

ezhukov commented 11 months ago

Please prioritize this, because now I have to do the following in my CI yml just to update an image:

- >
  aws ecs describe-services
  --cluster $AWS_ECS_CLUSTER
  --services $AWS_ECS_SERVICE
  --query 'services[].taskDefinition[]'
  --output text |
  xargs aws ecs describe-task-definition --task-definition |
  jq --arg IMAGE $AWS_ECR/my-project:new-img-tag '.taskDefinition
  | .containerDefinitions[0].image = $IMAGE
  | del(.taskDefinitionArn)
  | del(.revision)
  | del(.status)
  | del(.requiresAttributes)
  | del(.compatibilities)
  | del(.registeredAt)
  | del(.registeredBy)' |
  xargs -0 aws ecs register-task-definition --cli-input-json |
  jq '.taskDefinition.taskDefinitionArn' |
  xargs aws ecs update-service
  --cluster $AWS_ECS_CLUSTER
  --service $AWS_ECS_SERVICE
  --task-definition
ashikMostofaTonmoy commented 4 months ago

I have slightly modified this that doesn't need 'jq' but can use custom tag

#!/bin/sh

# Define the full image name with tag
FULL_IMAGE="registry/project:mycustomtag"

# Retrieve details of the existing ECS task definition
TASK_DEFINITION=$(aws ecs describe-task-definition \
--task-definition "$TASK_DEFINATION_NAME" \
--region "$REGISTRY_REGION" \
--query '{  containerDefinitions: taskDefinition.containerDefinitions,
            family: taskDefinition.family,
            executionRoleArn: taskDefinition.executionRoleArn,
            volumes: taskDefinition.volumes,
            placementConstraints: taskDefinition.placementConstraints,
            cpu: taskDefinition.cpu,
            memory: taskDefinition.memory
            }')

# Modify the task definition to update the image name with the provided full image
NEW_TASK_DEFINITION=$(echo "$TASK_DEFINITION" | sed "s|\"image\": \".*\"|\"image\": \"$FULL_IMAGE\"|")
echo $NEW_TASK_DEFINITION

# Register the modified task definition
NEW_TASK_INFO=$(aws ecs register-task-definition \
      --region "$REGISTRY_REGION" \
      --cli-input-json "$NEW_TASK_DEFINITION")
echo $NEW_TASK_INFO

# Extract the revision number of the newly registered task definition
REVISION=$(echo "$NEW_TASK_INFO" | grep -o '"revision":[^,]*' | cut -d':' -f2)

# Remove leading and trailing whitespaces from the revision number
NEW_REVISION=$(echo $REVISION | tr -d ' ')
echo $NEW_REVISION

# Update ecs service
UPDATE_SERVICE=$(aws ecs update-service \
--region $REGISTRY_REGION \
--cluster ${CLUSTER_NAME} \
--service ${SERVICE_NAME} \
--task-definition ${TASK_DEFINATION_NAME}:${NEW_REVISION})