-
Notifications
You must be signed in to change notification settings - Fork 13
70 lines (60 loc) · 2.34 KB
/
delete-ecs-task-defs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Delete ECS task definitions
on:
workflow_dispatch:
schedule:
- cron: "0 5 * * 0" # 5am Sunday UTC
env:
AWS_REGION: ca-central-1
permissions:
id-token: write
contents: read
jobs:
delete-ecs-task-definitions:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- account: "687401027353"
- account: "957818836222"
steps:
- name: Checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: arn:aws:iam::${{ matrix.account }}:role/platform-forms-client-apply
role-session-name: ECSTaskDefDelete
aws-region: ${{ env.AWS_REGION }}
# Retrieves all ACTIVE task definitions except for the 5 most recent
- name: Get ACTIVE ECS task definitions
env:
TASK_NAME: form-viewer
TASK_STATUS: ACTIVE
TASKS_TO_KEEP: 6 # 1 greater than number to keep
run: |
aws ecs list-task-definitions \
--sort ASC \
--status ${{ env.TASK_STATUS }} \
--region ${{ env.AWS_REGION }} \
--no-cli-pager \
| jq -r '(.taskDefinitionArns | map(select(contains("${{ env.TASK_NAME }}")))[:length-${{ env.TASKS_TO_KEEP }}])[]' > task-def-active-arns.txt
- name: Set ECS tasks to INACTIVE
run: |
./bin/delete-ecs-task-defs.sh DEREGISTER task-def-active-arns.txt
# Retrieves all INACTIVE task definitions except for the 100 most recent
- name: Get INACTIVE ECS task definitions
env:
TASK_NAME: form-viewer
TASK_STATUS: INACTIVE
TASKS_TO_KEEP: 101 # 1 greater than number to keep
run: |
aws ecs list-task-definitions \
--sort ASC \
--status ${{ env.TASK_STATUS }} \
--region ${{ env.AWS_REGION }} \
--no-cli-pager \
| jq -r '(.taskDefinitionArns | map(select(contains("${{ env.TASK_NAME }}")))[:length-${{ env.TASKS_TO_KEEP }}])[]' > task-def-inactive-arns.txt
- name: Delete INACTIVE ECS task definitions
run: |
./bin/delete-ecs-task-defs.sh DELETE task-def-inactive-arns.txt