From 29e140e47ea253ce04758aa5edd2d5ed8aa54af9 Mon Sep 17 00:00:00 2001 From: will Date: Sun, 25 Feb 2024 06:46:25 +0800 Subject: [PATCH] build: add github action for deploy to GCP --- .github/workflows/deploy.yml | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..0a37e49 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,51 @@ +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 }}" \ No newline at end of file