Skip to content

Commit 81053c0

Browse files
committed
Added support for jenkins official container
1 parent 7b9ec17 commit 81053c0

26 files changed

Lines changed: 1459 additions & 0 deletions

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,19 @@ services:
513513
- proxy
514514
- proxy2
515515

516+
### Jenkins ###################################################
517+
jenkins:
518+
build: ./jenkins
519+
environment:
520+
JAVA_OPTS: "-Djava.awt.headless=true"
521+
ports:
522+
- "${JENKINS_HOST_SLAVE_AGENT_PORT}:50000"
523+
- "${JENKINS_HOST_HTTP_PORT}:8080"
524+
privileged: true
525+
volumes:
526+
- ${JENKINS_HOME}:/var/jenkins_home
527+
- /var/run/docker.sock:/var/run/docker.sock
528+
516529
### Networks Setup ############################################
517530

518531
networks:

env-example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ VARNISH_PROXY2_SERVER=SERVER2
145145
### HAPROXY Container
146146
HAPROXY_HOST_HTTP_PORT=8085
147147

148+
### JENKINS Container
149+
JENKINS_HOST_HTTP_PORT=8090
150+
JENKINS_HOST_SLAVE_AGENT_PORT=50000
151+
JENKINS_HOME=./jenkins/jenkins_home
152+
148153
### MISC
149154
# Replace with your Docker Host IP (will be appended to /etc/hosts)
150155
DOCKER_HOST_IP=10.0.75.1

