diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index e8d0f4ff..43c0883e 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,12 +1,13 @@ -# main 브랜치에 push 되면 배포 서버의 러너가 이미지를 빌드하고 컨테이너를 재기동합니다. +# main 브랜치에 push 되면 배포 서버의 러너가 영구 배포 디렉터리에서 +# git pull 후 이미지를 빌드하고 컨테이너를 재기동합니다. # # 사전 준비 (배포 서버에서 1회): -# 1. Gitea 관리자 설정에서 Actions 활성화 -# 2. act_runner를 배포 서버에 설치하고, host 모드 라벨 "deploy"로 등록 -# (config.yml 의 labels 에 "deploy:host" 추가 후 register) -# 3. 저장소 Settings > Actions > Secrets 에 등록: -# - ENV_FILE : 루트 .env 전체 내용 (DB 비밀번호, JWT 시크릿 등) -# - FRONTEND_ENV_FILE : frontend/.env.production 전체 내용 (VITE_API_BASE_URL 등) +# 1. act_runner를 host 모드 라벨 "deploy"로 등록 (러너 계정: deploy) +# 2. 영구 배포 디렉터리 준비: +# git clone https://git.wandergo.net/partnership/blog_report.git ~/stacks/_clients/blog_report +# 해당 디렉터리에 .env 와 frontend/.env.production 을 생성 (chmod 600) +# +# .env 는 gitignore 대상이라 git 작업에 영향받지 않고 서버에 유지됩니다. name: Deploy @@ -14,23 +15,35 @@ on: push: branches: [main] +env: + DEPLOY_DIR: /home/deploy/stacks/_clients/blog_report + jobs: deploy: runs-on: deploy steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Create env files from secrets + - name: Pull latest code run: | - printf '%s\n' "${{ secrets.ENV_FILE }}" > .env - printf '%s\n' "${{ secrets.FRONTEND_ENV_FILE }}" > frontend/.env.production + cd "$DEPLOY_DIR" + git remote set-url origin "https://gitea-actions:${{ github.token }}@git.wandergo.net/partnership/blog_report.git" + git fetch origin main + git reset --hard origin/main + + - name: Check env files exist + run: | + cd "$DEPLOY_DIR" + test -f .env || { echo "ERROR: $DEPLOY_DIR/.env 가 없습니다"; exit 1; } + test -f frontend/.env.production || { echo "ERROR: frontend/.env.production 이 없습니다"; exit 1; } - name: Build images - run: docker compose build backend frontend + run: | + cd "$DEPLOY_DIR" + docker compose build backend frontend - name: Restart containers - run: docker compose up -d + run: | + cd "$DEPLOY_DIR" + docker compose up -d - name: Prune dangling images run: docker image prune -f