Build & Deploy / build-and-push (backend) (push) Successful in 25s
Build & Deploy / build-and-push (discord-gateway) (push) Successful in 26s
Build & Deploy / build-and-push (proxy) (push) Successful in 4m10s
docker compose down can fail silently, breaking the && chain and preventing docker rm -f from running. Using || true on each step ensures every cleanup command runs independently. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68 lines
2.5 KiB
YAML
68 lines
2.5 KiB
YAML
name: Build & Deploy
|
|
run-name: "Build & Deploy ${{ github.sha }}"
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
max-parallel: 1
|
|
matrix:
|
|
service: [backend, discord-gateway, proxy]
|
|
steps:
|
|
- name: Setup
|
|
run: |
|
|
set -eu
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends ca-certificates git docker.io
|
|
git config --global http.sslVerify false
|
|
|
|
- name: Checkout
|
|
run: |
|
|
cd /tmp
|
|
git clone --depth 1 https://MythEclipse:${{ secrets.REGISTRY_TOKEN }}@git.imrnes.team/MythEclipse/GMW.git repo
|
|
cd /tmp/repo
|
|
|
|
- name: Docker Login
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ vars.REGISTRY }} -u MythEclipse --password-stdin
|
|
|
|
- name: Build & Push ${{ matrix.service }}
|
|
env:
|
|
DOCKER_BUILDKIT: "1"
|
|
run: |
|
|
cd /tmp/repo
|
|
IMG=${{ vars.REGISTRY }}/mytheclipse/gmw/bete-${{ matrix.service }}
|
|
docker build \
|
|
--file infra/docker/Dockerfile.${{ matrix.service }} \
|
|
--tag $IMG:${{ github.sha }} \
|
|
--tag $IMG:latest \
|
|
--build-arg VITE_BE_API_URL=https://imphnen.asepharyana.my.id \
|
|
--build-arg VITE_BE_WS_URL=wss://imphnen.asepharyana.my.id \
|
|
.
|
|
docker push $IMG:${{ github.sha }}
|
|
docker push $IMG:latest
|
|
|
|
- name: Deploy (proxy only — after all pushes)
|
|
if: matrix.service == 'proxy' && github.ref == 'refs/heads/main'
|
|
env:
|
|
ENV_FILE: ${{ secrets.ENV_FILE }}
|
|
SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
|
|
VPS_USER: ${{ secrets.VPS_USER }}
|
|
VPS_HOST: ${{ secrets.VPS_HOST }}
|
|
run: |
|
|
set -eu
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends openssh-client ca-certificates
|
|
mkdir -p ~/.ssh
|
|
echo "$SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
ENV_B64=$(echo "$ENV_FILE" | base64 -w0)
|
|
ssh -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 -o ServerAliveCountMax=3 \
|
|
"$VPS_USER@$VPS_HOST" \
|
|
"cd /opt/imphenbot/infra/docker && echo '$ENV_B64' | base64 -d > .env && docker compose pull || true && docker compose down --remove-orphans || true && docker rm -f imphenbot-discord-gateway imphenbot-backend imphenbot-proxy || true && docker compose up -d --remove-orphans && docker image prune -f"
|