added networking and academy pages #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Deploy to Cloud Run | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| # Required GitHub Secrets (configure in repo settings): | |
| # - GCP_SA_KEY: JSON service account key with roles/artifactregistry.admin and roles/run.admin | |
| # - GCP_PROJECT_ID: GCP Project ID | |
| # - GCP_REGION: e.g. us-central1 | |
| # - GAR_REPOSITORY: Artifact Registry repo name (e.g., pitchlense) | |
| # - CLOUD_RUN_SERVICE: Cloud Run service name (e.g., pitchlense-backend) | |
| env: | |
| PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
| REGION: ${{ secrets.GCP_REGION }} | |
| REPOSITORY: ${{ secrets.GAR_REPOSITORY }} | |
| SERVICE_NAME: ${{ secrets.CLOUD_RUN_SERVICE }} | |
| jobs: | |
| build-and-deploy: | |
| name: Build, Push, Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Authenticate to Google Cloud | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| project_id: ${{ env.PROJECT_ID }} | |
| - name: Setup gcloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| with: | |
| project_id: ${{ env.PROJECT_ID }} | |
| - name: Configure Docker for Artifact Registry | |
| run: gcloud auth configure-docker "${{ env.REGION }}-docker.pkg.dev" --quiet | |
| - name: Build Docker image | |
| run: | | |
| IMAGE_URI="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" | |
| LATEST_URI="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:latest" | |
| echo "IMAGE_URI=$IMAGE_URI" >> $GITHUB_ENV | |
| echo "LATEST_URI=$LATEST_URI" >> $GITHUB_ENV | |
| docker build -t "$IMAGE_URI" -t "$LATEST_URI" . | |
| - name: Push image to Artifact Registry | |
| run: | | |
| docker push "$IMAGE_URI" | |
| docker push "$LATEST_URI" | |
| - name: Deploy to Cloud Run | |
| run: | | |
| ENV_FILE=".env" | |
| SET_ENV_FLAG="--set-env-vars NODE_ENV=production" | |
| if [ -f "$ENV_FILE" ]; then | |
| # Build a comma-separated KEY=VALUE list from .env | |
| # - drop comments/blank lines | |
| # - strip leading 'export ' | |
| # - remove CR from CRLF | |
| # - escape commas in values for gcloud | |
| ENV_VARS=$(grep -v '^[# ]' "$ENV_FILE" | sed '/^$/d' | tr -d '\r' | sed 's/^export \+//' | sed 's/,/\\,/g' | paste -sd, -) | |
| if [ -n "$ENV_VARS" ]; then | |
| # Ensure NODE_ENV=production is present | |
| case ",$ENV_VARS," in | |
| *,NODE_ENV=*) : ;; | |
| *) ENV_VARS="$ENV_VARS,NODE_ENV=production" ;; | |
| esac | |
| SET_ENV_FLAG="--set-env-vars $ENV_VARS" | |
| fi | |
| fi | |
| gcloud run deploy "$SERVICE_NAME" \ | |
| --image "$IMAGE_URI" \ | |
| --region "$REGION" \ | |
| --platform managed \ | |
| --allow-unauthenticated \ | |
| --port 80 \ | |
| --quiet | |