4 Baking machine images with Packer

 

This chapter covers

  • Overview of immutable infrastructure
  • Baking Jenkins machine images with Packer
  • Discovering Jenkins essentials plugins
  • Executing Jenkins Groovy scripts
  • Using Packer provisioners to automate Jenkins settings

In the previous chapter, you learned how Jenkins distributed mode architecture works. In this one, we will get our hands dirty and deploy a Jenkins cluster on AWS. As a quick reminder, you learned that the Jenkins cluster is divided into two main components: master and worker. Before diving into the implementation of the distributed builds architecture, we will deploy the standalone mode, shown in figure 4.1, to cover some basics.

To deploy this architecture, we need to provision a server (for example, an EC2 instance in AWS). Then we’ll install and configure Jenkins on the machine. While this manual process works, it’s not efficient when we want to deploy Jenkins to scale. Plus, updating or upgrading Jenkins can be lengthy and painful, and things can easily go wrong—breaking your CI/CD pipelines and impacting your product release as a result.

Figure 4.1 Jenkins standalonearchitecture on AWS

4.1 Immutable infrastructure

4.2 Introducing Packer

4.2.1 How does it work?

4.2.2 Installation and configuration

4.2.3 Baking a machine image

4.3 Baking the Jenkins master AMI

4.3.1 Configuring Jenkins upon startup

4.3.2 Discovering Jenkins plugins

4.4 Baking the Jenkins worker AMI

Summary