- Replace build: blocks with image: from ghcr.io - Simplify deploy: git clone/pull on VPS, then docker compose pull/up - Remove SCP step entirely — nginx.conf baked into proxy image - Rename containers to imphenbot-* to match existing VPS setup - Fix backend port to 3000 for production Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
98 lines
2.7 KiB
YAML
98 lines
2.7 KiB
YAML
name: Deploy to VPS
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
OWNER: mytheclipse
|
|
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
service: [frontend, backend, discord-gateway, proxy]
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push ${{ matrix.service }}
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: infra/docker/Dockerfile.${{ matrix.service }}
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ env.OWNER }}/bete-${{ matrix.service }}:latest
|
|
${{ env.REGISTRY }}/${{ env.OWNER }}/bete-${{ matrix.service }}:${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
build-args: |
|
|
VITE_BE_API_URL=https://imphnen.asepharyana.my.id
|
|
VITE_BE_WS_URL=wss://imphnen.asepharyana.my.id
|
|
|
|
deploy:
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
if: github.ref == 'refs/heads/master'
|
|
steps:
|
|
- name: Deploy to VPS
|
|
uses: appleboy/ssh-action@v1.2.5
|
|
env:
|
|
GHCR_USERNAME: ${{ github.actor }}
|
|
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
ENV_FILE: ${{ secrets.ENV_FILE }}
|
|
with:
|
|
host: ${{ secrets.VPS_HOST }}
|
|
username: ${{ secrets.VPS_USERNAME }}
|
|
key: ${{ secrets.VPS_SSH_KEY }}
|
|
envs: GHCR_USERNAME,GHCR_TOKEN,ENV_FILE
|
|
script: |
|
|
set -eu
|
|
|
|
APP_DIR=/opt/imphenbot
|
|
REPO_URL=https://github.com/MythEclipse/bete.git
|
|
|
|
if [ ! -d "$APP_DIR/.git" ]; then
|
|
mkdir -p "$APP_DIR"
|
|
git clone "$REPO_URL" "$APP_DIR"
|
|
fi
|
|
|
|
cd "$APP_DIR"
|
|
git fetch origin master
|
|
git checkout master
|
|
git reset --hard origin/master
|
|
|
|
printf '%s\n' "$ENV_FILE" > .env
|
|
|
|
mkdir -p recordings
|
|
|
|
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
|
|
|
|
docker compose -f infra/docker/docker-compose.yml pull
|
|
docker compose -f infra/docker/docker-compose.yml down --remove-orphans || true
|
|
docker compose -f infra/docker/docker-compose.yml up -d --remove-orphans
|
|
docker image prune -f
|