aws-actions/amazon-ecs-render-task-definition

Way to simply update the container name and tag in task definition

alex-benoit opened this issue · 6 comments

CircleCi orb has a way to only update the container name and/or tag without requiring the whole json task definition
https://circleci.com/orbs/registry/orb/circleci/aws-ecs (see container-image-name-updates)

This isn't supported with this action right?

Correct, this action assumes you have the task definition json checked into your git repository

@clareliguori thanks for the quick response

What would be the recommended approach for ENV variables that are defined in the task definition then?

As in, use one task definition file, but different services need different environment variable values?

I have a similar question about injecting env variables and/or secrets. For example, what is the recommended approach to inject a param from ssm without hardcoding the stage:

"secrets": [{
        "name": "environment_variable_name",
        "valueFrom": "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${DeploymentStage}/infra/param/test"
      }]

A tool like envsubst can be used to inject env variable values into a task def file. It looks like there is a GitHub Action that wraps envsubst, though I haven't used it personally: https://github.com/marketplace/actions/envsubst-action

I'm also happy to take contributions to add similar functionality to this action!

ended up doing this instead of using the action to avoid having to use a repeated task definition json in the repo (it pulls the latest one from ECS)

LATEST_TASK_DEFINITION=`aws ecs describe-task-definition --task-definition XYZ` NEW_TASK_DEFINTIION=`echo $LATEST_TASK_DEFINITION | jq '.taskDefinition | .containerDefinitions[0].image = "${{ secrets.ECR_REPOSITORY_URL }}:${{ github.sha }}" | del(.["taskDefinitionArn", "revision", "status", "requiresAttributes", "compatibilities"])'` TASK_DEFINITION_REVISION=`aws ecs register-task-definition --cli-input-json "$NEW_TASK_DEFINTIION" | jq '.taskDefinition.revision'` aws ecs update-service --cluster XYZ --service XYZ --task-definition XYZ:${TASK_DEFINITION_REVISION}