You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

google.yml 2.9 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when a release is created
  2. #
  3. # To configure this workflow:
  4. #
  5. # 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc.
  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).
  8. #
  9. # 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, and DEPLOYMENT_NAME environment variables (below).
  10. #
  11. # For more support on how to run the workflow, please visit https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke
  12. name: Build and Deploy to GKE
  13. on:
  14. release:
  15. types: [created]
  16. env:
  17. PROJECT_ID: ${{ secrets.GKE_PROJECT }}
  18. GKE_CLUSTER: cluster-1 # TODO: update to cluster name
  19. GKE_ZONE: us-central1-c # TODO: update to cluster zone
  20. DEPLOYMENT_NAME: gke-test # TODO: update to deployment name
  21. IMAGE: static-site
  22. jobs:
  23. setup-build-publish-deploy:
  24. name: Setup, Build, Publish, and Deploy
  25. runs-on: ubuntu-latest
  26. environment: production
  27. steps:
  28. - name: Checkout
  29. uses: actions/checkout@v2
  30. # Setup gcloud CLI
  31. - uses: google-github-actions/setup-gcloud@v0.2.0
  32. with:
  33. service_account_key: ${{ secrets.GKE_SA_KEY }}
  34. project_id: ${{ secrets.GKE_PROJECT }}
  35. # Configure Docker to use the gcloud command-line tool as a credential
  36. # helper for authentication
  37. - run: |-
  38. gcloud --quiet auth configure-docker
  39. # Get the GKE credentials so we can deploy to the cluster
  40. - uses: google-github-actions/get-gke-credentials@v0.2.1
  41. with:
  42. cluster_name: ${{ env.GKE_CLUSTER }}
  43. location: ${{ env.GKE_ZONE }}
  44. credentials: ${{ secrets.GKE_SA_KEY }}
  45. # Build the Docker image
  46. - name: Build
  47. run: |-
  48. docker build \
  49. --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
  50. --build-arg GITHUB_SHA="$GITHUB_SHA" \
  51. --build-arg GITHUB_REF="$GITHUB_REF" \
  52. .
  53. # Push the Docker image to Google Container Registry
  54. - name: Publish
  55. run: |-
  56. docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
  57. # Set up kustomize
  58. - name: Set up Kustomize
  59. run: |-
  60. curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
  61. chmod u+x ./kustomize
  62. # Deploy the Docker image to the GKE cluster
  63. - name: Deploy
  64. run: |-
  65. ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
  66. ./kustomize build . | kubectl apply -f -
  67. kubectl rollout status deployment/$DEPLOYMENT_NAME
  68. kubectl get services -o wide