9 Building Docker images within a CI pipeline

 

This chapter covers

  • Building Docker images inside Jenkins pipelines and best practices of writing Dockerfiles
  • Using Docker agents as an execution environment in Jenkins declarative pipelines
  • Integrating Jenkins build statuses into GitHub pull requests
  • Deploying and configuring hosted and managed Docker private registry solutions
  • Docker images life cycle within the development cycle and tagging strategies
  • Scanning Docker images for security vulnerabilities within Jenkins pipelines

In the previous chapter, you learned how to run automated tests inside Docker containers within CI pipelines. In this chapter, we will finish the CI workflow by building a Docker image and storing it inside a private remote repository for versioning; see figure 9.1.

Figure 9.1 The Build and Push stages will be implemented in this chapter.

By the end of this chapter, you should be able to build a similar CI pipeline with these steps:

  1. Check out the source code from a remote repository. The CI server fetches the code from the version-control system (VCS) on a push event.
  2. Run pre-integration tests such as unit tests, security tests, quality tests, and UI tests inside a Docker container. These might include generating coverage reports and integrating quality-inspection tools like SonarQube for static code analysis.
  3. Compile the source code and build a Docker image (automated packaging).
  4. Tag the end image and store it in a private registry.

9.1 Building Docker images

9.1.1 Using the Docker DSL

9.1.2 Docker build arguments

9.2 Deploying a Docker private registry

9.2.1 Nexus Repository OSS

9.2.2 Amazon Elastic Container Registry

9.2.3 Azure Container Registry

9.2.4 Google Container Registry

9.3 Tagging Docker images the right way

9.4 Scanning Docker images for vulnerabilities