-
Notifications
You must be signed in to change notification settings - Fork 9
62 lines (59 loc) · 3.79 KB
/
build_test_push_docker_arm.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
name: Build, Test, and Push Datastream Docker Containers on ARM
on:
push:
branches:
- main
paths:
- 'docker/**'
- 'forcingprocessor/**'
- 'scripts/**'
- 'python_tools/**'
- 'research_datastream/terraform/test/execution_gp_arm_docker_buildNtester.json'
- '.github/workflows/forcingprocessor.yml'
- '.github/workflows/datastream_python.yml'
- '.github/workflows/build_test_push_docker_arm.yml'
jobs:
build-test-push-docker-arm:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- name: Configure AWS
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws configure set region us-east-1
- name: Build AWS Infra
run: |
cd research_datastream/terraform
terraform init
terraform validate
../scripts/import_resources.sh ./test/variables_gitactions_arm.tfvars
terraform apply -var-file=./test/variables_gitactions_arm.tfvars -auto-approve
sleep 60
- name: Set permissions
run : |
cd research_datastream/terraform
aws iam attach-role-policy --role-name datastream_ec2_role_github_actions_arm --policy-arn arn:aws:iam::aws:policy/SecretsManagerReadWrite
if ! aws ec2 describe-key-pairs --key-names "actions_key_arm" --query 'KeyPairs[0].KeyName' --output text 2>/dev/null; then aws ec2 create-key-pair --key-name "actions_key_arm" --query 'KeyName' --output text && echo "Key pair 'actions_key_arm' created in AWS"; else echo "Key pair 'actions_key_arm' already exists"; fi
sleep 60
- name: Build and Test arm docker containers with AWS infra
run : |
cd research_datastream/terraform
execution_arn=$(aws stepfunctions start-execution --state-machine-arn $(cat ./sm_ARN.txt) --name docker_builder_$(env TZ=US/Eastern date +'%Y%m%d%H%M%S') --input "file://test/execution_gp_arm_docker_buildNtester.json" --region us-east-1 --query 'executionArn' --output text); echo "Execution ARN: $execution_arn"; status="RUNNING"; while [ "$status" != "SUCCEEDED" ]; do status=$(aws stepfunctions describe-execution --execution-arn "$execution_arn" --region us-east-1 --query 'status' --output text); echo "Current status: $status"; if [ "$status" == "FAILED" ]; then echo "State machine execution failed!"; exit 1; fi; sleep 5; done; echo "State machine execution succeeded!"
- name: Confirm docker push
run : |
docker rmi -f $(docker images -aq)
docker pull awiciroh/datastream:latest
CREATION_EPOCH=$(date --date="$(docker inspect -f '{{.Created}}' awiciroh/datastream:latest)" +%s) && CURRENT_EPOCH=$(date +%s) && TIME_DIFF=$((CURRENT_EPOCH - CREATION_EPOCH)) && [ $TIME_DIFF -le 900 ] && echo "The container was created within the past 15 minutes." || { echo "Error: The container was NOT created within the past 15 minutes."; exit 1; }
docker pull awiciroh/forcingprocessor:latest
CREATION_EPOCH=$(date --date="$(docker inspect -f '{{.Created}}' awiciroh/forcingprocessor:latest)" +%s) && CURRENT_EPOCH=$(date +%s) && TIME_DIFF=$((CURRENT_EPOCH - CREATION_EPOCH)) && [ $TIME_DIFF -le 900 ] && echo "The container was created within the past 15 minutes." || { echo "Error: The container was NOT created within the past 15 minutes."; exit 1; }
sleep 5
- name: Tear down infra
if: always()
run : |
cd research_datastream/terraform
terraform destroy -var-file=./test/variables_gitactions_arm.tfvars -auto-approve
sleep 60