Follow

Build and Test Docker Images on CloudShare

Do you work with Jenkins and Docker combined? CloudShare's Jenkins plugin makes it easy to execute Docker commands on dedicated Cloudshare docker-machines, instead of running them on the Jenkins host itself. There is no need to go into CloudShare to provision environments or VMs. It is all done for you.

You'll enjoy several benefits when you start working with this plugin:

  • Each job runs on its own dedicated VM that does the actual building and running of Docker images. This gives you easy parallelization without using Jenkins slaves.

  • You can execute docker-compose based tests without worrying about conflicting published ports. There won't be any collisions, since different jobs will use different VMs. So, it's fine to include the same port bindings in your test scripts as you use when you test locally on your developer machine,.

  •  Since any docker-compose based test runs in isolation on its own VM, you can easily SSH into it and debug a failed test, if needed, without worrying about disturbing/pausing Jenkins itself.

  • There is no need to worry about docker container/image/volume accumulation and cleanup. The VMs are deleted after a configurable expiration period, and your Jenkins host won't get clogged up with obsolete docker files. 

  • CloudShare docker-machines get auto-suspended when the job is idle. We have extended our auto-suspension mechanism to sense when a docker-machine is actually being used. Once no containers are running and nothing is transmitted over the Docker port (TCP:2376) for 15 minutes, CloudShare auto-suspends the environment. It will automatically resume when the job runs again.

  • With the CloudShare plugin enabled, Jenkins uses Docker-Machine to run containers remotely and securely over TCP. So there is no need to mount the docker daemon's socket as a volume and you won't need to run Jenkins as a priviliged container, which is a security concern.

Install

  1. Make sure the following are installed on the Jenkins host (if you do work with Jenkins slaves and you want to continue like that, you'll also need to do this on each slave as well as the master): 

    • Docker (strictly speaking, you just need the binaries, the daemon does not have to be running).

    • Docker-Machine

  2. Install the CloudShare Docker-Machine driver in the Jenkins' PATH.

  3. Install the CloudShare Docker-Machine plug-in through the Jenkins Plugin Manager.

  4. Enter your CloudShare API key and API ID in the global configuration page ("Configure System"). You can obtain your CloudShare API credentials on your user details page.

Enable and Configure

  1. In the project configuration, under Build Environment, check the Run Docker commands on CloudShare VM box. This enables CloudShare docker-machines.

  2. Optionally, in the Machine name field, you can modify the name of the VM that will be provisioned and dedicated to the project. By default, the VM is called jenkins-$JOB_NAME. This default causes one CloudShare VM to be provisioned per Jenkins job.

  3. Optionally, change the expiration period in the Days until VM expires field. By default, the VMs are deleted after 14 days. If you're concerned that even with that automatic deletion, you'll be accumulating too many unused environments over time, you could set it to something shorter. 

Tip

If you change the docker-machine name to jenkins-$JOB_NAME-$EXECUTOR_NUMBER, for example, you would get a separate CloudShare environment and VM per build. This could help you if you have Execute concurrent builds if necessary enabled in the Jenkins job and you don't want concurrent builds to run on the same VM, e.g. because you are publishing host ports during the build.

Pipeline Usage

Any command that you wrap with the cloudshareDockerMachineDSL extension runs on a CloudShare VM, instead of locally:

cloudshareDockerMachine {
  // docker commands
}

For example, in the following pipeline script, the docker-compose command will run against a dedicated CloudShare docker-machine, and not on the Jenkins host itself:

node { stage('build') { git 'https://github.com/cloudshare/express-ws-chat.git' cloudshareDockerMachine { sh 'docker-compose -p ${JOB_NAME} build' } } }

If you want to modify the name of the CloudShare environment that's created for the project, you can specify:

cloudShareDockerMachine(name: 'my-environment') { // docker stuff }

Outside the scope of the cloudshareDockerMachine step, any docker command would run against the local Docker daemon.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk