Skip to content

Commit 3d96dcc

Browse files
author
Simran Bajaj
committed
Added shell script for Fargate example
1 parent e38f7d7 commit 3d96dcc

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
# Usage:
3+
# ./examples/ecs-firelens/bin/publish-fargate.sh \
4+
# <account-id> \
5+
# <region> \
6+
# <image-name> \
7+
# <config-image-name> \
8+
# <ecs-cluster-name> \
9+
# <ecs-task-family> \
10+
# <ecs-service-name>
11+
12+
rootdir=$(git rev-parse --show-toplevel)
13+
14+
ACCOUNT_ID=$1
15+
REGION=$2
16+
IMAGE_NAME=$3 # emf-ecs-firelens
17+
FLUENT_BIT_CONFIG=$4
18+
CLUSTER_NAME=$5 # emf-example
19+
ECS_TASK_FAMILY=$6 # aws-emf-ecs-app-example
20+
ECS_SERVICE_NAME=$7 # aws-emf-ecs-firelens-ec2
21+
22+
LIB_PATH=$rootdir
23+
EXAMPLE_DIR=$rootdir/examples/ecs-firelens
24+
ECR_REMOTE=$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$IMAGE_NAME
25+
26+
function check_exit() {
27+
last_exit_code=$?
28+
if [ $last_exit_code -ne 0 ];
29+
then
30+
echo "Last command failed with exit code: $last_exit_code."
31+
echo "Exiting."
32+
exit $last_exit_code;
33+
fi
34+
}
35+
36+
echo 'BUILDING THE LOCAL PROJECT'
37+
pushd $rootdir
38+
./gradlew :examples:ecs-firelens:build
39+
check_exit
40+
popd
41+
42+
pushd $EXAMPLE_DIR
43+
pwd
44+
45+
46+
echo 'UPDATING CONTAINER DEFINITIONS'
47+
sed "s/<account-id>/$ACCOUNT_ID/g" $EXAMPLE_DIR/container-definitions-fargate.template.json \
48+
| sed "s/<region>/$REGION/g" \
49+
| sed "s/<Firelens-custom-conf-image>/$FLUENT_BIT_CONFIG/g" \
50+
| sed "s/<image-name>/$IMAGE_NAME/g" \
51+
> $EXAMPLE_DIR/container-definitions.json
52+
check_exit
53+
54+
echo 'BUILDING THE EXAMPLE DOCKER IMAGE'
55+
`aws ecr get-login --no-include-email --region $REGION`
56+
docker build . -t $IMAGE_NAME:latest
57+
check_exit
58+
59+
echo 'PUSHING THE EXAMPLE DOCKER IMAGE TO ECR'
60+
imageid=$(docker images -q $IMAGE_NAME:latest)
61+
docker tag $imageid $ECR_REMOTE
62+
docker push $ECR_REMOTE
63+
check_exit
64+
65+
echo 'UPDATING THE ECS SERVICE'
66+
aws ecs update-service \
67+
--region $REGION \
68+
--cluster $CLUSTER_NAME \
69+
--service $ECS_SERVICE_NAME \
70+
--force-new-deployment \
71+
--task-definition $(aws ecs register-task-definition \
72+
--network-mode awsvpc \
73+
--task-role arn:aws:iam::$ACCOUNT_ID:role/ecsTaskExecutionRole \
74+
--execution-role-arn "arn:aws:iam::$ACCOUNT_ID:role/ecsTaskExecutionRole" \
75+
--region $REGION \
76+
--memory 512 \
77+
--cpu 256 \
78+
--family $ECS_TASK_FAMILY \
79+
--container-definitions "$(cat container-definitions.json)" \
80+
| jq --raw-output '.taskDefinition.taskDefinitionArn' | awk -F '/' '{ print $2 }')
81+
82+
popd

0 commit comments

Comments
 (0)