Run Jenkins by Kubernetes, we use an official image (https://hub.docker.com/u/jenkins/) but customize it to install the following applications on it:
- Docker CE
- kubectl binary
- Jenkins Docker plugin
To do that, prepare Dockerfile to maintain your own Jenkins image:
$ cat Dockerfile
FROM jenkins/jenkins:lts
EXPOSE 8080 50000
# install Docker CE for Debian : https://docs.docker.com/engine/installation/linux/docker-ce/debian/
USER root
RUN apt-get update
RUN apt-get install -y sudo apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y docker-ce
# install kubectl binary
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.2/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin/kubectl
# setup Jenkins plubins : https://github.com/jenkinsci/docker#script-usage
RUN /usr/local/bin/install-plugins.sh docker
Use docker build to build your Jenkins image and then docker push command to upload to your own registry in Docker hub, as shown:
//build your own Jenkins image
$ docker build -t <your-docker-hub-account>/my-jenkins .
//push to Docker Hub
$ docker push <your-docker-hub-account>/my-jenkins
Or, alternatively, you could upload that to your private registry or any other cloud-provided registry.
Hurray! We have our build system image ready now.