Skip to content

Add control relay schema and enhance control relay endpoint with dyna… #18

Add control relay schema and enhance control relay endpoint with dyna…

Add control relay schema and enhance control relay endpoint with dyna… #18

Workflow file for this run

name: Deploy PCB Backend
on:
push:
branches: [ "main" ] # Trigger saat push ke main
env:
# GANTI DENGAN USERNAME GITHUB KAMU (HURUF KECIL):
IMAGE_NAME: bagus-devlab/pcb-backend-api
REGISTRY: ghcr.io
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_KEY }}
port: 22
script: |
cd /var/www/pcb-backend/API-PCB
# 1. PAKSA TIMPA perubahan manual di server dengan yang ada di GitHub
git fetch origin main
git reset --hard origin/main
# 2. Login GHCR
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# 3. Tarik Image Terbaru (Explicit Pull)
docker-compose pull
# 4. Restart Container dengan Opsi FORCE
# --force-recreate: Paksa bikin ulang container meski config gak berubah
# --remove-orphans: Hapus container hantu
docker-compose up -d --force-recreate --remove-orphans
# 5. Bersih-bersih
docker image prune -f