-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildspec.yml
58 lines (54 loc) · 2.3 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
58
version: 0.2
#https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
#####
# Performs an infrastructure deployment.
# For Code Deployments see CircleCI and AWS CodeDeploy
#####
run-as: circleci
env:
variables:
#Terraform workspace that we operate in
TF_DEV_WORKSPACE: Dev
TF_WORKSPACE: Prod
#The ref of the main branch we work against
MAIN_BRANCH_REF: "refs/heads/main"
MAIN_BRANCH: "main"
#The ref of the dev branch we work against
DEV_BRANCH_REF: "refs/heads/dev"
DEV_BRANCH: "dev"
#Metaflow requires a username to run
USERNAME: "codebuild"
secrets-manager:
PAGERDUTY_TOKEN: "CodeBuild/Default:pagerduty_token"
GITHUB_ACCESS_TOKEN: "CodeBuild/Default:github_access_token"
#All phases are ran within the pocket/pocket-build:prod docker image
phases:
pre_build:
run-as: circleci
commands:
- . /home/circleci/.codebuild_shims_wrapper.sh
- echo $CODEBUILD_WEBHOOK_HEAD_REF
- echo Setting Github Access Token
- echo "//npm.pkg.github.com/:_authToken=${GITHUB_ACCESS_TOKEN}" > ~/.npmrc
- echo Setting environment variables
- cd .aws
- npm ci
- tfenv install
# synthesize the js into terraform json with the proper node environment
- 'if [ "$GIT_BRANCH" = "$DEV_BRANCH" ]; then NODE_ENV=development npm run synth; else npm run synth; fi'
- cd cdktf.out/stacks/syntheticchecks
- 'if [ "$GIT_BRANCH" = "$DEV_BRANCH" ]; then TF_WORKSPACE=$TF_DEV_WORKSPACE terraform init; else terraform init; fi'
build:
run-as: circleci
commands:
- echo Build started on `date`
### If the branch is not main, and it's not dev, lets do a plan on prod.
- 'if [ "$CODEBUILD_WEBHOOK_HEAD_REF" != "$MAIN_BRANCH_REF" ] && [ "$CODEBUILD_WEBHOOK_HEAD_REF" != "$DEV_BRANCH_REF" ] && [ -z "$GIT_BRANCH" ]; then terraform plan -lock=false -refresh=false -no-color; fi'
#### If the branch is dev, lets do an apply on dev.
- 'if [ "$GIT_BRANCH" = "$DEV_BRANCH" ]; then TF_WORKSPACE=$TF_DEV_WORKSPACE TF_LOG=INFO terraform apply -auto-approve -no-color; fi'
#### If the branch is main lets apply.
- 'if [ "$GIT_BRANCH" = "$MAIN_BRANCH" ]; then terraform apply -auto-approve -no-color; fi'
post_build:
run-as: circleci
commands:
- echo Build completed on `date`