-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (72 loc) · 2.68 KB
/
deploy.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Deploy
on:
push:
branches:
- main
paths:
- 'terraform/**'
- '.github/workflows/deploy.yml'
- 'lambda_function/**'
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Package Lambda function
run: |
cd lambda_function
zip -r ../terraform/lambda_function.zip . -x "venv/*"
echo "Lambda function zipped"
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
- name: Make scripts executable
working-directory: ./terraform
run: |
chmod +x ./scripts/upload_to_s3.sh
chmod +x ./scripts/upload_resume.py
chmod +x ./scripts/s3_backend.sh
chmod +x ./empty_bucket.py
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install boto3
- name: Create s3 backend
working-directory: ./terraform/scripts
run: ./s3_backend.sh
- name: Decrypt tfvars file, Initialize and Deploy infrastructure with Terraform
working-directory: ./terraform
run: |
gpg --quiet --batch --yes --decrypt --passphrase="$SECRET_PASSPHRASE" --output variables.tfvars variables.tfvars.gpg
terraform init
terraform apply -auto-approve -var-file="variables.tfvars"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SECRET_PASSPHRASE: ${{ secrets.SECRET_PASSPHRASE }}
- name: Check for failure
if: ${{ failure() }}
run: echo "A previous step failed. Proceeding to destroy infrastructure."
- name: Empty S3 bucket
if: ${{ failure() }}
working-directory: ./terraform
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: python3 empty_bucket.py
- name: Destroy Terraform
working-directory: ./terraform
if: ${{ failure() }}
run: terraform destroy -var-file=variables.tfvars -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}