[83] Test deployment #19
Workflow file for this run
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
name: CD for Backend | ||
on: | ||
pull_request: | ||
branches: | ||
- release-* | ||
- * | ||
paths: | ||
- 'backend/**' | ||
jobs: | ||
cd: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./backend | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- 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: ${{ secrets.AWS_REGION }} | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 21 | ||
distribution: 'adopt' | ||
- name: Cache Gradle packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | ||
restore-keys: ${{ runner.os }}-gradle | ||
- name: Run Gradle build | ||
run: ./gradlew build | ||
- name: Zip Gradle build | ||
working-directory: ./backend/build/libs | ||
run: zip backend.zip backend-0.1.jar | ||
- name: Terraform init | ||
run: terraform init -migrate-state | ||
working-directory: ./deployment/cd_backend | ||
- name: Terraform deployment | ||
working-directory: ./deployment/cd_backend | ||
run: | | ||
SECURITY_GROUP_ID=$(aws ec2 describe-security-groups --filters "Name=group-name,Values=${RDS_CONN_SECURITY_GROUP_NAME}" --query "SecurityGroups[0].GroupId" --output text) | ||
TF_VAR_sqs_endpoint=$AWS_SQS_ENDPOINT TF_VAR_rds_connection_sg_id=$SECURITY_GROUP_ID TF_VAR_rds_instance_username=$RDS_INSTANCE_USERNAME TF_VAR_rds_instance_password=$RDS_INSTANCE_PASSWORD TF_VAR_rds_instance_endpoint=$RDS_INSTANCE_ENDPOINT terraform apply -var-file="../variables.tfvars" -replace="aws_instance.ec2_backend" -auto-approve | ||
env: | ||
RDS_CONN_SECURITY_GROUP_NAME: ${{ secrets.RDS_CONN_SECURITY_GROUP_NAME }} | ||
RDS_INSTANCE_USERNAME: ${{ secrets.RDS_INSTANCE_USERNAME }} | ||
RDS_INSTANCE_PASSWORD: ${{ secrets.RDS_INSTANCE_PASSWORD }} | ||
RDS_INSTANCE_ENDPOINT: ${{ secrets.RDS_INSTANCE_ENDPOINT }} | ||
AWS_SQS_ENDPOINT: ${{ secrets.AWS_SQS_ENDPOINT }} |