build: add github action for deploy to GCP #2
This file contains 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: CI/CD | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: "read" | |
id-token: "write" | |
env: | |
IMAGE_NAME: gcr.io/${{secrets.PROJECT_ID}}/ai-recipe-generator | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: ${{secrets.WORKLOAD_IDENTITY_PROVIDER_LOCATION}} | |
service_account: ${{secrets.SERVICE_ACCOUNT}} | |
- name: Configure Docker | |
run: gcloud auth configure-docker --quiet | |
- name: Build Docker image | |
run: docker build . -t $IMAGE_NAME --cache-from $IMAGE_NAME | |
- name: Push Docker image | |
run: docker push $IMAGE_NAME | |
- id: deploy | |
name: Deploy Docker image | |
uses: "google-github-actions/deploy-cloudrun@v2" | |
with: | |
image: ${{ env.IMAGE_NAME }} | |
region: asia-east1 | |
service: ai-recipe-generator | |
flags: --port=8501 | |
- name: Test URL | |
run: curl "${{ steps.deploy.outputs.url }}" |