chapter nine

9 Building Docker Images within 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 builds status into GitHub pull requests
  • Deployment and configuration of hosted and managed Docker private registry solutions
  • Docker images lifecycle within the development cycle and tagging strategies
  • Scanning Docker Images for security vulnerabilities within Jenkins pipelines

In the previous chapter, we learned how to run tests inside Docker containers within continuous integration pipelines. In this part, we will finish the CI workflow by building a Docker image and storing it inside a private remote repository for versioning.

Figure 9.1. Continuous Integration Stages

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

  • Checkout the source code from a remote repository. It fetches the code from the version control system (VCS) on a push event.
  • Running pre-integration tests such as unit tests, security tests, quality tests, UI tests, etc inside a Docker container. Might include, generation of coverage reports and integration of quality inspection tools like SonarQube for static code analysis.
  • Compiling the source code and building a Docker image (automated packaging).
  • Tagging the end image and storing it in a private registry.

9.1    Building Docker Images

9.1.1   Usage of Docker DSL

9.1.2   Docker Build Arguments

9.2    Deploying 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 Cloud Registry

9.3    Tagging Docker images the right way

9.4    Scanning Docker Images for Vulnerabilities

9.5    Writing Jenkins Declarative Pipeline

9.6    Managing Pull Requests with Jenkins

9.7    Summary