CD #15
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 }}/mobile | |
| jobs: | |
| deploy: | |
| name: Deploy to Server | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - 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: | | |
| set -e | |
| cd ~/mobile | |
| echo "${{ secrets.ENV_FILE }}" > .env | |
| # >> 는 파일 내용을 덮어쓰지 않고 맨 뒤에 추가(append)하는 명령어입니다. | |
| echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> .env | |
| if [ -n "${{ secrets.DOCKER_PASSWORD }}" ]; then | |
| echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| fi | |
| echo "[1/3] Pull latest Docker image..." | |
| docker compose pull spring | |
| echo "[2/3] Restart services with new image..." | |
| docker compose up -d --no-deps spring | |
| echo "[3/3] Cleanup unused images..." | |
| docker image prune -f | |