-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_task_definition.sh
More file actions
47 lines (38 loc) · 1.49 KB
/
update_task_definition.sh
File metadata and controls
47 lines (38 loc) · 1.49 KB
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
#!/bin/bash
set -e
ls
pwd
# Install AWS CLI and jq
sudo apt-get update
sudo apt-get install -y awscli jq
# Get the current branch or tag
ACCOUNT_ID=$1
BRANCH_OR_TAG=$(git rev-parse --abbrev-ref HEAD)
TASK_DEFINITION_ARN="arn:aws:ecs:us-east-1:${ACCOUNT_ID}:task-definition/auto-normalize-iz6m29xlzo8a770dbc180028ba90d9b2"
NEW_IMAGE="${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/idscience/ecs-auto-normalize:$BRANCH_OR_TAG"
echo "Branch or Tag: $BRANCH_OR_TAG"
echo "New Image: $NEW_IMAGE"
# Retrieve the existing task definition
if ! aws ecs describe-task-definition \
--task-definition "$TASK_DEFINITION_ARN" \
--query 'taskDefinition' \
--output json > task-def.json; then
echo "Failed to retrieve task definition" >&2
exit 1
fi
# Modify the image URL in the container definition
if ! jq --arg new_image "$NEW_IMAGE" '
.containerDefinitions[0].image = $new_image |
del(.revision, .status, .taskDefinitionArn, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)
' task-def.json > updated-task-def.json; then
echo "Failed to modify task definition" >&2
exit 1
fi
# Register the new task definition
if ! aws ecs register-task-definition --cli-input-json file://updated-task-def.json; then
echo "Failed to register new task definition" >&2
exit 1
fi
# Retrieve branch or tag name and update Parameter Store
BRANCH_OR_TAG=$(git rev-parse --abbrev-ref HEAD)
aws ssm put-parameter --name "container_tag-data-normalization" --value "$BRANCH_OR_TAG" --type String --overwrite