-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathbuildspec-blue-green.yml
46 lines (39 loc) · 1.5 KB
/
buildspec-blue-green.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
version: 0.2
env:
variables:
IMAGE_REPO_NAME: reinvent-trivia-backend
phases:
install:
runtime-versions:
nodejs: latest
commands:
# Install CDK & jq, upgrade npm
- yum install -y jq
- npm install -g aws-cdk
pre_build:
commands:
# Set up environment variables like image tag and repo
- cd $CODEBUILD_SRC_DIR/trivia-backend
- export IMAGE_TAG=build-`echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}'`
- AWS_ACCOUNT_ID=`echo $CODEBUILD_BUILD_ARN | awk -F":" '{print $5}'`
- ECR_REPO=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
- aws ecr get-login-password | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
# Consume base image
- export BASE_IMAGE=`jq -r '.ImageURI' <$CODEBUILD_SRC_DIR_BaseImage/imageDetail.json`
- sed -i "s|reinvent-trivia-backend-base:release|$BASE_IMAGE|g" Dockerfile
build:
commands:
# Build Docker image
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $ECR_REPO:$IMAGE_TAG
- docker push $ECR_REPO:$IMAGE_TAG
# Synthesize CloudFormation templates
- cd $CODEBUILD_SRC_DIR/trivia-backend/infra/cdk
- npm ci
- npm run build
- cdk --no-version-reporting synth -o build --app 'node ecs-service-blue-green.js'
- cp StackConfig.json build/
artifacts:
files:
- trivia-backend/infra/cdk/build/*
discard-paths: yes