From bf0447b905f71b5e5bf8c04875077a2171a76ebc Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Mon, 20 Apr 2026 20:11:13 +0300 Subject: [PATCH] feat: Add GitHub Actions deployment workflow with staging/production environments and container registry integration - Add deploy workflow triggered on push to main, version tags, and manual workflow_dispatch with environment selection - Add build-and-push job with GHCR login, Docker metadata extraction for API server/web dashboard, image builds with branch/tag/sha tagging, and image outputs - Add deploy-staging job (main branch or manual staging selection) with kubectl setup and placeholder deployment commands --- .github/workflows/deploy.yml | 116 +++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..895dce5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,116 @@ +name: Deploy + +on: + push: + branches: [main] + tags: + - 'v*' + workflow_dispatch: + inputs: + environment: + description: 'Deployment environment' + required: true + default: 'staging' + type: choice + options: + - staging + - production + +jobs: + build-and-push: + name: Build & Push Images + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + outputs: + api-image: ${{ steps.api-meta.outputs.tags }} + dashboard-image: ${{ steps.dashboard-meta.outputs.tags }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (API Server) + id: api-meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }}/api-server + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha,prefix={{branch}}- + + - name: Build and push API server + uses: docker/build-push-action@v5 + with: + context: ./apps/api-server + push: true + tags: ${{ steps.api-meta.outputs.tags }} + labels: ${{ steps.api-meta.outputs.labels }} + + - name: Extract metadata (Dashboard) + id: dashboard-meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }}/web-dashboard + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha,prefix={{branch}}- + + - name: Build and push web dashboard + uses: docker/build-push-action@v5 + with: + context: ./apps/web-dashboard + push: true + tags: ${{ steps.dashboard-meta.outputs.tags }} + labels: ${{ steps.dashboard-meta.outputs.labels }} + + deploy-staging: + name: Deploy to Staging + runs-on: ubuntu-latest + needs: build-and-push + if: github.ref == 'refs/heads/main' || github.event.inputs.environment == 'staging' + environment: staging + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup kubectl + uses: azure/setup-kubectl@v4 + with: + version: 'latest' + + - name: Deploy to staging cluster + run: | + echo "Deploying to staging..." + # kubectl apply -f k8s/staging/ + echo "Staging deployment complete" + + deploy-production: + name: Deploy to Production + runs-on: ubuntu-latest + needs: build-and-push + if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.environment == 'production' + environment: production + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup kubectl + uses: azure/setup-kubectl@v4 + with: + version: 'latest' + + - name: Deploy to production cluster + run: | + echo "Deploying to production..." + # kubectl apply -f k8s/production/ + echo "Production deployment complete"