
Next, you need to create a container repository to store the containers that are built by the assembly line.
Notice ENCRYPTION is set to Google-managed key. Like most Google Cloud services, Artifact Repository encrypts data at rest by default.
Implementing continuous integration with Cloud Build
In previous chapters, you have been using Cloud Build behind the scenes whether you realized it or not. Every time you used gcloud run deploy or gcloud functions deploy you have been triggering a Cloud Build pipeline in the background using your local source code as the source.
Now you are going to use it to automatically trigger a build whenever there is a commit to the main branch of the GitHub repository. You will use the skill service as an example, but it will be a similar process to the other services. The build configuration will differ slightly for the fact service and the skill service, for example, as it is a Java application rather than Go. Cloud Build is very flexible and can be configured to build almost any type of application.
This is setting the name of the trigger to skill-service-trigger, the branch pattern to ^main$ (i.e., only trigger when there is a commit to the main branch), and the build config file to a file in the skill service directory skill-service/cloudbuild.yaml.
The single SkillsMapper repository contains multiple services. What you don’t want is for all services to be rebuilt and redeployed when there is a commit to the main branch. To only build and deploy the service that has changed, you can restrict the files that trigger a build with the included-file parameter. In the next example, only changes to files in the skill-service directory will trigger a build.
This will run the trigger on the main branch. The message returned will include a link to the build log in the metadata.build.logUrl field, which you can open in your browser to see progress.
Tip
To speed up the build process by excluding files that are not needed for the build process, you can create a .gcloudignore in the root of the repository to exclude files. This works in a similar way as a .gitignore file. For example, you can exclude all markdown files like README.md files with the following entry in the .gcloudignore file: */*.md.
Now let’s look at the details of the Cloud Build configuration file to understand what the build pipeline is doing.
Understanding Cloud Build configurations
The Cloud Build configuration is a YAML file, in this case, the cloudbuild.yaml file in the skill-service directory.
It is made up of one or more build steps. The build process starts with a workspace containing a fresh clone of the GitHub repository for each execution and then runs each step in turn.