From 61142ed55ef16c2136868a7fdd40b9b8c81ea7ff Mon Sep 17 00:00:00 2001 From: shinalok Date: Fri, 7 Aug 2026 19:04:30 +0900 Subject: [PATCH] add CI/CD workflow for testing and deployment steps on main branch push --- .gitea/workflows/ci-cd.yml | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .gitea/workflows/ci-cd.yml diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml new file mode 100644 index 0000000..7f75bed --- /dev/null +++ b/.gitea/workflows/ci-cd.yml @@ -0,0 +1,62 @@ +name: CI/CD + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + container: + image: python:3.13-slim + steps: + - name: 저장소 체크아웃 + uses: actions/checkout@v4 + + - name: 테스트용 .env 준비 + run: | + cat > .env <<'EOF' + SECRET_KEY=ci-dummy-secret-key + DATABASE_URL=sqlite:///./ci.db + EOF + + - name: 의존성 설치 + run: pip install -e . + + - name: pytest 실행 + run: pytest + + deploy: + needs: test + if: gitea.ref == 'refs/heads/main' + runs-on: ubuntu-latest + container: + image: alpine:3.20 + steps: + - name: 저장소 체크아웃 + uses: actions/checkout@v4 + + - name: ssh/rsync 설치 + run: apk add --no-cache openssh-client rsync + + - name: SSH 키 준비 + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh-keyscan -p ${{ vars.DEPLOY_SSH_PORT }} ${{ vars.DEPLOY_SSH_HOST }} >> ~/.ssh/known_hosts + + - name: 소스 동기화 + run: | + rsync -avz \ + --exclude='.env' --exclude='media' --exclude='__pycache__' \ + -e "ssh -p ${{ vars.DEPLOY_SSH_PORT }}" \ + pyproject.toml alembic.ini Dockerfile docker-compose.yml app migrations scripts \ + ${{ vars.DEPLOY_SSH_USER }}@${{ vars.DEPLOY_SSH_HOST }}:${{ vars.DEPLOY_REMOTE_PATH }}/ + + - name: 컨테이너 재빌드 & 재시작 + run: | + ssh -p ${{ vars.DEPLOY_SSH_PORT }} ${{ vars.DEPLOY_SSH_USER }}@${{ vars.DEPLOY_SSH_HOST }} \ + "cd ${{ vars.DEPLOY_REMOTE_PATH }} && docker compose build && docker compose up -d" \ No newline at end of file