Merge pull request #62 from DrInTech22/integration #10
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: Frontend CD Pipeline | |
on: | |
push: | |
branches: | |
- deployment | |
paths: | |
- 'frontend/**' | |
- '!frontend/*.md' | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Prepare Frontend Env | |
run: | | |
# Frontend env file | |
echo "VITE_API_URL=https://test.drintech.online" > 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: Copy files to Server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ env.PUBLIC_IP }} | |
username: ${{ vars.EC2_USER }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
source: "frontend.env, 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: | | |
mv frontend.env frontend/.env | |
touch backend/.env | |
# docker compose down frontend | |
docker compose up -d --no-deps --force-recreate frontend | |
frontend/.env backend/.env |