-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildspec-codedeploy.yml
30 lines (27 loc) · 1.57 KB
/
buildspec-codedeploy.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
version: 0.2
env:
variables:
IMAGE_TAG: ""
phases:
install:
commands:
- aws --version
- echo Installing dependencies...
- yum install -y jq
pre_build:
commands:
- aws ecs describe-task-definition --task-definition demo-tmcdapne2 --query 'taskDefinition' --output json > $CODEBUILD_SRC_DIR/task-definition.json
- jq 'del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)' $CODEBUILD_SRC_DIR/task-definition.json > $CODEBUILD_SRC_DIR/cleaned-task-definition.json
- jq '.containerDefinitions[].image |= gsub(":[^:]+$"; ":${IMAGE_TAG}")' $CODEBUILD_SRC_DIR/cleaned-task-definition.json
- echo "Register new task definition"
- aws ecs register-task-definition --cli-input-json file://$CODEBUILD_SRC_DIR/cleaned-task-definition.json > /dev/null
build:
commands:
- TASK_DEFINITION_ARN=$(aws ecs describe-task-definition --task-definition demo-tmcdapne2 --query 'taskDefinition.taskDefinitionArn' --output text)
- echo $TASK_DEFINITION_ARN
- sed -i "s|ARN|${TASK_DEFINITION_ARN}|g" $CODEBUILD_SRC_DIR/appspec.json
- json_string=$(jq -c . $CODEBUILD_SRC_DIR/appspec.json| jq -Rr '@json' | sed 's/"/\\"/g')
- echo ${json_string}
- sed -i "s|DEPLOYMENT_SPEC|${json_string}|g" $CODEBUILD_SRC_DIR/codedeploy-template.json
- DEPLOYMENT_ID=$(aws deploy create-deployment --cli-input-json file://$CODEBUILD_SRC_DIR/codedeploy-template.json --query "deploymentId" --output text)
- echo "Create new deployment by codedeploy - ${DEPLOYMENT_ID}"