-
Notifications
You must be signed in to change notification settings - Fork 7
59 lines (48 loc) · 1.79 KB
/
build.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
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Start Terraform infrastructure
run: |
export TF_VAR_aws_api_key='${{ secrets.AWS_API_KEY_1 }}'
export TF_VAR_aws_api_secret='${{ secrets.AWS_API_SECRET_1 }}'
./.github/resources/scripts/start_terraform.sh
- name: Set new AWS instances private key
run: |
echo "⚙️ Set AWS AMI private key."
AWS_AMI_PRIVATE_KEY_FILE=$(mktemp)
echo "${{ secrets.AWS_AMI_PRIVATE_KEY }}" > $AWS_AMI_PRIVATE_KEY_FILE
chmod 600 $AWS_AMI_PRIVATE_KEY_FILE
echo "AWS_AMI_PRIVATE_KEY_FILE=$AWS_AMI_PRIVATE_KEY_FILE" >> $GITHUB_ENV
- name: Wait for 60s
run: sleep 60s
- name: Copy files
run: |
./.github/resources/scripts/copy_files.sh
- name: Build images on remote instances
run: |
./.github/resources/scripts/build_images.sh
- name: Push images on Docker Hub
if: github.ref == 'refs/heads/main'
run: |
export DOCKER_PASSWORD=${{ secrets.DOCKER_HUB_REGISTRY_PASSWORD }}
./.github/resources/scripts/push_images.sh
- name: Push tags on Docker Hub
if: github.ref == 'refs/heads/main'
run: |
export DOCKER_PASSWORD=${{ secrets.DOCKER_HUB_REGISTRY_PASSWORD }}
./.github/resources/scripts/push_tags.sh
- name: Destroy Terraform infrastructure
if: ${{ always() }}
run: |
export TF_VAR_aws_api_key='${{ secrets.AWS_API_KEY_1 }}'
export TF_VAR_aws_api_secret='${{ secrets.AWS_API_SECRET_1 }}'
./.github/resources/scripts/destroy_terraform.sh