The tutorial for this makefile can be found here: http://engineering.riotgames.com/news/building-jenkins-inside-ephemeral-docker-container

Ephemeral Build Slaves using Jenkins and Docker

This tutorial contains all the files necessary to create your own local Docker-Toolbox version of a fully ephemeral jenkins environment. Build slaves are designed to be docker containers in this configuration. The only thing missing to make it work is your Docker Machine certs (see directions below on how to add these).

Quick Start

Ideally you'll follow along with the entire blog series. However if you'd like to get this up and running as quickly as possible here's the steps you need to do:

  1. Make sure you have all the pre-reqs installed (i.e. Docker-toolbox)
  2. Clone this repository to your local drive
  3. Find the docker-machine folder container your 4 client pem keys (ca-key.pem, ca.pem, key.pem, cert.pem). Mine for example, is in ~/.docker/machine/certs.
  4. cp -R yourdockermachinecertsfolder jenkins-master/certs
  5. make build
  6. make run
  7. Point your browser to http://yourdockermachineip
  8. In jenkins, configure a ssh-key pair using an ssh private key for the user "jenkins". As the private key, use the file in jenkins-slave/files/dummy_private_rsa_key
  9. In jenkins, configure a Docker Certificates Directory credential using /usr/local/etc/jenkins/certs as the source directory
  10. In jenkins configuration, add a new Docker cloud provider
  11. Set host to https://yourdockermachineip:2376
  12. Select the docker certificates directory you made
  13. Set read timeout to 5
  14. set connection timeout to 15
  15. Click on "Test COnnection" and make sure you get a valid response
  16. In jenkins config on your new Docker cloud add a Docker template
  17. Set the image name to: jenkins_slave
  18. Create a label "testslave"
  19. Make sure credentials are your new ssh key pair you made above
  20. Click "Save"
  21. Create a new free-style jenkins job
  22. Restrict the job to the label "testslave"
  23. Add a build step, like execute shell "echo 'Hello World!'"
  24. Save job
  25. Run job

If everything is configured correctly your job should dynamically allocate a slave, run itself and then de-allocate the slave.