|
| 1 | +name: Build, Publish, and Deploy Docker Image (Production) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + ORG: ctrlaltelite-devs |
| 11 | + IMAGE: embedding.worker.faculytics |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-deploy: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + # Deployment Started |
| 19 | + - name: Deployment started notification |
| 20 | + env: |
| 21 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }} |
| 22 | + DISCORD_USERNAME: "CaseOh" |
| 23 | + DISCORD_AVATAR: "https://yt3.googleusercontent.com/QL_kksdOZPCOmFsGyHMVVcGgf9fBtyMGBZSwsNfSxqLKE9z5Lmp8fCGCHMFM7JGpgW38juJPvQ=s900-c-k-c0x00ffffff-no-rj" |
| 24 | + uses: Ilshidur/action-discord@0.4.0 |
| 25 | + with: |
| 26 | + args: "CHAT! CHAT! si ${{github.actor}} kay nag deploy sa Embedding Worker to PRODUCTION 🍔 Hold up hold up, tabangan nato ni siya mga dawg 🙏" |
| 27 | + |
| 28 | + # 1️⃣ Checkout repository |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + # 2️⃣ Set up Docker Buildx |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@v3 |
| 35 | + |
| 36 | + # 3️⃣ Log in to GHCR |
| 37 | + - name: Log in to GitHub Container Registry |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ secrets.GH_USERNAME }} |
| 42 | + password: ${{ secrets.GH_PAT }} |
| 43 | + |
| 44 | + # 4️⃣ Build and push Docker image (with layer caching) |
| 45 | + - name: Build and push Docker image |
| 46 | + uses: docker/build-push-action@v6 |
| 47 | + with: |
| 48 | + context: . |
| 49 | + push: true |
| 50 | + tags: | |
| 51 | + ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }}:latest |
| 52 | + ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }}:${{ github.sha }} |
| 53 | + cache-from: type=gha |
| 54 | + cache-to: type=gha,mode=max |
| 55 | + |
| 56 | + # 5️⃣ Deploy to VPS via SSH (pull pre-built image) |
| 57 | + - name: Deploy to Production VPS |
| 58 | + uses: appleboy/ssh-action@v1.0.3 |
| 59 | + with: |
| 60 | + host: ${{ secrets.VPS_HOST }} |
| 61 | + username: ${{ secrets.VPS_PROD_USERNAME }} |
| 62 | + key: ${{ secrets.VPS_SSH_KEY }} |
| 63 | + script: | |
| 64 | + docker login ghcr.io -u ${{ secrets.GH_USERNAME }} -p ${{ secrets.GH_PAT }} |
| 65 | + docker pull ghcr.io/ctrlaltelite-devs/embedding.worker.faculytics:latest |
| 66 | + cd ~/deployments/faculytics/embedding-worker && docker compose -f docker-compose.prod.yml up -d |
| 67 | +
|
| 68 | + # Deployment failed |
| 69 | + - name: Failed deployment notification |
| 70 | + if: failure() |
| 71 | + env: |
| 72 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }} |
| 73 | + DISCORD_USERNAME: "CaseOh" |
| 74 | + DISCORD_AVATAR: "https://yt3.googleusercontent.com/QL_kksdOZPCOmFsGyHMVVcGgf9fBtyMGBZSwsNfSxqLKE9z5Lmp8fCGCHMFM7JGpgW38juJPvQ=s900-c-k-c0x00ffffff-no-rj" |
| 75 | + uses: Ilshidur/action-discord@0.4.0 |
| 76 | + with: |
| 77 | + args: "NAH BRO NAH 💀 ang Embedding Worker deployment ni ${{github.actor}} naguba BWAHAHAHAHA what is this chat??" |
| 78 | + |
| 79 | + # Deployment succeeded |
| 80 | + - name: Successful deployment notification |
| 81 | + if: success() |
| 82 | + env: |
| 83 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }} |
| 84 | + DISCORD_USERNAME: "CaseOh" |
| 85 | + DISCORD_AVATAR: "https://yt3.googleusercontent.com/QL_kksdOZPCOmFsGyHMVVcGgf9fBtyMGBZSwsNfSxqLKE9z5Lmp8fCGCHMFM7JGpgW38juJPvQ=s900-c-k-c0x00ffffff-no-rj" |
| 86 | + uses: Ilshidur/action-discord@0.4.0 |
| 87 | + with: |
| 88 | + args: "WWWWW Embedding Worker deployment to Production successful ✅🍔 nice ka dawg ${{github.actor}}, that's a dub chat!!" |
0 commit comments