From e0507e673cae5918f51f7cbc03bd2ade73b629a2 Mon Sep 17 00:00:00 2001 From: Kunwar Toor Date: Mon, 3 Aug 2020 10:47:03 -0700 Subject: [PATCH 1/6] updated google.yml to reflect the more recent gke workflow action given by google in https://github.com/GoogleCloudPlatform/github-actions --- ci/google.yml | 67 +++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/ci/google.yml b/ci/google.yml index b8d1079..b9d6e74 100644 --- a/ci/google.yml +++ b/ci/google.yml @@ -7,69 +7,72 @@ # 2. Set up secrets in your workspace: GKE_PROJECT with the name of the project, GKE_EMAIL with the service account email, GKE_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs). # # 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, REGISTRY_HOSTNAME and DEPLOYMENT_NAME environment variables (below). +# +# For more support on how to run the workflow, please visit https://github.com/GoogleCloudPlatform/github-actions/tree/master/example-workflows/gke name: Build and Deploy to GKE on: - release: - types: [created] + push: + branches: + - master -# Environment variables available to all jobs and steps in this workflow env: - GKE_PROJECT: ${{ secrets.GKE_PROJECT }} - GKE_EMAIL: ${{ secrets.GKE_EMAIL }} - GITHUB_SHA: ${{ github.sha }} - GKE_ZONE: us-west1-a - GKE_CLUSTER: example-gke-cluster - IMAGE: gke-test - REGISTRY_HOSTNAME: gcr.io - DEPLOYMENT_NAME: gke-test + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + GKE_CLUSTER: cluster-1 # TODO: update to cluster name + GKE_ZONE: us-central1-c # TODO: update to cluster zone + DEPLOYMENT_NAME: gke-test # TODO: update to deployment name + IMAGE: static-site jobs: setup-build-publish-deploy: name: Setup, Build, Publish, and Deploy runs-on: ubuntu-latest - steps: + steps: - name: Checkout uses: actions/checkout@v2 # Setup gcloud CLI - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master with: - version: '270.0.0' - service_account_email: ${{ secrets.GKE_EMAIL }} - service_account_key: ${{ secrets.GKE_KEY }} + version: '290.0.1' + service_account_key: ${{ secrets.GKE_SA_KEY }} + project_id: ${{ secrets.GKE_PROJECT }} + + # Configure Docker to use the gcloud command-line tool as a credential + # helper for authentication + - run: |- + gcloud --quiet auth configure-docker + + # Get the GKE credentials so we can deploy to the cluster + - run: |- + gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE" - # Configure docker to use the gcloud command-line tool as a credential helper - - run: | - # Set up docker to authenticate - # via gcloud command-line tool. - gcloud auth configure-docker - # Build the Docker image - name: Build - run: | - docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE":"$GITHUB_SHA" \ + run: |- + docker build \ + --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \ --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" . + --build-arg GITHUB_REF="$GITHUB_REF" \ + . # Push the Docker image to Google Container Registry - name: Publish - run: | - docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:$GITHUB_SHA - + run: |- + docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" + # Set up kustomize - name: Set up Kustomize - run: | - curl -o kustomize --location https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 + run: |- + curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 chmod u+x ./kustomize # Deploy the Docker image to the GKE cluster - name: Deploy - run: | - gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT - ./kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA} + run: |- + ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA ./kustomize build . | kubectl apply -f - kubectl rollout status deployment/$DEPLOYMENT_NAME kubectl get services -o wide From 96d4d9913c1959f40e92c5af3549f90cf8cb6e26 Mon Sep 17 00:00:00 2001 From: Kunwar Toor Date: Mon, 3 Aug 2020 10:55:35 -0700 Subject: [PATCH 2/6] updated google.yml to reflect the more recent gke workflow action given by google in https://github.com/GoogleCloudPlatform/github-actions --- ci/google.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/google.yml b/ci/google.yml index b9d6e74..dc37de4 100644 --- a/ci/google.yml +++ b/ci/google.yml @@ -13,9 +13,8 @@ name: Build and Deploy to GKE on: - push: - branches: - - master + release: + types: [created] env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} From 27c4cec0db5be1cbd9d926b157b9319a2c76137e Mon Sep 17 00:00:00 2001 From: ktoor-google <69051209+ktoor-google@users.noreply.github.com> Date: Mon, 10 Aug 2020 16:42:41 -0700 Subject: [PATCH 3/6] Update ci/google.yml Co-authored-by: John Bohannon --- ci/google.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/google.yml b/ci/google.yml index dc37de4..fb29666 100644 --- a/ci/google.yml +++ b/ci/google.yml @@ -4,7 +4,7 @@ # # 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. # -# 2. Set up secrets in your workspace: GKE_PROJECT with the name of the project, GKE_EMAIL with the service account email, GKE_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs). +# 2. Set up secrets in your workspace: GKE_PROJECT with the name of the project and GKE_SA_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs). # # 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, REGISTRY_HOSTNAME and DEPLOYMENT_NAME environment variables (below). # From 0ec52ad66b01f8b0a4e9f22cc71cfab60e70e106 Mon Sep 17 00:00:00 2001 From: ktoor-google <69051209+ktoor-google@users.noreply.github.com> Date: Mon, 10 Aug 2020 16:43:03 -0700 Subject: [PATCH 4/6] Update ci/google.yml Co-authored-by: John Bohannon --- ci/google.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/google.yml b/ci/google.yml index fb29666..cfbbddb 100644 --- a/ci/google.yml +++ b/ci/google.yml @@ -6,7 +6,7 @@ # # 2. Set up secrets in your workspace: GKE_PROJECT with the name of the project and GKE_SA_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs). # -# 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, REGISTRY_HOSTNAME and DEPLOYMENT_NAME environment variables (below). +# 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, and DEPLOYMENT_NAME environment variables (below). # # For more support on how to run the workflow, please visit https://github.com/GoogleCloudPlatform/github-actions/tree/master/example-workflows/gke From ee064c5e4b6c2ff11f25d79ea68d7db195fccf46 Mon Sep 17 00:00:00 2001 From: Kunwar Toor Date: Mon, 10 Aug 2020 17:07:34 -0700 Subject: [PATCH 5/6] updated gcloud action to latest --- ci/google.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/google.yml b/ci/google.yml index cfbbddb..aaaf6db 100644 --- a/ci/google.yml +++ b/ci/google.yml @@ -35,7 +35,6 @@ jobs: # Setup gcloud CLI - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master with: - version: '290.0.1' service_account_key: ${{ secrets.GKE_SA_KEY }} project_id: ${{ secrets.GKE_PROJECT }} From bfe353443a94ed8fb57751d2934b5c3c2f4bd61b Mon Sep 17 00:00:00 2001 From: ktoor-google <69051209+ktoor-google@users.noreply.github.com> Date: Thu, 13 Aug 2020 11:52:11 -0700 Subject: [PATCH 6/6] Update ci/google.yml Co-authored-by: John Bohannon --- ci/google.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/google.yml b/ci/google.yml index aaaf6db..b9313b2 100644 --- a/ci/google.yml +++ b/ci/google.yml @@ -33,7 +33,7 @@ jobs: uses: actions/checkout@v2 # Setup gcloud CLI - - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master + - uses: GoogleCloudPlatform/github-actions/setup-gcloud@0.1.3 with: service_account_key: ${{ secrets.GKE_SA_KEY }} project_id: ${{ secrets.GKE_PROJECT }}