-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f079d63
commit e1ad539
Showing
3 changed files
with
81 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,49 @@ | ||
name: Terraform | ||
name: Terraform AWS Deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
terraform: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_REGION: us-west-2 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v3 | ||
|
||
- name: Verify AWS Secrets Presence (Debug Step) | ||
run: | | ||
if [ -z "${{ secrets.AWS_ACCESS_KEY_ID }}" ]; then | ||
echo "AWS_ACCESS_KEY_ID secret is not set" | ||
exit 1 | ||
fi | ||
if [ -z "${{ secrets.AWS_SECRET_ACCESS_KEY }}" ]; then | ||
echo "AWS_SECRET_ACCESS_KEY secret is not set" | ||
exit 1 | ||
fi | ||
echo "AWS secrets are set" | ||
- 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: us-west-2 | ||
|
||
- name: Verify AWS credentials | ||
run: aws sts get-caller-identity | ||
|
||
- name: Initialize Terraform | ||
run: terraform init | ||
working-directory: terraform | ||
|
||
- name: Plan Terraform | ||
run: terraform plan -out=tfplan | ||
working-directory: terraform | ||
|
||
- name: Apply Terraform | ||
run: terraform apply -auto-approve tfplan | ||
working-directory: terraform | ||
|
||
- name: Wait for 6 minutes | ||
run: sleep 600 # 360 seconds equals 4 minutes | ||
|
||
- name: Destroy Terraform | ||
run: terraform destroy -auto-approve | ||
working-directory: terraform | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v1 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Terraform Init | ||
run: terraform init | ||
|
||
- name: Terraform Plan | ||
run: terraform plan | ||
|
||
- name: Terraform Apply | ||
if: github.ref == 'refs/heads/main' | ||
run: terraform apply -auto-approve | ||
|
||
- name: Cleanup old resources | ||
if: always() | ||
run: | | ||
# List and remove old security groups that aren't being used | ||
OLD_SGS=$(aws ec2 describe-security-groups --query 'SecurityGroups[?contains(GroupName, `allow_ssh_`) || contains(GroupName, `allow_http_flask_`)].GroupId' --output text) | ||
for SG_ID in $OLD_SGS; do | ||
aws ec2 delete-security-group --group-id $SG_ID || true | ||
done | ||
continue-on-error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from flask import Flask | ||
import chromadb | ||
|
||
app = Flask(__name__) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters