ci: skip nginx pull (not built in CI) #43
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 and Push Images | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write # Required to push to GHCR | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: pd-graduation-project/pd-server | |
| jobs: | |
| build-app: | |
| name: Build App Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push App | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile.app | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-app:latest | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-app:${{ github.sha }} | |
| cache-from: type=gha,scope=pd-app | |
| cache-to: type=gha,mode=max,scope=pd-app | |
| build-worker: | |
| name: Build Worker Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push Worker | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile.worker | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-worker:latest | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-worker:${{ github.sha }} | |
| cache-from: type=gha,scope=pd-worker | |
| cache-to: type=gha,mode=max,scope=pd-worker | |
| deploy: | |
| name: Signal Server to Pull | |
| runs-on: ubuntu-latest | |
| needs: [build-app, build-worker] | |
| steps: | |
| - name: SSH and deploy | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.ORACLE_HOST }} | |
| username: ubuntu | |
| port: 22 | |
| key: ${{ secrets.SSH_KEY }} | |
| script: | | |
| cd ~/PD-Server | |
| # Pull latest code | |
| git pull origin main | |
| cd ~/PD-Server/docker | |
| # Pull latest images from GHCR | |
| docker pull ghcr.io/pd-graduation-project/pd-server/pd-app:latest | |
| docker pull ghcr.io/pd-graduation-project/pd-server/pd-worker:latest | |
| # Tag for local use | |
| docker tag ghcr.io/pd-graduation-project/pd-server/pd-app:latest pd-server-app:local | |
| docker tag ghcr.io/pd-graduation-project/pd-server/pd-worker:latest pd-server-worker:local | |
| # Restart containers with new images (skip nginx - unchanged) | |
| docker compose --profile prod up -d --no-build app worker watchtower | |
| # Clean up old image layers | |
| docker image prune -f | |
| # Verify everything came up | |
| docker compose ps | |
| docker compose logs app --tail=20 |