updated google.yml to reflect the more recent gke workflow action given by google in https://github.com/GoogleCloudPlatform/github-actions

This commit is contained in:
Kunwar Toor
2020-08-03 10:47:03 -07:00
parent 948df6a3d0
commit e0507e673c
+33 -30
View File
@@ -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). # 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). # 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 name: Build and Deploy to GKE
on: on:
release: push:
types: [created] branches:
- master
# Environment variables available to all jobs and steps in this workflow
env: env:
GKE_PROJECT: ${{ secrets.GKE_PROJECT }} PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_EMAIL: ${{ secrets.GKE_EMAIL }} GKE_CLUSTER: cluster-1 # TODO: update to cluster name
GITHUB_SHA: ${{ github.sha }} GKE_ZONE: us-central1-c # TODO: update to cluster zone
GKE_ZONE: us-west1-a DEPLOYMENT_NAME: gke-test # TODO: update to deployment name
GKE_CLUSTER: example-gke-cluster IMAGE: static-site
IMAGE: gke-test
REGISTRY_HOSTNAME: gcr.io
DEPLOYMENT_NAME: gke-test
jobs: jobs:
setup-build-publish-deploy: setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps:
steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
# Setup gcloud CLI # Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with: with:
version: '270.0.0' version: '290.0.1'
service_account_email: ${{ secrets.GKE_EMAIL }} service_account_key: ${{ secrets.GKE_SA_KEY }}
service_account_key: ${{ secrets.GKE_KEY }} project_id: ${{ secrets.GKE_PROJECT }}
# Configure docker to use the gcloud command-line tool as a credential helper # Configure Docker to use the gcloud command-line tool as a credential
- run: | # helper for authentication
# Set up docker to authenticate - run: |-
# via gcloud command-line tool. gcloud --quiet auth configure-docker
gcloud 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"
# Build the Docker image # Build the Docker image
- name: Build - name: Build
run: | run: |-
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE":"$GITHUB_SHA" \ docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
--build-arg GITHUB_SHA="$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 # Push the Docker image to Google Container Registry
- name: Publish - name: Publish
run: | run: |-
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:$GITHUB_SHA docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
# Set up kustomize # Set up kustomize
- name: Set up Kustomize - name: Set up Kustomize
run: | run: |-
curl -o kustomize --location https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize chmod u+x ./kustomize
# Deploy the Docker image to the GKE cluster # Deploy the Docker image to the GKE cluster
- name: Deploy - name: Deploy
run: | run: |-
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
./kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA}
./kustomize build . | kubectl apply -f - ./kustomize build . | kubectl apply -f -
kubectl rollout status deployment/$DEPLOYMENT_NAME kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl get services -o wide kubectl get services -o wide