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: Build & Deploy Spike (GHCR → EC2) | |
| on: | |
| push: | |
| branches: [ main ] | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-push-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build & Push spike image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/dmu-debugvisual/debugvisual-spike:latest | |
| ghcr.io/dmu-debugvisual/debugvisual-spike:${{ github.sha }} | |
| - name: Deploy on EC2 (compose pull/up) | |
| env: | |
| HOST: ${{ secrets.EC2_HOST }} | |
| USER: ${{ secrets.EC2_USER }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_KEY }}" > ~/.ssh/id_rsa | |
| sed -i 's/\r$//' ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts | |
| ssh "$USER@$HOST" "bash -s" << 'EOSSH' | |
| set -e | |
| LOCK=/tmp/debugvisual.deploy.lock | |
| ( | |
| flock -n 9 || { echo 'Another deploy is running. Skip.'; exit 0; } | |
| cd ~/apps/debugvisual | |
| docker logout ghcr.io || true # 익명 pull 강제 | |
| docker compose pull --ignore-pull-failures flask-server | |
| docker compose up -d --wait --remove-orphans flask-server | |
| docker image prune -af || true | |
| curl -skI https://api.zivorp.com/healthz | head -n1 | |
| ) 9>$LOCK | |
| EOSSH |