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 automated 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. The “Build” and “Push” stages will be implemented along this chapter
By the end of this chapter, you should be able to build a similar CI pipeline with the above stages:
- Check out 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.