refactor: split monolith into 3 microservices (frontend, backend, discord-gateway)
- Extract services into services/{frontend,backend,discord-gateway}
- Create packages/shared/ for shared logger, errors, utils, types
- Setup Modular MVC pattern in backend (controller→service→repository)
- Setup event-driven architecture in discord-gateway with Redis pub/sub
- Move Docker files to infra/docker/ with per-service Dockerfiles
- Update docker-compose.yml to use Traefik-only routing (no port exposes)
- Update GitHub Actions deploy workflow for multi-service matrix build
- Fix all import paths and resolve type errors across all services
- All 3 services pass tsc --noEmit clean
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
bda8304bb9
commit
c48a0c5e3b
@@ -11,20 +11,21 @@ permissions:
|
||||
packages: write
|
||||
|
||||
env:
|
||||
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/bete
|
||||
REGISTRY: ghcr.io
|
||||
OWNER: ${{ github.repository_owner }}
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
service: [frontend, backend, discord-gateway]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Normalize image name
|
||||
run: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
@@ -35,19 +36,28 @@ jobs:
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
- name: Build and push ${{ matrix.service }}
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: infra/docker/Dockerfile.${{ matrix.service }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.IMAGE_NAME }}:${{ github.sha }}
|
||||
${{ 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
|
||||
|
||||
deploy:
|
||||
needs: build-and-push
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Deploy to VPS
|
||||
uses: appleboy/ssh-action@v1.2.5
|
||||
env:
|
||||
IMAGE_NAME: ${{ env.IMAGE_NAME }}
|
||||
GHCR_USERNAME: ${{ github.actor }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
ENV_FILE: ${{ secrets.ENV_FILE }}
|
||||
@@ -55,7 +65,7 @@ jobs:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USERNAME }}
|
||||
key: ${{ secrets.VPS_SSH_KEY }}
|
||||
envs: IMAGE_NAME,GHCR_USERNAME,GHCR_TOKEN,ENV_FILE
|
||||
envs: GHCR_USERNAME,GHCR_TOKEN,ENV_FILE
|
||||
script: |
|
||||
set -eu
|
||||
|
||||
@@ -63,27 +73,58 @@ jobs:
|
||||
mkdir -p "$APP_DIR"
|
||||
cd "$APP_DIR"
|
||||
|
||||
printf '%s\nIMAGE_NAME=%s:latest\n' "$ENV_FILE" "$IMAGE_NAME" > .env
|
||||
printf '%s\n' "$ENV_FILE" > .env
|
||||
|
||||
cat > docker-compose.yml <<'EOF'
|
||||
cat > docker-compose.yml <<'COMPOSE_EOF'
|
||||
services:
|
||||
app:
|
||||
image: ${IMAGE_NAME}
|
||||
container_name: imphenbot-app
|
||||
backend:
|
||||
image: ghcr.io/${OWNER:-mytheclipse}/bete-backend:latest
|
||||
container_name: imphenbot-backend
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./recordings:/app/recordings
|
||||
- ./.muxer-queue.db:/app/.muxer-queue.db
|
||||
- ./.muxer-queue.db-shm:/app/.muxer-queue.db-shm
|
||||
- ./.muxer-queue.db-wal:/app/.muxer-queue.db-wal
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
WEBSERVER_PORT: 3000
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.imphenbot.rule=Host(`imphnen.asepharyana.tech`)"
|
||||
- "traefik.http.routers.imphenbot.entrypoints=websecure"
|
||||
- "traefik.http.routers.imphenbot.tls=true"
|
||||
- "traefik.http.services.imphenbot.loadbalancer.server.port=3000"
|
||||
- "traefik.http.routers.imphenbot-backend.rule=Host(`imphnen.asepharyana.my.id`) && PathPrefix(`/api`, `/ws`)"
|
||||
- "traefik.http.routers.imphenbot-backend.entrypoints=websecure"
|
||||
- "traefik.http.routers.imphenbot-backend.tls=true"
|
||||
- "traefik.http.services.imphenbot-backend.loadbalancer.server.port=3000"
|
||||
depends_on:
|
||||
- discord-gateway
|
||||
networks:
|
||||
- app-shared-net
|
||||
|
||||
discord-gateway:
|
||||
image: ghcr.io/${OWNER:-mytheclipse}/bete-discord-gateway:latest
|
||||
container_name: imphenbot-discord-gateway
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
volumes:
|
||||
- ./recordings:/app/recordings
|
||||
networks:
|
||||
- app-shared-net
|
||||
|
||||
frontend:
|
||||
image: ghcr.io/${OWNER:-mytheclipse}/bete-frontend:latest
|
||||
container_name: imphenbot-frontend
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
VITE_API_URL: https://imphnen.asepharyana.my.id
|
||||
VITE_WS_URL: wss://imphnen.asepharyana.my.id
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.imphenbot-frontend.rule=Host(`imphnen.asepharyana.my.id`)"
|
||||
- "traefik.http.routers.imphenbot-frontend.entrypoints=websecure"
|
||||
- "traefik.http.routers.imphenbot-frontend.tls=true"
|
||||
- "traefik.http.services.imphenbot-frontend.loadbalancer.server.port=3000"
|
||||
depends_on:
|
||||
- backend
|
||||
networks:
|
||||
- app-shared-net
|
||||
|
||||
@@ -91,9 +132,8 @@ jobs:
|
||||
app-shared-net:
|
||||
name: app-shared-net
|
||||
external: true
|
||||
EOF
|
||||
COMPOSE_EOF
|
||||
|
||||
touch .muxer-queue.db .muxer-queue.db-shm .muxer-queue.db-wal
|
||||
mkdir -p recordings
|
||||
|
||||
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
|
||||
|
||||
Reference in New Issue
Block a user