diff --git a/content/actions/guides/deploying-to-google-kubernetes-engine.md b/content/actions/guides/deploying-to-google-kubernetes-engine.md index 951335cc35..451596561c 100644 --- a/content/actions/guides/deploying-to-google-kubernetes-engine.md +++ b/content/actions/guides/deploying-to-google-kubernetes-engine.md @@ -91,16 +91,12 @@ on: release: types: [created] -# 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: @@ -112,38 +108,46 @@ jobs: uses: actions/checkout@v2 # Setup gcloud CLI - - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master + - uses: google-github-actions/setup-gcloud@v0.2.0 with: - service_account_email: ${{ secrets.GKE_EMAIL }} - service_account_key: ${{ secrets.GKE_KEY }} + 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 - - run: | - # Set up docker to authenticate - # via gcloud command-line tool. - gcloud auth configure-docker + - run: |- + gcloud --quiet auth configure-docker + # Get the GKE credentials so we can deploy to the cluster + - uses: google-github-actions/get-gke-credentials@v0.2.1 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GKE_SA_KEY }} + # 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" \ + . # 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