Best Practices for Dockerfile in repository

17 views
Skip to first unread message

Simon Richter

unread,
Feb 5, 2020, 6:20:11 AM2/5/20
to jenkins...@googlegroups.com
Hi,

Looking at https://jenkins.io/doc/book/pipeline/docker/#dockerfile , I've
set up a repository for our project with a Dockerfile to describe the build
environment, and a simple Jenkinsfile describing the build:

pipeline {
agent {
dockerfile true
}
stages {
stage('Build') {
steps {
sh 'make'
}
}
}
}

To make this build correctly, I had to install Docker CLI inside the
Jenkins container and give Jenkins access to control Docker.

The latter is kind of obvious, and Jenkins already had that access in order
to spawn agents as required, but I'm wondering if it makes sense to require
the Docker CLI, as I have to make sure it is present on whatever agent
builds the project, so the assertion in the documentation that it is only
Windows and MacOS agents that would have trouble running such a pipeline is
a bit bold.

I can certainly work around that, so I'm wondering what is the best
approach:

- continue to build a derived image for Jenkins, adding the Docker CLI as
a statically linked executable, and limit execution of Docker pipelines
to master
- set up a single agent that has the Docker CLI installed, give it an
appropriate label, and use that
- use the Docker cloud plugin to create agents on-demand that have the
Docker CLI installed, and use these to build the pipeline (so a single
build creates two containers).

There was a pull request[1] that eliminates the need for Docker CLI to run
a pipeline with 'agent { dockerfile true }', but it has been closed.

What would be the most sensible option to build a project like this from a
Jenkins instance that is itself running inside a Docker container?

Is there a readymade image of jenkins/jenkins:lts plus the Docker CLI, or
jenkinsci/slave:latest plus the Docker CLI, or do I have to build and
maintain these myself?

Simon

[1] https://github.com/jenkinsci/docker-workflow-plugin/pull/195

Marc Runkel

unread,
Feb 7, 2020, 10:03:13 AM2/7/20
to Jenkins Users
Hey Simon,

We went ahead and built our own..

FROM docker

RUN apk add --no-cache git nodejs npm docker-compose openssh-client && \
    apk add python py-pip py-setuptools git ca-certificates && \
    pip install python-dateutil && \
    git clone https://github.com/s3tools/s3cmd.git /opt/s3cmd && \
    ln -s /opt/s3cmd/s3cmd /usr/bin/s3cmd

COPY ./files/s3cfg /root/.s3cfg

I'm currently working on getting multiple images to work so that we don't have to include stuff like mysql clients and JS building tools in this image but 
that's not working for me.  Hopefully I'll get a response to my earlier message so I can get that working.

m.
Reply all
Reply to author
Forward
0 new messages