libraries/docker.rb
def add_docker_image(image, docker_public_key, memory_limit, memory_swap, cpu_shared)
      # Convert docker image name into something that works as a Groovy variable name
      var_name = image.tr('/:\-.', '_')
      # Convert docker image name into a more sensible jenkins label converting slashes and colons to dashes
      label = "docker-#{image.tr('/:', '-')}"
      <<-EOH
          def #{var_name}_templateBaseParameters = [
            image: '#{image}',
            volumesString: 'ccache:/var/cache/ccache',
            environmentsString: 'JENKINS_SLAVE_SSH_PUBKEY=#{docker_public_key}',
            memoryLimit: #{memory_limit},
            memorySwap: #{memory_swap},
            cpuShares: #{cpu_shared},
            privileged: false,
            tty: false,
          ]
          DockerTemplateBase #{var_name}_TemplateBase = new DockerTemplateBase(#{var_name}_templateBaseParameters.image);
          #{var_name}_templateBaseParameters.findAll{ it.key != "image" }.each { k, v ->
            #{var_name}_TemplateBase."$k" = v
          }
          DockerTemplate dk_#{var_name}_Template = new DockerTemplate(
            #{var_name}_TemplateBase, // dockerTemplateBase
            sshConnector,   // connector
            '#{label}',     // labelString
            '',             // remoteFs
            '50',           // instanceCapStr
          )
          def #{var_name}_privileged_templateBaseParameters = [
            image: '#{image}',
            volumesString: 'ccache:/var/cache/ccache',
            environmentsString: 'JENKINS_SLAVE_SSH_PUBKEY=#{docker_public_key}',
            memoryLimit: #{memory_limit},
            memorySwap: #{memory_swap},
            cpuShares: #{cpu_shared},
            privileged: true,
            tty: false,
          ]
          DockerTemplateBase #{var_name}_privileged_TemplateBase = new DockerTemplateBase(#{var_name}_privileged_templateBaseParameters.image);
          #{var_name}_privileged_templateBaseParameters.findAll{ it.key != "image" }.each { k, v ->
            #{var_name}_privileged_TemplateBase."$k" = v
          }
          DockerTemplate dk_#{var_name}_privileged_Template = new DockerTemplate(
            #{var_name}_privileged_TemplateBase, // dockerTemplateBase
            sshConnector,   // connector
            '#{label}-privileged', // labelString
            '',             // remoteFs
            '50',           // instanceCapStr
          )
          dkTemplates.add(dk_#{var_name}_Template);
          dkTemplates.add(dk_#{var_name}_privileged_Template);

      EOH
    end
# A Groovy snippet that will add new docker images
# @param [String] image name
# @param [String] ssh public key to inject into the image
# @param [Integer] docker memory limit
# @param [Integer] docker memory swap
# @param [Integer] docker cpu shared
A Groovy snippet that will add new docker images
A Groovy snippet that will add new docker images
def add_docker_image(image, docker_public_key, memory_limit, memory_swap, cpu_shared)
      var_name = image.tr('/:\-.', '_')
      label = "docker-#{image.tr('/:', '-')}"
      <<-EOH
          def #{var_name}_templateBaseParameters = [
            image: '#{image}',
            volumesString: 'ccache:/var/cache/ccache',
            environmentsString: 'JENKINS_SLAVE_SSH_PUBKEY=#{docker_public_key}',
            memoryLimit: #{memory_limit},
            memorySwap: #{memory_swap},
            cpuShares: #{cpu_shared},
            privileged: false,
            tty: false,
          ]
          DockerTemplateBase #{var_name}_TemplateBase = new DockerTemplateBase(#{var_name}_templateBaseParameters.image);
          #{var_name}_templateBaseParameters.findAll{ it.key != "image" }.each { k, v ->
            #{var_name}_TemplateBase."$k" = v
          }
          DockerTemplate dk_#{var_name}_Template = new DockerTemplate(
            #{var_name}_TemplateBase, // dockerTemplateBase
            sshConnector,   // connector
            '#{label}',     // labelString
            '',             // remoteFs
            '50',           // instanceCapStr
          )
          def #{var_name}_privileged_templateBaseParameters = [
            image: '#{image}',
            volumesString: 'ccache:/var/cache/ccache',
            environmentsString: 'JENKINS_SLAVE_SSH_PUBKEY=#{docker_public_key}',
            memoryLimit: #{memory_limit},
            memorySwap: #{memory_swap},
            cpuShares: #{cpu_shared},
            privileged: true,
            tty: false,
          ]
          DockerTemplateBase #{var_name}_privileged_TemplateBase = new DockerTemplateBase(#{var_name}_privileged_templateBaseParameters.image);
          #{var_name}_privileged_templateBaseParameters.findAll{ it.key != "image" }.each { k, v ->
            #{var_name}_privileged_TemplateBase."$k" = v
          }
          DockerTemplate dk_#{var_name}_privileged_Template = new DockerTemplate(
            #{var_name}_privileged_TemplateBase, // dockerTemplateBase
            sshConnector,   // connector
            '#{label}-privileged', // labelString
            '',             // remoteFs
            '50',           // instanceCapStr
          )
          dkTemplates.add(dk_#{var_name}_Template);
          dkTemplates.add(dk_#{var_name}_privileged_Template);
      EOH
    end
def add_docker_image ( image , docker_public_key , memory_limit , memory_swap , cpu_shared ) var_name = image . tr ( '/:\-.' , '_' ) label = "docker-#{image.tr('/:', '-')}" <<-EOH 
          def  #{ var_name } _templateBaseParameters = [
            image: ' #{ image } ',
            volumesString: 'ccache:/var/cache/ccache',
            environmentsString: 'JENKINS_SLAVE_SSH_PUBKEY= #{ docker_public_key } ',
            memoryLimit:  #{ memory_limit } ,
            memorySwap:  #{ memory_swap } ,
            cpuShares:  #{ cpu_shared } ,
            privileged: false,
            tty: false,
          ]
          DockerTemplateBase  #{ var_name } _TemplateBase = new DockerTemplateBase( #{ var_name } _templateBaseParameters.image);
           #{ var_name } _templateBaseParameters.findAll{ it.key != "image" }.each { k, v ->
             #{ var_name } _TemplateBase."$k" = v
          }
          DockerTemplate dk_ #{ var_name } _Template = new DockerTemplate(
             #{ var_name } _TemplateBase, // dockerTemplateBase
            sshConnector,   // connector
            ' #{ label } ',     // labelString
            '',             // remoteFs
            '50',           // instanceCapStr
          )
          def  #{ var_name } _privileged_templateBaseParameters = [
            image: ' #{ image } ',
            volumesString: 'ccache:/var/cache/ccache',
            environmentsString: 'JENKINS_SLAVE_SSH_PUBKEY= #{ docker_public_key } ',
            memoryLimit:  #{ memory_limit } ,
            memorySwap:  #{ memory_swap } ,
            cpuShares:  #{ cpu_shared } ,
            privileged: true,
            tty: false,
          ]
          DockerTemplateBase  #{ var_name } _privileged_TemplateBase = new DockerTemplateBase( #{ var_name } _privileged_templateBaseParameters.image);
           #{ var_name } _privileged_templateBaseParameters.findAll{ it.key != "image" }.each { k, v ->
             #{ var_name } _privileged_TemplateBase."$k" = v
          }
          DockerTemplate dk_ #{ var_name } _privileged_Template = new DockerTemplate(
             #{ var_name } _privileged_TemplateBase, // dockerTemplateBase
            sshConnector,   // connector
            ' #{ label } -privileged', // labelString
            '',             // remoteFs
            '50',           // instanceCapStr
          )
          dkTemplates.add(dk_ #{ var_name } _Template);
          dkTemplates.add(dk_ #{ var_name } _privileged_Template);

       EOH end
A Groovy snippet that will add new docker images
A Groovy snippet that will add new docker images
# Convert docker image name into something that works as a Groovy variable name # Convert docker image name into a more sensible jenkins label converting slashes and colons to dashes
image
docker_public_key
memory_limit
memory_swap
cpu_shared
docker cpu shared
docker cpu shared