-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
39 lines (37 loc) · 1.84 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
version: 0.2
env:
variables:
region: "ap-southeast-2"
bucket: "fromeroad"
key: "prod.tfstate"
phases:
install:
commands:
- cd /usr/bin
- curl -s -qL -o terraform.zip https://releases.hashicorp.com/terraform/1.5.1/terraform_1.5.1_linux_amd64.zip
- unzip -o terraform.zip
- terraform --version
- cd $CODEBUILD_SRC_DIR
- echo $region
- docker login --username $DOCKER_USER --password $DOCKER_PWD
pre_build:
commands:
- echo Logging in to Amazon ECR...
- docker login --username AWS -p $(aws ecr get-login-password --region $region ) $AWS_ID.dkr.ecr.$region.amazonaws.com
- cd terraform && terraform init -var="ACCESS_KEY=$ACCESS_KEY" -var="SECRET_KEY=$SECRET_KEY" -backend-config="bucket=$bucket" -backend-config="region=$region" -backend-config="key=$key" -migrate-state
- terraform plan -var="ACCESS_KEY=$ACCESS_KEY" -var="SECRET_KEY=$SECRET_KEY" -var="region=$region" -var="env=$ENV" -var="RDS_USER=$RDS_USER" -var="RDS_PASSWORD=$RDS_PWD"
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- cd ../api && docker build -t fr_ecr_$ENV .
- docker tag fr_ecr_$ENV:latest $AWS_ID.dkr.ecr.$region.amazonaws.com/fr_ecr_$ENV:latest
- docker tag fr_ecr_$ENV $AWS_ID.dkr.ecr.$region.amazonaws.com/fr_ecr_$ENV:$CODEBUILD_BUILD_NUMBER
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ID.dkr.ecr.$region.amazonaws.com/fr_ecr_$ENV:latest
- docker push $AWS_ID.dkr.ecr.$region.amazonaws.com/fr_ecr_$ENV:$CODEBUILD_BUILD_NUMBER
post_build:
commands:
- cd ../terraform
- terraform apply -auto-approve -var="ACCESS_KEY=$ACCESS_KEY" -var="SECRET_KEY=$SECRET_KEY" -var="region=$region" -var="env=$ENV" -var="RDS_USER=$RDS_USER" -var="RDS_PASSWORD=$RDS_PWD"