Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Forked from tobstarr/Dockerfile
Created August 3, 2013 19:30
Show Gist options
  • Save jamtur01/6147676 to your computer and use it in GitHub Desktop.
Save jamtur01/6147676 to your computer and use it in GitHub Desktop.

Jenkins for go projects with docker

Clone this gist

Build docker image

cat Dockerfile | docker build -t jenkins -

Start Jenkins

mkdir -p /git /data/jenkins/jobs
id=$(docker run -v /git:/git -v /data/jenkins/jobs:/data/jenkins/jobs -d jenkins)
echo "jenkins running in container $id listening on port $(docker port $id 8080)"

Setup a git repository for the project

mkdir -p /git/golang_project.git
cd /git/golang_project.git && git init --bare

Create Jenkins Job

Jenkins is bound to the port specified in jenkins running in container.

Use /git/golang_project.git as your git repository

Use this as Execute shell task:

#!/bin/bash
set -e

make test
make

Enable build artifacts in Post-build Actions. Use bin/* as pattern. Obviously you should place your go binaries in bin/ when building.

Push into repository

git remote add build <user>@<serverip>:/git/golang_project.git
git push build master

Trigger build in Jenkins

Click on Build Now in Jenkins.

Next Steps

  • Enable SCM polling
  • Create a post commit hook
FROM ubuntu:12.04
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-6-jdk curl git-core build-essential bzr
RUN mkdir -p /tmp/downloads
# install go
RUN curl -sf -o /tmp/downloads/go1.1.1.linux-amd64.tar.gz -L https://go.googlecode.com/files/go1.1.1.linux-amd64.tar.gz
RUN mkdir -p /opt && cd /opt && tar xfz /tmp/downloads/go1.1.1.linux-amd64.tar.gz
# install jenkins
RUN curl -sf -o /opt/jenkins-1.523.war -L http://mirrors.jenkins-ci.org/war/1.523/jenkins.war
# install plugins
RUN mkdir -p /data/jenkins/plugins
RUN curl -sf -o /data/jenkins/plugins/chucknorris.hpi -L http://mirrors.jenkins-ci.org/plugins/chucknorris/latest/chucknorris.hpi
RUN curl -sf -o /data/jenkins/plugins/greenballs.hpi -L http://mirrors.jenkins-ci.org/plugins/greenballs/latest/greenballs.hpi
RUN curl -sf -o /data/jenkins/plugins/git-client.hpi -L http://mirrors.jenkins-ci.org/plugins/git-client/latest/git-client.hpi
RUN curl -sf -o /data/jenkins/plugins/git.hpi -L http://mirrors.jenkins-ci.org/plugins/git/latest/git.hpi
# env stuff
ENV JENKINS_HOME /data/jenkins
ENV GOROOT /opt/go
ENV GOPATH /root/gocode
ENV PATH /opt/go/bin:/root/gocode/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
EXPOSE 8080
CMD cd /opt && java -jar jenkins-1.523.war
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment