From 3108616ef7eaffc3c36b987c55a82638340a11eb Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:19:31 +0800 Subject: [PATCH 01/24] Create google.yml test --- .github/workflows/google.yml | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml new file mode 100644 index 0000000..35f2674 --- /dev/null +++ b/.github/workflows/google.yml @@ -0,0 +1,86 @@ +# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "main" branch. +# +# To configure this workflow: +# +# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. +# +# 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 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-kustomize + +name: Build and Deploy to GKE + +on: + push: + branches: [ "main" ] + +env: + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + #GAR_LOCATION: asia # TODO: update region of the Artifact Registry + GKE_CLUSTER: cluster-1 # TODO: update to cluster name + GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone + DEPLOYMENT_NAME: gke-test # TODO: update to deployment name + REPOSITORY: demo # TODO: update to Artifact Registry docker repository + IMAGE: php-site + +jobs: + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + environment: production + + permissions: + contents: 'read' + id-token: 'write' + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Configure Workload Identity Federation and generate an access token. + #- id: 'auth' + # name: 'Authenticate to Google Cloud' + # uses: 'google-github-actions/auth@v0' + # with: + # token_format: 'access_token' + # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + - id: 'auth' + uses: 'google-github-actions/auth@v0' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Get the GKE credentials so we can deploy to the cluster + - name: Set up GKE credentials + uses: google-github-actions/get-gke-credentials@v0 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + + # Build the Docker image + - name: Build + run: |- + docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . + . + # Push the Docker image to Google Artifact Registry + - name: Publish + run: |- + docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" + # Set up kustomize + - name: Set up Kustomize + 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: |- + ./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 3226ed0c50bd43c323ae879bdf21808cb37989bb Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:20:06 +0800 Subject: [PATCH 02/24] Update google.yml --- .github/workflows/google.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 35f2674..ea2afec 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -9,7 +9,7 @@ # 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-kustomize - +# name: Build and Deploy to GKE on: From 82393d812e1e564fb5e31fb1c3c4ec8b7244687a Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:21:20 +0800 Subject: [PATCH 03/24] Delete google.yml --- .github/workflows/google.yml | 86 ------------------------------------ 1 file changed, 86 deletions(-) delete mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml deleted file mode 100644 index ea2afec..0000000 --- a/.github/workflows/google.yml +++ /dev/null @@ -1,86 +0,0 @@ -# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "main" branch. -# -# To configure this workflow: -# -# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. -# -# 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 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-kustomize -# -name: Build and Deploy to GKE - -on: - push: - branches: [ "main" ] - -env: - PROJECT_ID: ${{ secrets.GKE_PROJECT }} - #GAR_LOCATION: asia # TODO: update region of the Artifact Registry - GKE_CLUSTER: cluster-1 # TODO: update to cluster name - GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone - DEPLOYMENT_NAME: gke-test # TODO: update to deployment name - REPOSITORY: demo # TODO: update to Artifact Registry docker repository - IMAGE: php-site - -jobs: - setup-build-publish-deploy: - name: Setup, Build, Publish, and Deploy - runs-on: ubuntu-latest - environment: production - - permissions: - contents: 'read' - id-token: 'write' - - steps: - - name: Checkout - uses: actions/checkout@v3 - - # Configure Workload Identity Federation and generate an access token. - #- id: 'auth' - # name: 'Authenticate to Google Cloud' - # uses: 'google-github-actions/auth@v0' - # with: - # token_format: 'access_token' - # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' - # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' - - # Alternative option - authentication via credentials json - - id: 'auth' - uses: 'google-github-actions/auth@v0' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - # Get the GKE credentials so we can deploy to the cluster - - name: Set up GKE credentials - uses: google-github-actions/get-gke-credentials@v0 - with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - - # Build the Docker image - - name: Build - run: |- - docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . - . - # Push the Docker image to Google Artifact Registry - - name: Publish - run: |- - docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" - # Set up kustomize - - name: Set up Kustomize - 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: |- - ./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 e7bffc451a1bf8da97181c1fd2b728c24d5685e8 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:21:53 +0800 Subject: [PATCH 04/24] Create google.yml --- .github/workflows/google.yml | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml new file mode 100644 index 0000000..35f2674 --- /dev/null +++ b/.github/workflows/google.yml @@ -0,0 +1,86 @@ +# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "main" branch. +# +# To configure this workflow: +# +# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. +# +# 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 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-kustomize + +name: Build and Deploy to GKE + +on: + push: + branches: [ "main" ] + +env: + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + #GAR_LOCATION: asia # TODO: update region of the Artifact Registry + GKE_CLUSTER: cluster-1 # TODO: update to cluster name + GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone + DEPLOYMENT_NAME: gke-test # TODO: update to deployment name + REPOSITORY: demo # TODO: update to Artifact Registry docker repository + IMAGE: php-site + +jobs: + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + environment: production + + permissions: + contents: 'read' + id-token: 'write' + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Configure Workload Identity Federation and generate an access token. + #- id: 'auth' + # name: 'Authenticate to Google Cloud' + # uses: 'google-github-actions/auth@v0' + # with: + # token_format: 'access_token' + # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + - id: 'auth' + uses: 'google-github-actions/auth@v0' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Get the GKE credentials so we can deploy to the cluster + - name: Set up GKE credentials + uses: google-github-actions/get-gke-credentials@v0 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + + # Build the Docker image + - name: Build + run: |- + docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . + . + # Push the Docker image to Google Artifact Registry + - name: Publish + run: |- + docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" + # Set up kustomize + - name: Set up Kustomize + 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: |- + ./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 c6a746892bbe5e7ef7a6730c9abf1046918a4e2e Mon Sep 17 00:00:00 2001 From: Lee Horng Date: Fri, 24 Mar 2023 03:24:16 +0000 Subject: [PATCH 05/24] test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1999af0..16745ee 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ then remove this sample app once things are working. This Docker container contains a simple _"Hello World!"_ [Node.js][node_js] app. -## Running the app in local development +## Running the app in local development1 The provided Docker Compose file allows you to run the app locally in development. To start the container, run: From 72ff0ace4d8a969343de5d34645ac870b75076c8 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:25:02 +0800 Subject: [PATCH 06/24] Delete google.yml --- .github/workflows/google.yml | 86 ------------------------------------ 1 file changed, 86 deletions(-) delete mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml deleted file mode 100644 index 35f2674..0000000 --- a/.github/workflows/google.yml +++ /dev/null @@ -1,86 +0,0 @@ -# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "main" branch. -# -# To configure this workflow: -# -# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. -# -# 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 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-kustomize - -name: Build and Deploy to GKE - -on: - push: - branches: [ "main" ] - -env: - PROJECT_ID: ${{ secrets.GKE_PROJECT }} - #GAR_LOCATION: asia # TODO: update region of the Artifact Registry - GKE_CLUSTER: cluster-1 # TODO: update to cluster name - GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone - DEPLOYMENT_NAME: gke-test # TODO: update to deployment name - REPOSITORY: demo # TODO: update to Artifact Registry docker repository - IMAGE: php-site - -jobs: - setup-build-publish-deploy: - name: Setup, Build, Publish, and Deploy - runs-on: ubuntu-latest - environment: production - - permissions: - contents: 'read' - id-token: 'write' - - steps: - - name: Checkout - uses: actions/checkout@v3 - - # Configure Workload Identity Federation and generate an access token. - #- id: 'auth' - # name: 'Authenticate to Google Cloud' - # uses: 'google-github-actions/auth@v0' - # with: - # token_format: 'access_token' - # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' - # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' - - # Alternative option - authentication via credentials json - - id: 'auth' - uses: 'google-github-actions/auth@v0' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - # Get the GKE credentials so we can deploy to the cluster - - name: Set up GKE credentials - uses: google-github-actions/get-gke-credentials@v0 - with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - - # Build the Docker image - - name: Build - run: |- - docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . - . - # Push the Docker image to Google Artifact Registry - - name: Publish - run: |- - docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" - # Set up kustomize - - name: Set up Kustomize - 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: |- - ./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 1029668c1f998471ed90a59a7a6a7d4baeb6620c Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:26:20 +0800 Subject: [PATCH 07/24] Create google.yml --- .github/workflows/google.yml | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml new file mode 100644 index 0000000..f7ab062 --- /dev/null +++ b/.github/workflows/google.yml @@ -0,0 +1,86 @@ +# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "master" branch. +# +# To configure this workflow: +# +# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. +# +# 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 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-kustomize + +name: Build and Deploy to GKE + +on: + push: + branches: [ "main" ] + +env: + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + #GAR_LOCATION: asia # TODO: update region of the Artifact Registry + GKE_CLUSTER: cluster-1 # TODO: update to cluster name + GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone + DEPLOYMENT_NAME: gke-test # TODO: update to deployment name + REPOSITORY: demo # TODO: update to Artifact Registry docker repository + IMAGE: sample-site + +jobs: + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + environment: production + + permissions: + contents: 'read' + id-token: 'write' + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Configure Workload Identity Federation and generate an access token. + #- id: 'auth' + # name: 'Authenticate to Google Cloud' + # uses: 'google-github-actions/auth@v0' + # with: + # token_format: 'access_token' + # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + - id: 'auth' + uses: 'google-github-actions/auth@v0' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Get the GKE credentials so we can deploy to the cluster + - name: Set up GKE credentials + uses: google-github-actions/get-gke-credentials@v0 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + + # Build the Docker image + - name: Build + run: |- + docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . + . + # Push the Docker image to Google Artifact Registry + - name: Publish + run: |- + docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" + # Set up kustomize + - name: Set up Kustomize + 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: |- + ./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 71dc72630a85bdf8f396b129385e1933f0e69059 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:32:51 +0800 Subject: [PATCH 08/24] Delete google.yml --- .github/workflows/google.yml | 86 ------------------------------------ 1 file changed, 86 deletions(-) delete mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml deleted file mode 100644 index f7ab062..0000000 --- a/.github/workflows/google.yml +++ /dev/null @@ -1,86 +0,0 @@ -# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "master" branch. -# -# To configure this workflow: -# -# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. -# -# 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 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-kustomize - -name: Build and Deploy to GKE - -on: - push: - branches: [ "main" ] - -env: - PROJECT_ID: ${{ secrets.GKE_PROJECT }} - #GAR_LOCATION: asia # TODO: update region of the Artifact Registry - GKE_CLUSTER: cluster-1 # TODO: update to cluster name - GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone - DEPLOYMENT_NAME: gke-test # TODO: update to deployment name - REPOSITORY: demo # TODO: update to Artifact Registry docker repository - IMAGE: sample-site - -jobs: - setup-build-publish-deploy: - name: Setup, Build, Publish, and Deploy - runs-on: ubuntu-latest - environment: production - - permissions: - contents: 'read' - id-token: 'write' - - steps: - - name: Checkout - uses: actions/checkout@v3 - - # Configure Workload Identity Federation and generate an access token. - #- id: 'auth' - # name: 'Authenticate to Google Cloud' - # uses: 'google-github-actions/auth@v0' - # with: - # token_format: 'access_token' - # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' - # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' - - # Alternative option - authentication via credentials json - - id: 'auth' - uses: 'google-github-actions/auth@v0' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - # Get the GKE credentials so we can deploy to the cluster - - name: Set up GKE credentials - uses: google-github-actions/get-gke-credentials@v0 - with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - - # Build the Docker image - - name: Build - run: |- - docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . - . - # Push the Docker image to Google Artifact Registry - - name: Publish - run: |- - docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" - # Set up kustomize - - name: Set up Kustomize - 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: |- - ./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 e42f076d267cf6b7e9d897904dd32089d1506c9d Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:33:39 +0800 Subject: [PATCH 09/24] Create google.yml --- .github/workflows/google.yml | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .github/workflows/google.yml diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml new file mode 100644 index 0000000..c60c33a --- /dev/null +++ b/.github/workflows/google.yml @@ -0,0 +1,91 @@ +# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "master" branch. +# +# To configure this workflow: +# +# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. +# +# 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 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-kustomize + +name: Build and Deploy to GKE + +on: + push: + branches: [ "master" ] + +env: + 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_ZONE: us-central1-c # TODO: update to cluster zone + DEPLOYMENT_NAME: gke-test # TODO: update to deployment name + REPOSITORY: samples # TODO: update to Artifact Registry docker repository + IMAGE: static-site + +jobs: + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + environment: production + + permissions: + contents: 'read' + id-token: 'write' + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' + with: + token_format: 'access_token' + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - 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 + - name: Set up GKE credentials + uses: google-github-actions/get-gke-credentials@v0 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + + # Build the Docker image + - name: Build + run: |- + docker build \ + --tag "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" \ + --build-arg GITHUB_SHA="$GITHUB_SHA" \ + --build-arg GITHUB_REF="$GITHUB_REF" \ + . + # Push the Docker image to Google Artifact Registry + - name: Publish + run: |- + docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" + # Set up kustomize + - name: Set up Kustomize + 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: |- + # 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 - + kubectl rollout status deployment/$DEPLOYMENT_NAME + kubectl get services -o wide From 654f3db11ea8715b717c038e2613ee0c20f6b53d Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:40:02 +0800 Subject: [PATCH 10/24] Update google.yml --- .github/workflows/google.yml | 45 ++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index c60c33a..f38e26c 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -18,12 +18,12 @@ on: env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} - GAR_LOCATION: us-central1 # TODO: update region of the Artifact Registry + #GAR_LOCATION: asia # TODO: update region of the Artifact Registry GKE_CLUSTER: cluster-1 # TODO: update to cluster name - GKE_ZONE: us-central1-c # TODO: update to cluster zone + GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone DEPLOYMENT_NAME: gke-test # TODO: update to deployment name - REPOSITORY: samples # TODO: update to Artifact Registry docker repository - IMAGE: static-site + REPOSITORY: demo # TODO: update to Artifact Registry docker repository + IMAGE: sample-site jobs: setup-build-publish-deploy: @@ -40,23 +40,20 @@ jobs: uses: actions/checkout@v3 # Configure Workload Identity Federation and generate an access token. + #- id: 'auth' + # name: 'Authenticate to Google Cloud' + # uses: 'google-github-actions/auth@v0' + # with: + # token_format: 'access_token' + # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json - id: 'auth' - name: 'Authenticate to Google Cloud' uses: 'google-github-actions/auth@v0' with: - token_format: 'access_token' - workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' - service_account: 'my-service-account@my-project.iam.gserviceaccount.com' - - # Alternative option - authentication via credentials json - # - id: 'auth' - # uses: 'google-github-actions/auth@v0' - # with: - # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - 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 - name: Set up GKE credentials uses: google-github-actions/get-gke-credentials@v0 @@ -67,15 +64,14 @@ jobs: # Build the Docker image - name: Build run: |- - docker build \ - --tag "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" \ - --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" \ + docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . . # Push the Docker image to Google Artifact Registry - name: Publish - run: |- - docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" + run: | + docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" + docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" # Set up kustomize - name: Set up Kustomize run: |- @@ -84,8 +80,7 @@ jobs: # Deploy the Docker image to the GKE cluster - name: Deploy run: |- - # 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 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 306e9c44f07f0be7bf01b2100a7d436de1ba5dda Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:42:31 +0800 Subject: [PATCH 11/24] Update google.yml --- .github/workflows/google.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index f38e26c..dc42e6d 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -69,7 +69,7 @@ jobs: # Push the Docker image to Google Artifact Registry - name: Publish run: | - docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:latest" + docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" # Set up kustomize From 0f6a779f5be38e8401c59fc6c8cc5db304bc3ce4 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:54:54 +0800 Subject: [PATCH 12/24] Update google.yml test --- .github/workflows/google.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index dc42e6d..31f853d 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -65,7 +65,6 @@ jobs: - name: Build run: |- docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . - . # Push the Docker image to Google Artifact Registry - name: Publish run: | From 119fe4bbbefd561faa5b9d7b7417c5614f49a4a6 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 12:00:35 +0800 Subject: [PATCH 13/24] Update google.yml test --- .github/workflows/google.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 31f853d..2831386 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -61,6 +61,9 @@ jobs: cluster_name: ${{ env.GKE_CLUSTER }} location: ${{ env.GKE_ZONE }} + - run: |- + sudo gcloud --quiet auth configure-docker + # Build the Docker image - name: Build run: |- From 8959e8cfdfa7affa943b876ea89bdad9ae9fb5e6 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:09:49 +0800 Subject: [PATCH 14/24] Update google.yml --- .github/workflows/google.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 2831386..6461485 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -69,6 +69,10 @@ jobs: run: |- docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . # Push the Docker image to Google Artifact Registry + + - run: |- + sudo gcloud auth login + - name: Publish run: | docker tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" From 92532d4ae7d505ea6866d161f8d531d6a8ff5704 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:16:11 +0800 Subject: [PATCH 15/24] Update google.yml --- .github/workflows/google.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 6461485..4784305 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -67,17 +67,16 @@ jobs: # Build the Docker image - name: Build run: |- - docker build -t "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" . - # Push the Docker image to Google Artifact Registry - - - run: |- - sudo gcloud auth login - + 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 tag "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:${{ github.sha }}" - docker push "gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE }}:latest" + run: |- + docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" # Set up kustomize - name: Set up Kustomize run: |- From 4c62d53bb5cac55c48335bc0e12047bd1fd15363 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:27:21 +0800 Subject: [PATCH 16/24] Update google.yml --- .github/workflows/google.yml | 67 +++++++++++++++--------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 4784305..aa1e784 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -1,29 +1,25 @@ -# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "master" branch. -# -# To configure this workflow: -# -# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. -# -# 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 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-kustomize +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. name: Build and Deploy to GKE on: push: - branches: [ "master" ] + branches: + - main env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} - #GAR_LOCATION: asia # TODO: update region of the Artifact Registry - GKE_CLUSTER: cluster-1 # TODO: update to cluster name - GKE_ZONE: asia-southeast1-b # TODO: update to cluster zone - DEPLOYMENT_NAME: gke-test # TODO: update to deployment name - REPOSITORY: demo # TODO: update to Artifact Registry docker repository - IMAGE: sample-site + GKE_CLUSTER: cluster-1 # Add your cluster name here. + GKE_ZONE: asia-southeast1-b # Add your cluster zone here. + DEPLOYMENT_NAME: gke-test # Add your deployment name here. + IMAGE: static-site jobs: setup-build-publish-deploy: @@ -31,38 +27,27 @@ jobs: runs-on: ubuntu-latest environment: production - permissions: - contents: 'read' - id-token: 'write' - steps: - name: Checkout uses: actions/checkout@v3 - # Configure Workload Identity Federation and generate an access token. - #- id: 'auth' - # name: 'Authenticate to Google Cloud' - # uses: 'google-github-actions/auth@v0' - # with: - # token_format: 'access_token' - # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' - # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' - - # Alternative option - authentication via credentials json - - id: 'auth' - uses: 'google-github-actions/auth@v0' + # Setup gcloud CLI + - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + 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 - - name: Set up GKE credentials - uses: google-github-actions/get-gke-credentials@v0 + - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e with: cluster_name: ${{ env.GKE_CLUSTER }} location: ${{ env.GKE_ZONE }} - - - run: |- - sudo gcloud --quiet auth configure-docker + credentials: ${{ secrets.GKE_SA_KEY }} # Build the Docker image - name: Build @@ -77,11 +62,13 @@ jobs: - name: Publish run: |- docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" + # Set up kustomize - name: Set up Kustomize 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: |- From 6848079cf8ebdb0546eb29366a7001bf463bbd9d Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:34:46 +0800 Subject: [PATCH 17/24] Update google.yml test --- .github/workflows/google.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index aa1e784..2c98edd 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -6,7 +6,7 @@ # GitHub recommends pinning actions to a commit SHA. # To get a newer version, you will need to update the SHA. # You can also reference a tag or branch, but the action may change without warning. - +# name: Build and Deploy to GKE on: From c678ef2d7ecc331768a2940f11a38dcc28754549 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:35:35 +0800 Subject: [PATCH 18/24] Update google.yml --- .github/workflows/google.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 2c98edd..c261024 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -6,13 +6,13 @@ # GitHub recommends pinning actions to a commit SHA. # To get a newer version, you will need to update the SHA. # You can also reference a tag or branch, but the action may change without warning. -# + name: Build and Deploy to GKE on: push: branches: - - main + - master env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} From 6f72c93afeee4bb748de685b57789a01bbe46ea9 Mon Sep 17 00:00:00 2001 From: horng91 <123155935+horng91@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:36:28 +0800 Subject: [PATCH 19/24] Update google.yml test --- .github/workflows/google.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index c261024..3bd2d20 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -7,6 +7,7 @@ # To get a newer version, you will need to update the SHA. # You can also reference a tag or branch, but the action may change without warning. + name: Build and Deploy to GKE on: From 2266d3a05b17d01c73ae637b8967aeceabbe2c01 Mon Sep 17 00:00:00 2001 From: jlieow <52845474+jlieow@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:16:21 +0800 Subject: [PATCH 20/24] Update github workflow to check kustomize installed location --- .github/workflows/google.yml | 114 ++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 3bd2d20..4f12b15 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -7,73 +7,77 @@ # To get a newer version, you will need to update the SHA. # You can also reference a tag or branch, but the action may change without warning. - name: Build and Deploy to GKE on: - push: - branches: - - master + push: + branches: + - master + - fix-jerome env: - PROJECT_ID: ${{ secrets.GKE_PROJECT }} - GKE_CLUSTER: cluster-1 # Add your cluster name here. - GKE_ZONE: asia-southeast1-b # Add your cluster zone here. - DEPLOYMENT_NAME: gke-test # Add your deployment name here. - IMAGE: static-site + PROJECT_ID: ${{ secrets.GKE_PROJECT }} + GKE_CLUSTER: cluster-1 # Add your cluster name here. + GKE_ZONE: asia-southeast1-b # Add your cluster zone here. + DEPLOYMENT_NAME: gke-test # Add your deployment name here. + IMAGE: static-site jobs: - setup-build-publish-deploy: - name: Setup, Build, Publish, and Deploy - runs-on: ubuntu-latest - environment: production + setup-build-publish-deploy: + name: Setup, Build, Publish, and Deploy + runs-on: ubuntu-latest + environment: production - steps: - - name: Checkout - uses: actions/checkout@v3 + steps: + - name: Checkout + uses: actions/checkout@v3 - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 - with: - service_account_key: ${{ secrets.GKE_SA_KEY }} - project_id: ${{ secrets.GKE_PROJECT }} + # Setup gcloud CLI + - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 + with: + 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 + # 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 - - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e - with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - credentials: ${{ secrets.GKE_SA_KEY }} + # Get the GKE credentials so we can deploy to the cluster + - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GKE_SA_KEY }} - # Build the Docker image - - name: Build - run: |- - docker build \ - --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \ - --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" \ - . + # Build the Docker image + - name: Build + 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 "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" + # Push the Docker image to Google Container Registry + - name: Publish + run: |- + docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" - # Set up kustomize - - name: Set up Kustomize - 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 + # Set up kustomize + - name: Set up Kustomize + 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 + echo "Check if kustomize is installed correctly 1" + echo ls + echo "Check if kustomize is installed correctly 1" + echo ls . - # Deploy the Docker image to the GKE cluster - - name: Deploy - 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 + # Deploy the Docker image to the GKE cluster + - name: Deploy + 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 f649764d9c2ab3016ba91c13dc2ff3ee1094c200 Mon Sep 17 00:00:00 2001 From: jlieow <52845474+jlieow@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:21:07 +0800 Subject: [PATCH 21/24] Commented out other steps left setting up kustomize --- .github/workflows/google.yml | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 4f12b15..996b30d 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -33,36 +33,36 @@ jobs: uses: actions/checkout@v3 # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 - with: - service_account_key: ${{ secrets.GKE_SA_KEY }} - project_id: ${{ secrets.GKE_PROJECT }} + # - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 + # with: + # 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 + # # 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 - - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e - with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - credentials: ${{ secrets.GKE_SA_KEY }} + # # Get the GKE credentials so we can deploy to the cluster + # - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e + # with: + # cluster_name: ${{ env.GKE_CLUSTER }} + # location: ${{ env.GKE_ZONE }} + # credentials: ${{ secrets.GKE_SA_KEY }} - # Build the Docker image - - name: Build - run: |- - docker build \ - --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \ - --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" \ - . + # # Build the Docker image + # - name: Build + # 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 "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" + # # Push the Docker image to Google Container Registry + # - name: Publish + # run: |- + # docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" # Set up kustomize - name: Set up Kustomize @@ -70,14 +70,14 @@ jobs: curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 chmod u+x ./kustomize echo "Check if kustomize is installed correctly 1" - echo ls + ls echo "Check if kustomize is installed correctly 1" - echo ls . + ls kustomize # Deploy the Docker image to the GKE cluster - - name: Deploy - 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 + # - name: Deploy + # 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 84fc6cc7cba28eccb76c62a9dfd51ab0cc760ad5 Mon Sep 17 00:00:00 2001 From: jlieow <52845474+jlieow@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:26:54 +0800 Subject: [PATCH 22/24] Update kustomize path --- .github/workflows/google.yml | 70 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index 996b30d..bd470e7 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -33,51 +33,47 @@ jobs: uses: actions/checkout@v3 # Setup gcloud CLI - # - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 - # with: - # service_account_key: ${{ secrets.GKE_SA_KEY }} - # project_id: ${{ secrets.GKE_PROJECT }} + - uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 + with: + 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 + # 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 - # - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e - # with: - # cluster_name: ${{ env.GKE_CLUSTER }} - # location: ${{ env.GKE_ZONE }} - # credentials: ${{ secrets.GKE_SA_KEY }} + # Get the GKE credentials so we can deploy to the cluster + - uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GKE_SA_KEY }} - # # Build the Docker image - # - name: Build - # run: |- - # docker build \ - # --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \ - # --build-arg GITHUB_SHA="$GITHUB_SHA" \ - # --build-arg GITHUB_REF="$GITHUB_REF" \ - # . + # Build the Docker image + - name: Build + 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 "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" + # Push the Docker image to Google Container Registry + - name: Publish + run: |- + docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" # Set up kustomize - name: Set up Kustomize 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 - echo "Check if kustomize is installed correctly 1" - ls - echo "Check if kustomize is installed correctly 1" - ls kustomize + chmod u+x kustomize # Deploy the Docker image to the GKE cluster - # - name: Deploy - # 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 + - name: Deploy + 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 b5c83f90eb29128c40bb74e352baaa815c6345a1 Mon Sep 17 00:00:00 2001 From: jlieow <52845474+jlieow@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:34:48 +0800 Subject: [PATCH 23/24] Removed kustomize as there is no kustomize.yaml --- .github/workflows/google.yml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index bd470e7..e865b12 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -64,16 +64,21 @@ jobs: run: |- docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" - # Set up kustomize - - name: Set up Kustomize + - name: Deploy to GKE 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 + kubectl create deployment hello-server \ + --image=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA - # Deploy the Docker image to the GKE cluster - - name: Deploy - 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 + # # Set up kustomize + # - name: Set up Kustomize + # 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: |- + # 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 a4e5996bedddb6c8679e69618d873fb88fa7da26 Mon Sep 17 00:00:00 2001 From: jlieow <52845474+jlieow@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:43:52 +0800 Subject: [PATCH 24/24] Removed branch trigger fix-jerome --- .github/workflows/google.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml index e865b12..ede039e 100644 --- a/.github/workflows/google.yml +++ b/.github/workflows/google.yml @@ -13,7 +13,6 @@ on: push: branches: - master - - fix-jerome env: PROJECT_ID: ${{ secrets.GKE_PROJECT }}