deploy-backend #4
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: Deploy backend on trigger from the backend repository | |
on: | |
repository_dispatch: | |
types: [deploy-backend] | |
env: | |
AWS_WORK_DIR: "./aws/${{ github.event.client_payload.environment }}/backend" | |
VERSION: ${{ github.event.client_payload.version }} | |
DOWNLOAD_URL_AMD64: ${{ github.event.client_payload.download_url_amd64 }} | |
DOWNLOAD_URL_ARM64: ${{ github.event.client_payload.download_url_arm64 }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.client_payload.sha }} | |
# AWS | |
## AWS (shared) | |
- name: Configure AWS credentials for shared TF state | |
id: shared-tf-state | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.TF_SHARED_ROLE }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
output-credentials: true | |
- name: Configure AWS Credentials File | |
run: | | |
mkdir -p ~/.aws | |
echo "[${{ steps.shared-tf-state.outputs.aws-account-id }}_TFStateLock]" >> ~/.aws/credentials | |
echo "aws_access_key_id=${{ steps.shared-tf-state.outputs.aws-access-key-id }}" >> ~/.aws/credentials | |
echo "aws_secret_access_key=${{ steps.shared-tf-state.outputs.aws-secret-access-key }}" >> ~/.aws/credentials | |
echo "aws_session_token=${{ steps.shared-tf-state.outputs.aws-session-token }}" >> ~/.aws/credentials | |
## AWS (prod) | |
- name: Configure AWS credentials for deployment (prod) | |
if: github.event.client_payload.environment == 'prod' | |
id: prod-deployment | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.BACKEND_PROD_ROLE }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
output-credentials: true | |
- name: Configure AWS Credentials File (prod) | |
if: github.event.client_payload.environment == 'prod' | |
run: | | |
echo "[${{ steps.prod-deployment.outputs.aws-account-id }}_Admin]" >> ~/.aws/credentials | |
echo "aws_access_key_id=${{ steps.prod-deployment.outputs.aws-access-key-id }}" >> ~/.aws/credentials | |
echo "aws_secret_access_key=${{ steps.prod-deployment.outputs.aws-secret-access-key }}" >> ~/.aws/credentials | |
echo "aws_session_token=${{ steps.prod-deployment.outputs.aws-session-token }}" >> ~/.aws/credentials | |
## AWS (dev) | |
- name: Configure AWS credentials for deployment (dev) | |
if: github.event.client_payload.environment == 'dev' | |
id: dev-deployment | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.BACKEND_DEV_ROLE }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
output-credentials: true | |
- name: Configure AWS Credentials File (dev) | |
if: github.event.client_payload.environment == 'dev' | |
run: | | |
echo "[${{ steps.dev-deployment.outputs.aws-account-id }}_Admin]" >> ~/.aws/credentials | |
echo "aws_access_key_id=${{ steps.dev-deployment.outputs.aws-access-key-id }}" >> ~/.aws/credentials | |
echo "aws_secret_access_key=${{ steps.dev-deployment.outputs.aws-secret-access-key }}" >> ~/.aws/credentials | |
echo "aws_session_token=${{ steps.dev-deployment.outputs.aws-session-token }}" >> ~/.aws/credentials | |
# Terraform | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
- name: Initialize Terraform modules | |
run: terraform init | |
working-directory: ${{ env.AWS_WORK_DIR }} | |
# Binary | |
- name: Download latest binary from the backend repository | |
run: | | |
mkdir tmp | |
curl -sSL -o tmp/bootstrap ${{ env.DOWNLOAD_URL_ARM64 }} | |
working-directory: ${{ env.AWS_WORK_DIR }} | |
shell: bash | |
# Deploy | |
- name: Apply Terraform changes (with the new binary) | |
run: terraform apply -auto-approve | |
working-directory: ${{ env.AWS_WORK_DIR }} |