Skip to content

Create a Python-friendly GoCD Agent in Docker

November 10th, 2017 - ITTutorial

I’ve got two requirements to make GoCD useful:

  1. Run both the server and agent(s) in Docker
  2. Make it python-friendly

Fortunately, GoCD offers Docker images (and Dockerfiles) for both, so it’s just a matter of extending it:

FROM gocd/gocd-agent-ubuntu-16.04:v17.11.0

# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
        tcl \
        tk \
        python2.7 \
        wget \
        apt-utils \
        build-essential \
        libssl-dev libffi-dev python2.7-dev \
    && rm -rf /var/lib/apt/lists/*

Unfortunately, pip is not quite adequate, so we re-install it from source. In the Dockerfile we add:

RUN \
    apt-get remove python-pip python3-pip \
# Install a newer version of pip
    ; wget https://bootstrap.pypa.io/get-pip.py \
    && python get-pip.py \
    && /usr/local/bin/pip install virtualenv

Now we have a fully functional Docker file capable of building python applications and we can actually build the image. In the directory where we have the Dockerfile, execute:

docker build -t gocd-python:1 .

Then, you can run it with:

docker run -d -e GO_SERVER_URL=https://192.168.99.100:8154/go gocd-python:1

I’m using 192.168.99.100:8154 because I’m running on my local machine for testing. You’ll probably need to replace the address.

Note: If you’re behind proxy, you can use my docker_build and docker_run aliases.

Full DockerFile

The full Dockerfile is:

FROM gocd/gocd-agent-ubuntu-16.04:v17.11.0

# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
        tcl \
        tk \
        python2.7 \
        wget \
        apt-utils \
        build-essential \
        libssl-dev libffi-dev python2.7-dev \
    && rm -rf /var/lib/apt/lists/*

RUN \
    apt-get remove python-pip python3-pip \
# Install a newer version of pip
    ; wget https://bootstrap.pypa.io/get-pip.py \
    && python get-pip.py \
    && /usr/local/bin/pip install virtualenv

HTH,

Share on
Reddit
Linked in
Whatsapp

A little experiment: