- test job: lint + vitest + build - docker job: main 머지 시 nginx 이미지 빌드/푸시 - deploy job: SSH로 docker compose pull web && up Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
2.2 KiB
YAML
80 lines
2.2 KiB
YAML
name: CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
# ── 1. 린트 + 테스트 + 빌드 ────────────────────────────────────────────────
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci --legacy-peer-deps
|
|
|
|
- name: Lint
|
|
run: npm run lint
|
|
|
|
- name: Test
|
|
run: npm test
|
|
|
|
- name: Build
|
|
run: npm run build
|
|
env:
|
|
VITE_API_BASE_URL: https://a301.api.tolelom.xyz
|
|
|
|
# ── 2. Docker 빌드 & GHCR 푸시 (main 머지 시만) ───────────────────────────
|
|
docker:
|
|
needs: test
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: docker/setup-buildx-action@v3
|
|
|
|
- uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ghcr.io/${{ github.repository_owner }}/a301-web:latest
|
|
platforms: linux/arm64
|
|
build-args: |
|
|
VITE_API_BASE_URL=https://a301.api.tolelom.xyz
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# ── 3. 서버 배포 (Docker 푸시 완료 후) ────────────────────────────────────
|
|
deploy:
|
|
needs: docker
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: ${{ secrets.SERVER_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
script: |
|
|
export PATH=$PATH:/usr/local/bin:/opt/homebrew/bin:$HOME/.docker/bin
|
|
cd ~/server
|
|
docker compose pull web
|
|
docker compose up -d web
|