Deploy API to Cloud Run #21
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 API to Cloud Run | |
| on: | |
| # workflow_run: | |
| # workflows: ["Rust CI"] | |
| # types: | |
| # - completed | |
| # branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "Branch to deploy" | |
| required: true | |
| default: "main" | |
| env: | |
| REGION: europe-west4 | |
| SERVICE_NAME: flatcitybuf-api | |
| GAR_LOCATION: europe-west4 | |
| GAR_REPOSITORY: flatcitybuf-api | |
| jobs: | |
| build-and-push: | |
| name: Build and Push Docker Image | |
| runs-on: ubuntu-latest | |
| # if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| # defaults: | |
| # run: | |
| # working-directory: src/rust | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Google Auth | |
| id: auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ secrets.WIF_PROVIDER }} | |
| project_id: ${{ secrets.PROJECT_ID }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Configure Docker for Artifact Registry | |
| run: gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev | |
| # - name: Extract metadata | |
| # id: meta | |
| # uses: docker/metadata-action@v5 | |
| # with: | |
| # images: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }} | |
| # tags: | | |
| # type=ref,event=branch | |
| # type=ref,event=pr | |
| # type=sha | |
| # type=raw,value=latest,enable={{is_default_branch}} | |
| - name: "Build and push container" | |
| run: |- | |
| docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" ./src/rust | |
| docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" | |
| # - name: Build and push Docker image | |
| # uses: docker/build-push-action@v5 | |
| # with: | |
| # context: . | |
| # file: src/rust/Dockerfile | |
| # push: true | |
| # tags: ${{ steps.meta.outputs.tags }} | |
| # labels: ${{ steps.meta.outputs.labels }} | |
| # cache-from: type=gha | |
| # cache-to: type=gha,mode=max | |
| deploy: | |
| name: Deploy to Cloud Run | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Google Auth | |
| id: auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ secrets.WIF_PROVIDER }} | |
| project_id: ${{ secrets.PROJECT_ID }} | |
| - name: Deploy to Cloud Run | |
| id: deploy | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: ${{ env.SERVICE_NAME }} | |
| region: ${{ env.REGION }} | |
| image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:latest | |
| flags: | | |
| --port=8080 | |
| --allow-unauthenticated | |
| --min-instances=0 | |
| --max-instances=3 | |
| --cpu=1 | |
| --memory=256Mi | |
| --timeout=300 | |
| - name: Show Output | |
| run: echo ${{ steps.deploy.outputs.url }} |