Enhance Redis integration and update documentation #7
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: Deploy to GCP | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - "**.md" | |
| - "docs/**" | |
| - "terraform/docs/**" | |
| workflow_dispatch: | |
| env: | |
| REGION: asia-southeast2 | |
| SERVICE_NAME: portfolio-backend | |
| REPO_NAME: portfolio | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Authenticate to GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }} | |
| service_account: ${{ vars.GCP_DEPLOYER_SA }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Configure Docker for Artifact Registry | |
| run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet | |
| - name: Build and push image | |
| run: | | |
| IMAGE="${{ env.REGION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.SERVICE_NAME }}" | |
| docker build --platform linux/amd64 -t "${IMAGE}:${{ github.sha }}" -t "${IMAGE}:latest" . | |
| docker push "${IMAGE}:${{ github.sha }}" | |
| docker push "${IMAGE}:latest" | |
| echo "IMAGE_URI=${IMAGE}:${{ github.sha }}" >> "$GITHUB_ENV" | |
| - name: Deploy to Cloud Run | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: ${{ env.SERVICE_NAME }} | |
| region: ${{ env.REGION }} | |
| image: ${{ env.IMAGE_URI }} | |
| - name: Smoke test | |
| run: | | |
| URL=$(gcloud run services describe ${{ env.SERVICE_NAME }} \ | |
| --region=${{ env.REGION }} \ | |
| --format='value(status.url)') | |
| echo "Service URL: ${URL}" | |
| for i in 1 2 3 4 5; do | |
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${URL}/health" || true) | |
| if [ "$STATUS" = "200" ]; then | |
| echo "Health check passed" | |
| exit 0 | |
| fi | |
| echo "Attempt $i: status=$STATUS, retrying in 10s..." | |
| sleep 10 | |
| done | |
| echo "Health check failed after 5 attempts" | |
| exit 1 |