-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildspec-ecs.yml
44 lines (43 loc) · 2.02 KB
/
buildspec-ecs.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
version: 0.2
env:
parameter-store:
DOCKERHUB_USER: "AW_DOCKERHUB_USERNAME"
DOCKERHUB_PW: "AW_DOCKERHUB_PW"
ECR_URI_PREFIX: "Fran_Frontend_ECR_URI"
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
#- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin ${ECR_URI_PREFIX}
- IMAGE_REPO_NAME=${ECR_REPO_NAME} #defined in Build environmnet
- REPOSITORY_URI=${ECR_URI_PREFIX} # $IMAGE_REPO_NAME defined in Build environment
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- pwd
- ls -alh
- echo ${IMAGE_TAG}
- echo ${IMAGE_REPO_NAME}
build:
commands:
- echo Starting to build ${ENV} # defined in Build environment
- echo Build started on `date`
- echo $DOCKERHUB_PW | docker login -u $DOCKERHUB_USER --password-stdin
- uname -a
- ls -alh
- docker images
- echo Building the Docker image...
- docker build -f ./apps/galaxy/Dockerfile --build-arg N_P_C_B_URL=${N_P_C_B_URL} -t ${IMAGE_REPO_NAME}:latest .
- docker tag ${IMAGE_REPO_NAME}:latest ${REPOSITORY_URI}:${IMAGE_TAG}
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push ${REPOSITORY_URI}:${IMAGE_TAG}
- echo Writing image definitions file...
- sed -i "s|{{imageID}}|${IMAGE_TAG}|" taskdef-uat.json
- printf '[{"name":"%s","imageUri":"%s"}]' ${CC_CONTAINER} ${REPOSITORY_URI}:${IMAGE_TAG} > imagedefinitions.json
- aws ecs register-task-definition --execution-role-arn arn:aws:iam::245866473499:role/myEcsTaskExecutionRole --cli-input-json file://taskdef-uat.json --region ap-southeast-2
- aws ecs update-service --cluster ${AWS_ECS_CLUSTER} --service ${AWS_ECS_SERVICE} --task-definition ${task_def_arn} --region ap-southeast-2
artifacts:
files: imagedefinitions.json