amazon-ecs-deploy-task-definition
amazon-ecs-deploy-task-definition copied to clipboard
Mark previous task definition(s) as inactive
When a new task definition is created it might be a good idea to allow marking the last one (or the one before the last one to allow rollback) as inactive.
Has anyone worked around this?
@tractorcow I add another step:
- name: Download task definition
id: download-task
run: |
aws ecs describe-task-definition \
--task-definition ${{ env.task-definition }} \
--query taskDefinition > task-definition.json
echo "::set-output name=revision::$(cat task-definition.json | jq .revision)"
- ...update the task definition...
- ...deploy the task definition with `aws-actions/amazon-ecs-deploy-task-definition`
- name: De-register previous revision
run: |
aws ecs deregister-task-definition \
--task-definition ${{ env.task-definition }}:${{ steps.download-task.outputs.revision }}
You may want delete not the latest revision but say latest - 2 just for the faster rollbacks. In this case the line that extracts the revision number can be replaced by this one
echo "::set-output name=revision::$(($(cat task-definition.json | jq .revision) - 2))"
P.S. I have not tested it how it will behave with the negative number when you just start. But since this is the last step in the deployment, error probably can be ignored for the first two runs.
if deregistering after a new task definition was pushed, then you would want to get rid of latest-1 revision.
here is a sample of my pipeline that works and tested
- name: Download task definition
id: download-task
run: |
aws ecs describe-task-definition \
--task-definition ${{ env.SERVICE_NAME }} \
--query taskDefinition > task-definition.json
echo "::set-output name=revision::$(($(cat task-definition.json | jq .revision) - 1))"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.SERVICE_NAME }}
image: ghcr.io/${{ env.REPO }}:${{ inputs.imageTag }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.SERVICE_NAME }}
cluster: ecs-${{ env.ENV }}
wait-for-service-stability: ${{ inputs.waitForServiceStability }}
- name: De-register (latest-1) revision
if: ${{ steps.download-task.outputs.revision > 0 }}
run: |
aws ecs deregister-task-definition \
--task-definition ${{ env.SERVICE_NAME }}:${{ steps.download-task.outputs.revision }}
I wonder if this will be included in the action or not. I just found out that the old task definitions are not de-registered and now I have 150+ versions of task definition as active.
I guess every old one should be deleted on success.
Active task definitions cost money on AWS?
I don't think so, it's the running task themselves that should only cost anything.
I don't think so, it's the running task themselves that should only cost anything.
I use tasks in order to update my fargate service Every update equals new ECR + new taskDef which pointer to the new image. Then, the task of my fargate service changed to the new one.
Therefore, if I understand correctly, the old once are meaningless