jenkins/.github/ISSUE_TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Issues and Contributing
2+
3+
Please note that only issues related to this Docker image will be addressed here.
4+
5+
* If you have Docker related issues, please ask in the [Docker user mailing list](https://groups.google.com/forum/#!forum/docker-user).
6+
* If you have Jenkins related issues, please ask in the [Jenkins mailing lists](https://jenkins-ci.org/content/mailing-lists).
7+
* If you are not sure, then this is probably not the place to create an issue and you should use any of the previously mentioned mailing lists.
8+
9+
If after going through the previous checklist you still think you should create an issue here please provide:
10+
11+
12+
### Docker commands that you execute
13+
14+
### Actual result
15+
16+
### Expected outcome
17+
18+
### Have you tried a non-dockerized Jenkins and get the expected outcome?
19+
20+
### Output of `docker version`
21+
22+
### Other relevant information
23+

jenkins/.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "tests/test_helper/bats-support"]
2+
path = tests/test_helper/bats-support
3+
url = https://github.com/ztombol/bats-support
4+
[submodule "tests/test_helper/bats-assert"]
5+
path = tests/test_helper/bats-assert
6+
url = https://github.com/ztombol/bats-assert

jenkins/CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Issues and Contributing
2+
3+
Please note that only issues related to this Docker image will be addressed here.
4+
5+
* If you have Docker related issues, please ask in the [Docker user mailing list](https://groups.google.com/forum/#!forum/docker-user).
6+
* If you have Jenkins related issues, please ask in the [Jenkins mailing lists](https://jenkins-ci.org/content/mailing-lists).
7+
* If you are not sure, then this is probably not the place to create an issue and you should use any of the previously mentioned mailing lists.
8+
9+
If after going through the previous checklist you still think you should create an issue here please provide:
10+
11+
* Docker commands that you execute
12+
* Actual result
13+
* Expected outcome
14+
* Have you tried a non-dockerized Jenkins and get the expected outcome?
15+
* Output of `docker version`
16+
* Other relevant information

jenkins/Dockerfile

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
FROM openjdk:8-jdk
2+
3+
RUN apt-get update && apt-get install -y git curl && rm -rf /var/lib/apt/lists/*
4+
5+
ENV JENKINS_HOME /var/jenkins_home
6+
ENV JENKINS_SLAVE_AGENT_PORT 50000
7+
8+
ARG user=jenkins
9+
ARG group=jenkins
10+
ARG uid=1000
11+
ARG gid=1000
12+
13+
# Jenkins is run with user `jenkins`, uid = 1000
14+
# If you bind mount a volume from the host or a data container,
15+
# ensure you use the same uid
16+
RUN groupadd -g ${gid} ${group} \
17+
&& useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -m -s /bin/bash ${user}
18+
19+
# Jenkins home directory is a volume, so configuration and build history
20+
# can be persisted and survive image upgrades
21+
VOLUME /var/jenkins_home
22+
23+
# `/usr/share/jenkins/ref/` contains all reference configuration we want
24+
# to set on a fresh new installation. Use it to bundle additional plugins
25+
# or config file with your custom jenkins Docker image.
26+
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
27+
28+
ENV TINI_VERSION 0.13.2
29+
ENV TINI_SHA afbf8de8a63ce8e4f18cb3f34dfdbbd354af68a1
30+
31+
# Use tini as subreaper in Docker container to adopt zombie processes
32+
RUN curl -fsSL https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini && chmod +x /bin/tini \
33+
&& echo "$TINI_SHA /bin/tini" | sha1sum -c -
34+
35+
COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy
36+
37+
# jenkins version being bundled in this docker image
38+
ARG JENKINS_VERSION
39+
ENV JENKINS_VERSION ${JENKINS_VERSION:-2.32.3}
40+
41+
# jenkins.war checksum, download will be validated using it
42+
ARG JENKINS_SHA=a25b9a314ca9e76f9673da7309e1882e32674223
43+
44+
# Can be used to customize where jenkins.war get downloaded from
45+
ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
46+
47+
# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
48+
# see https://github.com/docker/docker/issues/8331
49+
RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
50+
&& echo "${JENKINS_SHA} /usr/share/jenkins/jenkins.war" | sha1sum -c -
51+
52+
ENV JENKINS_UC https://updates.jenkins.io
53+
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
54+
55+
56+
# Add jenkins to the correct group
57+
# see http://stackoverflow.com/questions/42164653/docker-in-docker-permissions-error
58+
# use "getent group docker | awk -F: '{printf "%d\n", $3}'" command on host to find correct value for gid or simply use 'id'
59+
ARG DOCKER_GID=998
60+
61+
RUN groupadd -g ${DOCKER_GID} docker \
62+
&& curl -sSL https://get.docker.com/ | sh \
63+
&& apt-get -q autoremove \
64+
&& apt-get -q clean -y \
65+
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*.bin
66+
67+
# Install Docker-in-Docker from git@github.com:jpetazzo/dind.git
68+
# RUN apt-get update -qq && apt-get install -qqy apt-transport-https ca-certificates curl lxc iptables
69+
# Install Docker from Docker Inc. repositories.
70+
RUN apt-get install -y curl && curl -sSL https://get.docker.com/ | sh
71+
RUN usermod -aG docker jenkins
72+
73+
# Install Docker-Compose
74+
RUN curl -L "https://github.com/docker/compose/releases/download/1.10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
75+
RUN chmod +x /usr/local/bin/docker-compose
76+
77+
78+
# for main web interface:
79+
EXPOSE 8080
80+
81+
# will be used by attached slave agents:
82+
EXPOSE 50000
83+
84+
ENV COPY_REFERENCE_FILE_LOG $JENKINS_HOME/copy_reference_file.log
85+
86+
USER ${user}
87+
88+
COPY jenkins-support /usr/local/bin/jenkins-support
89+
COPY jenkins.sh /usr/local/bin/jenkins.sh
90+
ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"]
91+
92+
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
93+
COPY plugins.sh /usr/local/bin/plugins.sh
94+
COPY install-plugins.sh /usr/local/bin/install-plugins.sh
95+
96+
# Only need below if we are starting from empty jenkins_home
97+
## Copy the RSA keys
98+
#RUN mkdir -p /var/jenkins_home/.ssh
99+
#RUN chown jenkins:jenkins /var/jenkins_home/.ssh
100+
#COPY keys/id_rsa /var/jenkins_home/.ssh/id_rsa.pub
101+
#COPY keys/id_rsa /var/jenkins_home/.ssh/id_rsa
102+
#COPY keys/known_hosts /var/jenkins_home/.ssh/known_hosts
103+
#
104+
#USER root
105+
#RUN chmod 600 /var/jenkins_home/.ssh/id_rsa
106+
#RUN chmod 644 /var/jenkins_home/.ssh/id_rsa.pub
107+
## ssh-keyscan -H github.com >> ~/.ssh/known_hosts
108+
## ssh-keyscan -H bitbucket.org >> ~/.ssh/known_hosts

jenkins/Jenkinsfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env groovy
2+
3+
properties([
4+
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5')),
5+
pipelineTriggers([cron('@daily')]),
6+
])
7+
8+
node('docker') {
9+
deleteDir()
10+
11+
stage('Checkout') {
12+
checkout scm
13+
}
14+
15+
if (!infra.isTrusted()) {
16+
/* Outside of the trusted.ci environment, we're building and testing
17+
* the Dockerful in this repository, but not publishing to docker hub
18+
*/
19+
stage('Build') {
20+
docker.build('jenkins')
21+
}
22+
23+
stage('Test') {
24+
sh """
25+
git submodule update --init --recursive
26+
git clone https://github.com/sstephenson/bats.git
27+
bats/bin/bats tests
28+
"""
29+
}
30+
} else {
31+
/* In our trusted.ci environment we only want to be publishing our
32+
* containers from artifacts
33+
*/
34+
stage('Publish') {
35+
sh './publish.sh'
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)