CD #16
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"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| env: | |
| IMAGE: ${{ secrets.DOCKER_USERNAME }}/talky-backend | |
| COMPOSE_FILE: docker-compose.yml | |
| jobs: | |
| deploy: | |
| name: Deploy to Server | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Copy docker-compose.yml to server | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| source: "${{ env.COMPOSE_FILE }}" | |
| target: "/home/${{ secrets.SERVER_USER }}/" | |
| - name: Deploy with Docker Compose | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd /home/${{ secrets.SERVER_USER }}/ | |
| # .env 파일 생성 및 DOCKER_USERNAME 추가 | |
| echo "${{ secrets.ENV_FILE }}" > .env | |
| echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> .env | |
| echo "[1/3] Pull latest Docker image for Spring service..." | |
| docker compose -f ${{ env.COMPOSE_FILE }} pull spring | |
| echo "[2/3] Restart Spring service with new image..." | |
| docker compose -f ${{ env.COMPOSE_FILE }} up -d --no-deps --force-recreate spring | |
| echo "[3/3] Cleanup unused images..." | |
| docker image prune -f |