-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildspec.yml
executable file
·63 lines (54 loc) · 2.55 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
59
60
61
62
63
version: 0.2
phases:
pre_build:
commands:
# Install dependencies
- echo "Installing dev dependencies"
- apt-get update
- apt-get install -y python3-pip make graphviz unzip
- pip3 install -r requirements.txt
# Documentation Test
- echo "Generating documentation"
- make html
# Install Terraform
- echo "Installing Terraform"
- cd terraform
- curl -o terraform.zip https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip
- unzip -o terraform.zip
- sudo mv terraform /usr/local/bin/
- terraform --version
- terraform init && terraform validate
build:
commands:
# Deployment commands
- echo "Deploying Bootstrap Architecture..."
- |
PF_ECR_REPO=sdc_aws_processing_lambda
SF_ECR_REPO=sdc_aws_sorting_lambda
AF_ECR_REPO=sdc_aws_artifacts_lambda
if git describe --tags --exact-match > /dev/null 2>&1; then
echo "This is a tag push event"
CDK_ENVIRONMENT=PRODUCTION
terraform workspace select prod
elif [ "${CDK_ENVIRONMENT}" = "PRODUCTION" ]; then
echo "This is a production environment"
terraform workspace select prod
else
echo "This is a development environment"
PF_ECR_REPO=dev-sdc_aws_processing_lambda
SF_ECR_REPO=dev-sdc_aws_sorting_lambda
AF_ECR_REPO=sdc_aws_artifacts_lambda
terraform workspace select dev
fi
# Fetch latest image and SF image tag
- |
PF_IMAGE_TAG=$(aws ecr describe-images --repository-name $PF_ECR_REPO --region us-east-1 --query "sort_by(imageDetails,& imagePushedAt)[-1].imageTags[]" --output text | awk '{for(i=1;i<=NF;i++) if($i!="latest") print $i; exit}')
echo $PF_IMAGE_TAG
SF_IMAGE_TAG=$(aws ecr describe-images --repository-name $SF_ECR_REPO --region us-east-1 --query "sort_by(imageDetails,& imagePushedAt)[-1].imageTags[]" --output text | awk '{for(i=1;i<=NF;i++) if($i!="latest") print $i; exit}')
echo $SF_IMAGE_TAG
AF_IMAGE_TAG=$(aws ecr describe-images --repository-name $AF_ECR_REPO --region us-east-1 --query "sort_by(imageDetails,& imagePushedAt)[-1].imageTags[]" --output text | awk '{for(i=1;i<=NF;i++) if($i!="latest") print $i; exit}')
echo $AF_IMAGE_TAG
# Run Terraform apply
- terraform apply -auto-approve -var "pf_image_tag=$PF_IMAGE_TAG" -var "sf_image_tag=$SF_IMAGE_TAG" -var "af_image_tag=$AF_IMAGE_TAG"
# Completion message
- echo "Build completed on $(date)"