Merge pull request #1259 from FrodoTheTrue/update-google-deployment-2

Update google deployment starter workflow (partner_templates)
This commit is contained in:
Anurag Chauhan
2021-11-24 15:47:21 +05:30
committed by GitHub
2 changed files with 27 additions and 22 deletions
+26 -21
View File
@@ -4,11 +4,11 @@
# #
# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. # 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 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). # 2. Create and configure a Workload Identity Provider for GitHub (https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)
# #
# 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, and DEPLOYMENT_NAME environment variables (below). # 3. Change the values for the GAR_LOCATION, GKE_ZONE, GKE_CLUSTER, IMAGE, REPOSITORY and DEPLOYMENT_NAME environment variables (below).
# #
# For more support on how to run the workflow, please visit https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke # For more support on how to run the workflow, please visit https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke-kustomize
name: Build and Deploy to GKE name: Build and Deploy to GKE
@@ -19,11 +19,17 @@ on:
env: env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }} PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GAR_LOCATION: us-central1 # TODO: update region of the Artifact Registry
GKE_CLUSTER: cluster-1 # TODO: update to cluster name GKE_CLUSTER: cluster-1 # TODO: update to cluster name
GKE_ZONE: us-central1-c # TODO: update to cluster zone GKE_ZONE: us-central1-c # TODO: update to cluster zone
DEPLOYMENT_NAME: gke-test # TODO: update to deployment name DEPLOYMENT_NAME: gke-test # TODO: update to deployment name
REPOSITORY: samples # TODO: update to Artifact Registry docker repository
IMAGE: static-site IMAGE: static-site
permissions:
contents: 'read'
id-token: 'write'
jobs: jobs:
setup-build-publish-deploy: setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy name: Setup, Build, Publish, and Deploy
@@ -34,48 +40,47 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
# Setup gcloud CLI # Configure Workload Identity Federation and generate an access token.
- uses: google-github-actions/[email protected] - id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/[email protected]'
with: with:
service_account_key: ${{ secrets.GKE_SA_KEY }} token_format: 'access_token'
project_id: ${{ secrets.GKE_PROJECT }} workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
service_account: '[email protected]'
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
- name: Docker configuration
run: |-
echo ${{steps.auth.outputs.access_token}} | docker login -u oauth2accesstoken --password-stdin https://$GAR_LOCATION-docker.pkg.dev
# Get the GKE credentials so we can deploy to the cluster # Get the GKE credentials so we can deploy to the cluster
- uses: google-github-actions/get-gke-credentials@v0.2.1 - name: Set up GKE credentials
uses: google-github-actions/[email protected]
with: with:
cluster_name: ${{ env.GKE_CLUSTER }} cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }} location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}
# Build the Docker image # Build the Docker image
- name: Build - name: Build
run: |- run: |-
docker build \ docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \ --tag "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$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 Artifact Registry
# Push the Docker image to Google Container Registry
- name: Publish - name: Publish
run: |- run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA"
# Set up kustomize # Set up kustomize
- name: Set up Kustomize - name: Set up Kustomize
run: |- run: |-
curl -sfLo kustomize 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: |-
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA # replacing the image name in the k8s template
./kustomize edit set image LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG=$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$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
@@ -3,5 +3,5 @@
"description": "Build a docker container, publish it to Google Container Registry, and deploy to GKE.", "description": "Build a docker container, publish it to Google Container Registry, and deploy to GKE.",
"creator": "Google Cloud", "creator": "Google Cloud",
"iconName": "googlegke", "iconName": "googlegke",
"categories": ["Deployment", "Dockerfile"] "categories": ["Deployment", "Dockerfile", "Kubernetes", "Kustomize"]
} }