Code Monkey home page Code Monkey logo

cloudshare-docker-plugin's Introduction

CloudShare Docker-Machine Jenkins Plugin

Using CloudShare's Jenkins plugin you can have you Docker builds run on dedicated docker-machines on CloudShare, instead of running on the Jenkins host itself.

Motivation

By using a dedicated docker-machine for each Jenkins project you enjoy the following benefits:

  • Each project gets its own dedicated VM that does the actual building & running of docker images. In other words, you get easy parallelization without using Jenkins slaves.
  • You can execute docker-compose based tests without worrying about conflicting published ports.
    • 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.
  • No need to worry about docker container/image/volume accumulation and cleanup. The VMs are disposable, and your Jenkins host won't get clogged up with obsolete docker files.
  • CloudShare VMs automatically get suspended after there's no more docker activity. You don't need to worry about shutting down slaves when they're not needed to cut costs.
  • If your Jenkins actually run in a container, you won't 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.

Installing

Requirements

  • Docker (strictly speaking, you just need the binaries, the daemon does not have to be running).
  • Docker-Machine.
  • CloudShare docker-machine driver must be installed and in Jenkins' PATH.
    • If you are using Jenkins slaves, make sure the above is installed on all of them, as well as the master node.

Install this plugin through the Jenkins Plugin Manager.

Configuration

Once the plugin is installed, enter your CloudShare API key & ID in the global configuration page ("Configure System").

plugin configuration screenshot

You can obtain the API key in your details page on CloudShare.

Usage

You can enable CloudShare docker-machines for your builds both in classic projects (under Build Environment) and as a pipeline step.

Build Environment

In your Jenkins project's configuration, under Build Environment, check the Run Docker commands on CloudShare VM box.

build environment screenshot

You can leave the default machine name template as is.

Now every build step that invokes docker (build, run, docker-compose, etc.) will run against a remote CloudShare docker-machine automatically.

Pipeline Step

Another way of achieving the same effect is with the cloudshareDockerMachine DSL step.

For example, in this pipeline script:

node {
    stage('build') {
        git 'https://github.com/cloudshare/express-ws-chat.git'

        cloudshareDockerMachine {
            sh 'docker-compose -p ${JOB_NAME} build'
        }
    }
}

The docker-compose command will run against a dedicated CloudShare docker-machine, and not on the Jenkins host itself.

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.

A note about concurrent builds

The default docker-machine name is jenkins-$JOB_NAME, which means there will be one CloudShare environment per Jenkins job. If you have enabled Execute concurrent builds if necessary in your Jenkins job, be aware that concurrent builds will run on the same CloudShare VM. If this is a problem for you (e.g. you are publishing host ports during the build), consider changing the docker-machine name to something like jenknis-$JOB_NAME-$EXECUTOR_NUMBER, to achieve complete isolation. However, this has the disadvantage of using multiple environments to uild the same job, thus incurring more Docker layer cache misses and slower builds. Another solution would be to avoid publishing container ports to the host, for example by using named networks in Docker-Compose, where the project name contains the build number.

Cleanup

When a dedicated environment is created per job, you might find yourself accumulating unused environments over time. However, CloudShare environments have a default policy that governs how long they persist. By default environments will be deleted after 14 days. So environment accumulation is not a huge concern, after all.

You can override the default policy for docker-machine environments, if you wish. For example, if you want VMs to hang around for at most 3 days, instead of 14, you can configure the expiry in the project settings (or using the pipeline syntax).

expiry screenshot

cloudshare-docker-plugin's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

anjilinux

cloudshare-docker-plugin's Issues

deleting unused VMs

The plugin currently creates/starts VMs for jobs that use it, but these VMs (by default) hang around for 2 weeks before they are expired by CloudShare. This of course depends on the user's CloudShare policy WRT expiration.

For a lot of Jenkins usage scenarios, it makes sense to "collect" (delete, expire) VMs more frequently than that. 2 weeks is enough time to accumulate a whole bunch of unused VMs, and the user might reach her account cap quite quickly.

Possible solutions:

  1. The plugin can have an extra parameter expiry-days, and define its own policy behind the scenes to collect any job's VM, say, after 24h. (any subsequent builds will just launch a replacement VM, so it's just some added build duration once a day - probably not a huge issue).
    1. This also helps fight image/container accumulation, and negates the need to run prune periodically.
  2. The user can change the default policy herself; or the plugin could accept an additional parameter for which policy to use.
  3. The plugin can (?) detect when a job is deleted and delete the corresponding VM. Not entirely sure if possible to do in a plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.