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 }} carrier-image: ${{ steps.carrier-meta.outputs.tags }} charging-image: ${{ steps.charging-meta.outputs.tags }} gateway-image: ${{ steps.gateway-meta.outputs.tags }} cli-image: ${{ steps.cli-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: . file: ./deployments/docker/api-server.Dockerfile push: true tags: ${{ steps.api-meta.outputs.tags }} labels: ${{ steps.api-meta.outputs.labels }} - name: Extract metadata (Carrier Connector) id: carrier-meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }}/carrier-connector tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix={{branch}}- - name: Build and push carrier connector uses: docker/build-push-action@v5 with: context: . file: ./deployments/docker/carrier-connector.Dockerfile push: true tags: ${{ steps.carrier-meta.outputs.tags }} labels: ${{ steps.carrier-meta.outputs.labels }} - name: Extract metadata (Charging Engine) id: charging-meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }}/charging-engine tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix={{branch}}- - name: Build and push charging engine uses: docker/build-push-action@v5 with: context: . file: ./deployments/docker/charging-engine.Dockerfile push: true tags: ${{ steps.charging-meta.outputs.tags }} labels: ${{ steps.charging-meta.outputs.labels }} - name: Extract metadata (Packet Gateway) id: gateway-meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }}/packet-gateway tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix={{branch}}- - name: Build and push packet gateway uses: docker/build-push-action@v5 with: context: . file: ./deployments/docker/packet-gateway.Dockerfile push: true tags: ${{ steps.gateway-meta.outputs.tags }} labels: ${{ steps.gateway-meta.outputs.labels }} - name: Extract metadata (CLI) id: cli-meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }}/cli tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix={{branch}}- - name: Build and push CLI uses: docker/build-push-action@v5 with: context: . file: ./deployments/docker/cli.Dockerfile push: true tags: ${{ steps.cli-meta.outputs.tags }} labels: ${{ steps.cli-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: . file: ./deployments/docker/web-dashboard.Dockerfile 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: Install goose run: go install github.com/pressly/goose/v3/cmd/goose@latest - name: Run database migrations run: | echo "Running database migrations for staging..." # goose postgres $DATABASE_URL up migrations echo "Staging migrations complete" - 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: Install goose run: go install github.com/pressly/goose/v3/cmd/goose@latest - name: Run database migrations run: | echo "Running database migrations for production..." # goose postgres $DATABASE_URL up migrations echo "Production migrations complete" - name: Deploy to production cluster run: | echo "Deploying to production..." # kubectl apply -f k8s/production/ echo "Production deployment complete"