-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuildspec.yml
57 lines (56 loc) · 2.4 KB
/
buildspec.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
version: 0.2
env:
parameter-store:
DOCKERHUB_USER: 'AW_DOCKERHUB_USERNAME'
DOCKERHUB_PW: 'AW_DOCKERHUB_PW'
ECR_URI_PREFIX: 'CC_ECR_URI_PREFIX'
DATA_MIGRATION_URL: 'DATA_MIGRATION_URL_DEV'
DATA_MIGRATION_URL_PROD: 'DATA_MIGRATION_URL_PROD'
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
- pwd
- ls -alh
- docker images
- echo Building the Docker image...
- docker build -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
# $AW_CONTAINER defined in Build Environment
- npm i
- export DATA_MIGRATION_URL=${DATA_MIGRATION_URL}
- export DATABASE=DEV
- export PORT=8080
- npm run migrate-up
- 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
- export DATA_MIGRATION_URL=${DATA_MIGRATION_URL_PROD}
- export DATABASE=PROD
- export PORT=8080
- npm run migrate-up
artifacts:
files: imagedefinitions.json