CD #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CD | |
| on: | |
| workflow_run: | |
| workflows: ["CI with Gradle"] # CI 워크플로 이름과 정확히 일치해야 함 | |
| types: [completed] # CI가 끝났을 때 트리거 | |
| branches: [main] # 특정 브랜치에서만 | |
| permissions: | |
| contents: read | |
| env: | |
| IMAGE: ${{ secrets.DOCKER_USERNAME }}/leafly | |
| jobs: | |
| deploy: | |
| name: Deploy to Server | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # SSH로 서버에 접속해 배포 | |
| - name: Deploy over SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| port: 22 | |
| script: | | |
| echo "${{ secrets.ENV_FILE }}" > /home/${{ secrets.SERVER_USER }}/.env | |
| echo "[1/3] Pull latest Docker image..." | |
| docker pull ${{ env.IMAGE }}:latest | |
| echo "[2/3] Restart container with new image..." | |
| docker stop leafly || true | |
| docker rm leafly || true | |
| docker run -d --name leafly \ | |
| --env-file /home/${{ secrets.SERVER_USER }}/.env \ | |
| -p 8080:8080 \ | |
| ${{ env.IMAGE }}:latest | |
| echo "[3/3] Cleanup unused images..." | |
| docker image prune -f |