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