Automatization exercise with jenkins, dockers, packer and chef
This is a basic automation exercise that can help others an easy start. It contains the basic files required :
- Dockerfile
- Jenkinsfile
- A json file for Packer (centochef.jenkins.09.json)
- A basic default.rb chef recipe
Along with that I used it the following artifacts but you can change them changing the references in the appropiate files:
- A chef-client rpm (chef-14.1.12-1.el7.x86_64.rpm) //Used by packer to bootstrap chef
- A centos:latest docker image //Used by packer as base image
- A jdk 8 instaler for linux (jdk-8u171-linux-x64.tar.gz) //Used by chef as pre-req to tomcat
- A tomcat instaler for linux (apache-tomcat-7.0.88.tar.gz) //Used by chef to install tomcat
- A alpine:latest docker image //Used by me to create a small alpine +packer
- The packer binaries to install in linux (packer_1.2.3_linux_amd64.zip) //Alpine + packer exec + docker
I think that this example is simple an easy to follow but i will give some indications to help get along with it. 0. Follow the Jenkinsfile - it could be used (with corrections) to build the pipeline
- Packer use docker builder and a pre-existing docker image (centos)
- Packer use file and shell provisioners to upload chef client file, install it and them upload a local cookbook named "tomcat" including the default.rb recipe
- Packer post-processor register the new docker image in local registry
- Jenkins , using that new image, calls the chef-client , in local mode, to execute the cookbook
- The execution of the cookbook will install jdk and tomcat with required configuration
- Jenkins again, as an exercise, call the docker image, set some env variables and startup tomcat
- As a very simple test, jenkins execute a curl against port 8080 after a 2m sleep to allow tomcat to start
- I need to parametrize artifacts names and env variables. Everything is harcoded now so take notice that you'll need to fix references to local directories in my machine
- Add a bitbucket/github stage so jenkins pull this files from there
- Artifacts shoulb be in a repository, not local directories
- ....
Hope it helps starting !