Skip to content

# build-and-deploy GitHub Actions job to GKE #88

@Dargon789

Description

@Dargon789

Reviewer's Guide

Adds a new GitHub Actions workflow that builds a Docker image, pushes it to Google Artifact Registry, and deploys it to a GKE cluster on pushes to the master branch using Workload Identity Federation for authentication.

Flow diagram for build-and-deploy GitHub Actions job to GKE

flowchart TD
  A["Push to 'master' branch"] --> B["Trigger workflow 'Build and Deploy to GKE'"]
  B --> C["Start job 'Setup, Build, Publish, and Deploy' on 'ubuntu-latest'"]
  C --> D["Step: Checkout repository (actions/checkout@v4)"]
  D --> E["Step: Authenticate to Google Cloud (google-github-actions/auth@v2) using 'WORKLOAD_IDENTITY_PROVIDER'"]
  E --> F["Output: Short-lived Google Cloud access token (auth_token)"]
  F --> G["Step: Docker Auth (docker/login-action@v3) to '${GAR_LOCATION}-docker.pkg.dev' with 'oauth2accesstoken'"]
  G --> H["Step: Set up GKE credentials (get-gke-credentials@v2) for cluster '${GKE_CLUSTER}' in '${GKE_ZONE}'"]
  H --> I["Step: Build Docker image with 'docker build' using 'GITHUB_SHA' and 'GITHUB_REF'"]
  I --> J["Tag image as '${GAR_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE}:${GITHUB_SHA}'"]
  J --> K["Step: Push Docker image to Artifact Registry with 'docker push'"]
  K --> L["Step: Download and set up 'kustomize' binary"]
  L --> M["Step: Update image in kustomize: 'kustomize edit set image LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG=...:${GITHUB_SHA}'"]
  M --> N["Step: Render manifests with 'kustomize build .' and pipe to 'kubectl apply -f -'"]
  N --> O["Step: Wait for rollout: 'kubectl rollout status deployment/${DEPLOYMENT_NAME}'"]
  O --> P["Step: Inspect services: 'kubectl get services -o wide'"]
  P --> Q["Job completes: Application updated on GKE cluster"]
Loading

File-Level Changes

Change Details Files
Introduce a GitHub Actions CI/CD pipeline for building, publishing, and deploying a containerized app to GKE via Artifact Registry.
  • Define workflow trigger on pushes to the master branch and set environment variables for GCP project, cluster, and Artifact Registry configuration.
  • Configure authentication to Google Cloud using google-github-actions/auth with Workload Identity Federation and set up Docker authentication against Artifact Registry.
  • Retrieve GKE cluster credentials using google-github-actions/get-gke-credentials to enable kubectl access.
  • Build and push a Docker image tagged with the current commit SHA to Artifact Registry using docker build and docker push.
  • Download and prepare kustomize, then use it to update the deployment image, apply manifests to the cluster, wait for rollout, and list services.
.github/workflows/google.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #87 (comment)

Metadata

Metadata

Assignees

Labels

dependenciesPull requests that update a dependency filedocumentationImprovements or additions to documentationduplicateThis issue or pull request already existsenhancementNew feature or requestgithub_actionsPull requests that update GitHub Actions codegood first issueGood for newcomersinvalidThis doesn't seem rightjavascriptPull requests that update javascript codequestionFurther information is requestedrustPull requests that update Rust code

Projects

Status

In Review

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions