A proof-of-concept, multi-purpose repo for testing and publishing cookbooks using Jenkins Docker containers.
In current form, this is best suited for creating a quick and dirty, on-the-fly, cookbook pipeline and works nicely as an ephemeral pipeline for local development. Careful considerations should be made before porting any of this functionality to a production environment.
What this does:
- creates a fresh jenkins install with a blueocean container
- installs plugins, configures and turns off the install wizard
- creates Admin user
- integrates with github repo and pulls/runs Jenkinsfile from a given cookbook repo
- creates a jenkins builder container (inside master) to run pipeline
- runs .kitchen.docker.yml (inside builder)
- runs cookbook validations and publishes the master branch to a Chef Server on Host network
- continues watching repo until destroyed
- The setup_jenkins.sh file is heavily dependent on static environment variables.
- keys and configurations need to added to jenkins-master dir.
- ./jenkins-master/*
- Add these files to the jenkins-master directory. This is the Jenkins Master Docker build context and the following files are used to build the container
- jenkins-master/cicdsvc-knife.rb A knife configuration file with the appropriate configuration for your environment
- jenkins-master/cicdsvc.pem A client.pem key for the user specified in the knife.rb file
- create jenkins-master/github-token file containing a valid github token A Github Access Token with repo and user email access to the cookbook repo
-
Edit setup_jenkins.sh and set Environment variables appropriately
-
Run ./jenkins-master/setup_jenkins.sh
This will run the bare bones basics of a cookbook pipeline.
- Unit tests with chefspec
- Linting with foodcritic and cookstyle
- Functional tests with TestKitchen
- Publishing to a Chef Server
- ./vars/publishMaster.groovy
- ./resources/Dockerfile (Jenkins Builder) A Dockerfile for running a cookbook builder inside the jenkinsci/blueocean Jenkins container
A bundle of bash hackery to setup Chef infrastructure with a cookbook pipeline.
A Jenkinsfile that dynamically imports the pipeline library.
// Dynamically include a jenkins library
library identifier: 'jenkins-cookbook-pipeline@master', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'git://github.com/mtyler/jenkins-cookbook-pipeline.git'])
// Call groovy method containing shared pipeline.
// Argument should be the name of the cookbook
node {
publishMaster 'chef-infra-base'
}
This library by James Massardo is more robust and provides more functionality. Especially, if you are coordinating between OS & Apps teams and multiple BUs. https://github.com/jmassardo/Chef-Jenkins-Library