name: Deploy on: push: branches: [main] concurrency: group: deploy-production cancel-in-progress: false jobs: build-and-push: name: Build & Push Image runs-on: ubuntu-latest permissions: contents: read packages: write outputs: image_tag: ${{ steps.meta.outputs.version }} steps: - uses: actions/checkout@v4 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/shumiland tags: | type=sha,prefix=sha-,format=short type=raw,value=latest - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push uses: docker/build-push-action@v6 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max deploy: name: Deploy to VPS runs-on: ubuntu-latest needs: build-and-push environment: production steps: - name: Deploy via SSH uses: appleboy/ssh-action@v1 with: host: ${{ secrets.VPS_HOST }} username: ${{ secrets.VPS_USER }} key: ${{ secrets.VPS_SSH_KEY }} envs: IMAGE_TAG script: | cd /opt/shumiland TAG="$IMAGE_TAG" docker compose -f docker-compose.prod.yml pull app TAG="$IMAGE_TAG" docker compose -f docker-compose.prod.yml up -d --no-deps app docker system prune -f --filter "until=24h" env: IMAGE_TAG: ${{ needs.build-and-push.outputs.image_tag }} - name: Health check uses: appleboy/ssh-action@v1 with: host: ${{ secrets.VPS_HOST }} username: ${{ secrets.VPS_USER }} key: ${{ secrets.VPS_SSH_KEY }} script: | sleep 10 curl -sf http://localhost:3000/api/health || exit 1