Skip to content

Backend CD Pipeline #18

Backend CD Pipeline

Backend CD Pipeline #18

Workflow file for this run

name: Backend CD Pipeline
on:
push:
branches:
- deployment
paths:
- 'backend/**'
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
# environment:
# name: backend
# url: ${{ vars.URL }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Prepare Frontend Env
env:
FRONTEND_ENV: ${{ secrets.FRONTEND_ENV }}
run: |
echo "$FRONTEND_ENV" > frontend.env
- name: Get terraform-apply.yml Run ID
id: get-run-id
run: |
RUN_ID=$(curl -s \
-H "Authorization: Bearer ${{ secrets.TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/terraform-apply.yml/runs?branch=infra_main&per_page=1" \
| jq -r '.workflow_runs[0].id')
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
echo "$RUN_ID"
- name: Download Public_IP File
uses: actions/download-artifact@v4
with:
name: Public_IP
github-token: ${{ secrets.TOKEN }}
run-id: ${{ steps.get-run-id.outputs.run_id }}
- name: Read public IP
id: read_ip
run: |
PUBLIC_IP=$(grep -oP '\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b' public_ip_env.txt | head -n 1)
echo "PUBLIC_IP=$PUBLIC_IP" >> $GITHUB_ENV
- name: Decrypt Backend Env File
env:
PASSPHRASE: ${{ secrets.ENCRYPTION_PASSPHRASE }}
ENCRYPTED_BACKEND_ENV: ${{ secrets.BACKEND_ENV_FILE }}
run: |
echo "$ENCRYPTED_BACKEND_ENV" | base64 -d | openssl enc -aes-256-cbc -d -pbkdf2 -k "$PASSPHRASE" -out backend.env
- name: Prepare PostgreSQL Password
env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
run: |
echo "$POSTGRES_PASSWORD" > POSTGRES_PASSWORD.txt
- name: Copy files to Server
uses: appleboy/[email protected]
with:
host: ${{ env.PUBLIC_IP }}
username: ${{ vars.EC2_USER }}
key: ${{ secrets.PRIVATE_KEY }}
source: "backend.env, frontend.env, POSTGRES_PASSWORD.txt, compose.yml"
target: "~/"
overwrite: true
- name: Use SSH Action
uses: appleboy/[email protected]
with:
host: ${{ env.PUBLIC_IP }}
username: ${{ vars.EC2_USER }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo chown -R root:root /home/ubuntu/*.env
sudo mv backend.env backend/.env
sudo mv frontend.env frontend/.env
sudo
docker compose up -d --no-deps --force-recreate backend db adminer