From 87d71b06743ad58a3f1a7e4e9dc7f0446f5dffba Mon Sep 17 00:00:00 2001 From: Sourav Chandhok <114119117+souravC01@users.noreply.github.com> Date: Wed, 16 Sep 2026 14:56:10 -0400 Subject: [PATCH] Add automatic Cloud Run backend deployment --- .github/workflows/ci.yml | 81 ++++++++++++++++++++++++++++++++++++++++ backend/.gitignore | 1 + 2 files changed, 82 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95d49a8..c274c2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,3 +44,84 @@ jobs: run: npm test - name: Build frontend run: npm run build + + deploy-backend: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: backend + runs-on: ubuntu-latest + + permissions: + contents: read + id-token: write + + env: + PROJECT_ID: roleimpact + REGION: us-west1 + SERVICE: roleimpact-api + AR_REPO: cloud-run-source-deploy + IMAGE_NAME: roleimpact-api + + steps: + - name: Check out repository + uses: actions/checkout@v7 + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v3 + with: + project_id: roleimpact + workload_identity_provider: projects/772739041868/locations/global/workloadIdentityPools/github-pool/providers/github-provider + service_account: roleimpact-github-deployer@roleimpact.iam.gserviceaccount.com + + - name: Set up Google Cloud SDK + uses: google-github-actions/setup-gcloud@v3 + with: + project_id: roleimpact + + - name: Configure Artifact Registry authentication + run: | + gcloud auth configure-docker "${REGION}-docker.pkg.dev" --quiet + + - name: Build backend image + run: | + IMAGE="${REGION}-docker.pkg.dev/${PROJECT_ID}/${AR_REPO}/${IMAGE_NAME}:${GITHUB_SHA}" + docker build \ + --file backend/Dockerfile \ + --tag "$IMAGE" \ + backend + echo "IMAGE=$IMAGE" >> "$GITHUB_ENV" + + - name: Push backend image + run: | + docker push "$IMAGE" + + - name: Deploy backend to Cloud Run + run: | + gcloud run services update "$SERVICE" \ + --project="$PROJECT_ID" \ + --region="$REGION" \ + --image="$IMAGE" \ + --quiet + + - name: Verify deployed backend + run: | + SERVICE_URL="$(gcloud run services describe "$SERVICE" \ + --project="$PROJECT_ID" \ + --region="$REGION" \ + --format='value(status.url)')" + + echo "Checking ${SERVICE_URL}/api/v1/health" + + for attempt in 1 2 3 4 5; do + if curl --fail --silent --show-error \ + "${SERVICE_URL}/api/v1/health"; then + echo + echo "Backend health check passed." + exit 0 + fi + + echo "Health check attempt ${attempt} failed. Retrying..." + sleep 5 + done + + echo "Backend health check failed." + exit 1 diff --git a/backend/.gitignore b/backend/.gitignore index 667aaef..7c6357e 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -3,6 +3,7 @@ target/ .mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ +gha-creds-*.json ### STS ### .apt_generated