From 1bd95f5e7e4e147f09589393f7f8d8a515b073b4 Mon Sep 17 00:00:00 2001 From: Andrew Marcuse Date: Sun, 8 Sep 2024 15:13:09 -0400 Subject: [PATCH] UPDATE: GHA to deploy to CloudRun --- .github/workflows/gcr-deploy.yaml | 64 +++++++++++++++++++++++++++++++ README.md | 5 ++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/gcr-deploy.yaml diff --git a/.github/workflows/gcr-deploy.yaml b/.github/workflows/gcr-deploy.yaml new file mode 100644 index 0000000..d12fd68 --- /dev/null +++ b/.github/workflows/gcr-deploy.yaml @@ -0,0 +1,64 @@ +name: deploy + +on: + push: + branches: + - main + + workflow_dispatch: + +# Environment variables available to all jobs and steps in this workflow +# NOTE: these aren't really secret, but there aren't non-secret settings +env: + RUN_PROJECT: ${{ secrets.RUN_PROJECT }} + RUN_REGION: ${{ secrets.RUN_REGION }} + RUN_SERVICE: ${{ secrets.RUN_SERVICE }} + +jobs: + deploy: + name: Deploy to CloudRun + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: gcloud auth + id: 'auth' + uses: 'google-github-actions/auth@v0' + with: + credentials_json: '${{ secrets.GCP_SA_KEY }}' + + # Setup gcloud CLI + - name: gcloud setup + uses: google-github-actions/setup-gcloud@v0 + + - name: gcloud docker-auth + run: gcloud auth configure-docker + + # Build and push image to Google Container Registry + - name: Build + run: | + docker build \ + --build-arg COMMIT=${GITHUB_SHA:0:7} \ + --build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \ + --tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \ + . + + - name: GCloud auth to docker + run: | + gcloud auth configure-docker + + - name: Push to registry + run: | + docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA + + # Deploy image to Cloud Run + - name: Deploy + run: | + gcloud run deploy ${RUN_SERVICE} \ + --allow-unauthenticated \ + --image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \ + --platform managed \ + --project ${RUN_PROJECT} \ + --region ${RUN_REGION} diff --git a/README.md b/README.md index a82a590..07e4949 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,12 @@ LATER ## Credits [![Google CloudRun](https://www.vectorlogo.zone/logos/google_cloud_run/google_cloud_run-ar21.svg)](https://cloud.google.com/run/ "Hosting") +[![Docker](https://www.vectorlogo.zone/logos/docker/docker-ar21.svg)](https://www.docker.com/ "Deployment") [![Git](https://www.vectorlogo.zone/logos/git-scm/git-scm-ar21.svg)](https://git-scm.com/ "Version control") [![Github](https://www.vectorlogo.zone/logos/github/github-ar21.svg)](https://github.com/ "Code hosting") -[![Google Noto Emoji](https://www.vectorlogo.zone/logos/google/google-ar21.svg)](https://github.com/googlefonts/noto-emoji/blob/master/svg/emoji_u1f441.svg "Logo/Favicon")[![NodePing](https://www.vectorlogo.zone/logos/nodeping/nodeping-ar21.svg)](https://nodeping.com?rid=201109281250J5K3P "Uptime monitoring") +[![Google Noto Emoji](https://www.vectorlogo.zone/logos/google/google-ar21.svg)](https://github.com/googlefonts/noto-emoji/blob/master/svg/emoji_u1f441.svg "Logo/Favicon") +[![Node.js](https://www.vectorlogo.zone/logos/nodejs/nodejs-ar21.svg)](https://nodejs.org/ "Application Server") +[![NodePing](https://www.vectorlogo.zone/logos/nodeping/nodeping-ar21.svg)](https://nodeping.com?rid=201109281250J5K3P "Uptime monitoring") [![npm](https://www.vectorlogo.zone/logos/npmjs/npmjs-ar21.svg)](https://www.npmjs.com/ "JS Package Management") [![Phosphor Icons](https://www.vectorlogo.zone/logos/phosphoricons/phosphoricons-ar21.svg)](https://phosphoricons.com/ "Toolbar icons") [![react.js](https://www.vectorlogo.zone/logos/reactjs/reactjs-ar21.svg)](https://reactjs.org/ "UI Framework")