|
| 1 | +name: Deploy to Production |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [docker] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + environment: |
| 9 | + description: "Deployment environment" |
| 10 | + required: true |
| 11 | + default: "production" |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - production |
| 15 | + - staging |
| 16 | + |
| 17 | +env: |
| 18 | + REGISTRY: ghcr.io |
| 19 | + IMAGE_NAME: ${{ github.repository }} |
| 20 | + |
| 21 | +jobs: |
| 22 | + deploy-staging: |
| 23 | + if: github.ref == 'refs/heads/docker' && (github.event.inputs.environment == 'staging' || github.event_name == 'push') |
| 24 | + runs-on: ubuntu-latest |
| 25 | + environment: staging |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Setup Node.js |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: "22.x" |
| 35 | + cache: "npm" |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: npm ci |
| 39 | + |
| 40 | + - name: Build for staging |
| 41 | + run: npm run build |
| 42 | + env: |
| 43 | + VITE_GEMINI_API_KEY: ${{ secrets.VITE_GEMINI_API_KEY_STAGING }} |
| 44 | + NODE_ENV: staging |
| 45 | + |
| 46 | + - name: Deploy to Vercel (Staging) |
| 47 | + uses: amondnet/vercel-action@v25 |
| 48 | + with: |
| 49 | + vercel-token: ${{ secrets.VERCEL_TOKEN }} |
| 50 | + vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} |
| 51 | + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} |
| 52 | + working-directory: ./ |
| 53 | + scope: ${{ secrets.VERCEL_ORG_ID }} |
| 54 | + |
| 55 | + - name: Comment PR with preview URL |
| 56 | + if: github.event_name == 'pull_request' |
| 57 | + uses: actions/github-script@v7 |
| 58 | + with: |
| 59 | + script: | |
| 60 | + github.rest.issues.createComment({ |
| 61 | + issue_number: context.issue.number, |
| 62 | + owner: context.repo.owner, |
| 63 | + repo: context.repo.repo, |
| 64 | + body: '🚀 Deployed to staging! Preview: https://vrt-games-staging.vercel.app' |
| 65 | + }) |
| 66 | +
|
| 67 | + deploy-production: |
| 68 | + if: github.ref == 'refs/heads/docker' && (github.event.inputs.environment == 'production' || github.event_name == 'push') |
| 69 | + runs-on: ubuntu-latest |
| 70 | + environment: production |
| 71 | + needs: [deploy-staging] |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Checkout code |
| 75 | + uses: actions/checkout@v4 |
| 76 | + |
| 77 | + - name: Setup Node.js |
| 78 | + uses: actions/setup-node@v4 |
| 79 | + with: |
| 80 | + node-version: "22.x" |
| 81 | + cache: "npm" |
| 82 | + |
| 83 | + - name: Install dependencies |
| 84 | + run: npm ci |
| 85 | + |
| 86 | + - name: Build for production |
| 87 | + run: npm run build |
| 88 | + env: |
| 89 | + VITE_GEMINI_API_KEY: ${{ secrets.VITE_GEMINI_API_KEY_PRODUCTION }} |
| 90 | + NODE_ENV: production |
| 91 | + |
| 92 | + - name: Deploy to Vercel (Production) |
| 93 | + uses: amondnet/vercel-action@v25 |
| 94 | + with: |
| 95 | + vercel-token: ${{ secrets.VERCEL_TOKEN }} |
| 96 | + vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} |
| 97 | + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} |
| 98 | + vercel-args: "--prod" |
| 99 | + working-directory: ./ |
| 100 | + scope: ${{ secrets.VERCEL_ORG_ID }} |
| 101 | + |
| 102 | + - name: Create GitHub Release |
| 103 | + if: github.event_name == 'push' |
| 104 | + uses: actions/create-release@v1 |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + with: |
| 108 | + tag_name: v${{ github.run_number }} |
| 109 | + release_name: Release v${{ github.run_number }} |
| 110 | + body: | |
| 111 | + 🎮 VRT Games Website - Production Release |
| 112 | +
|
| 113 | + **Changes in this release:** |
| 114 | + - ${{ github.event.head_commit.message }} |
| 115 | +
|
| 116 | + **Deployed to:** https://vrt-games.vercel.app |
| 117 | + **Commit:** ${{ github.sha }} |
| 118 | + draft: false |
| 119 | + prerelease: false |
| 120 | + |
| 121 | + docker-deploy: |
| 122 | + if: github.ref == 'refs/heads/docker' |
| 123 | + runs-on: ubuntu-latest |
| 124 | + environment: production |
| 125 | + |
| 126 | + steps: |
| 127 | + - name: Checkout code |
| 128 | + uses: actions/checkout@v4 |
| 129 | + |
| 130 | + - name: Set up Docker Buildx |
| 131 | + uses: docker/setup-buildx-action@v3 |
| 132 | + |
| 133 | + - name: Login to GitHub Container Registry |
| 134 | + uses: docker/login-action@v3 |
| 135 | + with: |
| 136 | + registry: ${{ env.REGISTRY }} |
| 137 | + username: ${{ github.actor }} |
| 138 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + |
| 140 | + - name: Extract metadata |
| 141 | + id: meta |
| 142 | + uses: docker/metadata-action@v5 |
| 143 | + with: |
| 144 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 145 | + tags: | |
| 146 | + type=ref,event=branch |
| 147 | + type=sha,prefix=prod-,suffix=-{{date 'YYYYMMDD'}} |
| 148 | + type=raw,value=latest |
| 149 | +
|
| 150 | + - name: Build and push production Docker image |
| 151 | + uses: docker/build-push-action@v5 |
| 152 | + with: |
| 153 | + context: . |
| 154 | + push: true |
| 155 | + tags: ${{ steps.meta.outputs.tags }} |
| 156 | + labels: ${{ steps.meta.outputs.labels }} |
| 157 | + build-args: | |
| 158 | + VITE_GEMINI_API_KEY=${{ secrets.VITE_GEMINI_API_KEY_PRODUCTION }} |
| 159 | + cache-from: type=gha |
| 160 | + cache-to: type=gha,mode=max |
| 161 | + |
| 162 | + notify-deployment: |
| 163 | + runs-on: ubuntu-latest |
| 164 | + needs: [deploy-production, docker-deploy] |
| 165 | + if: always() |
| 166 | + |
| 167 | + steps: |
| 168 | + - name: Notify deployment status |
| 169 | + uses: 8398a7/action-slack@v3 |
| 170 | + if: always() |
| 171 | + with: |
| 172 | + status: ${{ job.status }} |
| 173 | + channel: "#deployments" |
| 174 | + webhook_url: ${{ secrets.SLACK_WEBHOOK }} |
| 175 | + text: | |
| 176 | + 🎮 VRT Games Website deployment completed! |
| 177 | + Status: ${{ job.status }} |
| 178 | + Environment: Production |
| 179 | + Commit: ${{ github.sha }} |
| 180 | + Author: ${{ github.actor }} |
0 commit comments