Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Cloud Run deployment workflow to GitHub actions #53

Open
satazor opened this issue Jan 9, 2020 · 1 comment
Open

Add a Cloud Run deployment workflow to GitHub actions #53

satazor opened this issue Jan 9, 2020 · 1 comment

Comments

@satazor
Copy link
Collaborator

satazor commented Jan 9, 2020

#51 added CI & CD (with Zeit's Now).

However, we are not actually deploying with Docker. So ideally, we would have one workflow with a deployment on Cloud Run.

@satazor satazor changed the title Add a Cloud Run deployment workflow GitHub actions Add a Cloud Run deployment workflow to GitHub actions Jan 10, 2020
@0xjjpa
Copy link

0xjjpa commented Jan 31, 2020

@satazor We actually are deploying w/Cloud Run. Our setup is with GitLab, but I'm sure it's easy enough to port with a similar alternative (e.g. CircleCI). Thought it might help you, so here it is:

services:
  - docker:dind

stages:
  - package
  - deploy

variables:
  GCP_PROJECT: gcp-project
  GCP_SERVICE: cloud-run-service
  GCP_REGISTRY: gcr.io/$GCP_PROJECT
  GCP_CLOUD_RUN_PROJECT: $GCP_SERVICE
  PACKAGE_CONTAINER_BUILD_IMAGE: $GCP_REGISTRY/$GCP_SERVICE:build-$CI_COMMIT_REF_SLUG
  URL_PROJECT: https://url

# Multiline Scripts
.deploy-cloud-run: &deploy-cloud-run |
  gcloud run deploy $GCP_CLOUD_RUN_PROJECT --image $PACKAGE_CONTAINER_BUILD_IMAGE \
  --set-env-vars=SECRET=$SECRET,\
  ANOTHER_SECRET=$ANOTHER_SECRET,\
  --platform managed --allow-unauthenticated --region europe-west1

# Scripts to be executed before all tasks
before_script:
  - mkdir -p $HOME/.docker
  - echo "$GITLAB_SERVICE_ACCOUNT_KEY_JSON" >> "$HOME/.docker/config.json"
  - echo "$CLOUD_RUN_SERVICE_ACCOUNT_KEY_JSON" >> "$HOME/google-cloud-run.json"

package:
  stage: package
  image: docker:latest
  script:
    - docker login -u _json_key --password-stdin https://gcr.io < $HOME/.docker/config.json
    - docker build --pull . -t $PACKAGE_CONTAINER_BUILD_IMAGE --cache-from $PACKAGE_CONTAINER_BUILD_IMAGE
    - docker push $PACKAGE_CONTAINER_BUILD_IMAGE

deploy:
  environment:
    name: $GCP_SERVICE
    url: $URL_PROJECT
  stage: deploy
  image: google/cloud-sdk:latest
  script:
    - gcloud auth activate-service-account --key-file=$HOME/google-cloud-run.json
    - gcloud config set project $GCP_PROJECT
    - *deploy-cloud-run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants