Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
gha-creds-*.json

### STS ###
.apt_generated
Expand Down
Loading