Building and Testing Applications on GCP
The course is part of these learning paths
Google Cloud Platform (GCP) is a powerful platform that brings the flexibility and reliability of Google’s infrastructure to your projects. As a leader in AI, machine learning, and networking, GCP has a suite of tools and services for developers to use for almost any circumstance. Before using them, it’s good to learn the ins and outs of GCP and the most effective patterns for software development. The Professional Cloud Developer exam, as well as the industry at large, has been transformed by Continuous Integration (CI) and Continuous Deployment (CD), which enable developers to deliver code safely and securely into production once properly setup. This course will cover the Google best practices for setting up a CI/CD pipeline on GCP.
For support, queries or feedback relating to this course, please contact us at firstname.lastname@example.org.
- Learn GCP core developer services
- Create a CI/CD pipeline with Google Cloud Build
- Test and deploy a containerized application
Developers who are studying for the Google Cloud Professional Cloud Developer Certification exam.
Cloud Build is the GCP solution for running a Continuous Integration/Continuous Deployment pipeline. Cloud Build works by taking a list of commands then running those on what they call a builder, which we'll get more into in just a moment. These steps can download dependencies, run unit tests, or create artifacts. They are defined in a build configuration in either YAML or JSON format, and stored alongside your application code.
To make sure that each step is performed in the same way, all steps are run on builders. These builders are Docker containers with languages and tools pre-installed on them. Once you start a build using one of these builders, they'll start up, run the steps in your build configuration, and then self-destruct. This means that any steps you run on the same builders are guaranteed to run on the same way every time. Some of these builders provided to you by Google are Gradle, Go, NPM, Docker, Dotnet Core, and Kubectl, or Kubernetes. You also have the option to create your own custom builders.
The code to get started is available on Github, and I'll put a link below. Running these steps in order is gonna be the basis for a CI/CD pipeline. For example, you might have a build step that tests code that was just checked into your cloud source repository, then a step that compiles a jar file from that code, then another one that creates a Docker image using that jar. If a Docker image is built from that pipeline, Cloud Build will take that image and upload it to the Google Container Registry.
In this demo, we'll create a simple Docker container from code in a cloud source repository using Cloud Build, then run it from the Google Container Registry to make sure it works. Let's get started.
In this demo, we're going to run a Cloud Build to build a simple Docker container and then run that container to make sure it works. So to start off, I'm here in my cloud source repository using Visual Studio Code, and just to make sure that I am in the right spot, let's go ahead and get some information on this repo.
So now we know I'm in the right spot, you'll see I have three files here, a quick start shell script which is just a simple, "Hello world," a Docker file, it copies that shell script and then runs it, and then cloudbuild.yaml, which has one step in it using the Docker Cloud Builder on line two. We're going to pass in build, and then the quick start image. And we're going to produce an image and upload it to the Google Container Registry. So let's go ahead and submit this to Cloud Build by entering
gcloud builds submit, and then our cloudbuild.yaml as the config parameter. And make sure you put a dot on the end of that dot, that's gonna mean build everything in the current directory.
Great, and we have a successful build. Let's go over to our console and take a look at it. Okay so I'm here in my Cloud Build console and we see we do have a successful build, about a minute ago, took 17 seconds. Let's go ahead and get some more details on that. You see we've got our build steps about middle of the screen, as well as the logs from the build. We also have the image that we built as part of our build process. So now we have an image, let's go ahead and see if it works.
All right, I'm back here in my terminal and the first thing I wanna do to get Docker to recognize the Google Container Registry is configure Docker for it. So this is just going to add some endpoints to our docker config so we can easily reach GCR. Wonderful, once that's all set let's go ahead and run our image from our registry. And perfect, it gives us the time and we're all set. That's it for this demo, thanks for watching.
Chris Blackden started his first IT job at the age of fifteen and has been doing it ever since. He’s held roles from Hardware Technician to Senior Software Engineer, and is currently working as a DevOps Engineer in a healthcare research organization. Some of his passions outside of work include cooking and eating spicy food, and old-school kung fu movies.