Skip to content

Commit 20780aa

Browse files
committed
Adding persistant JENKINS_HOME support
1 parent 3872da1 commit 20780aa

File tree

6 files changed

+125
-12
lines changed

6 files changed

+125
-12
lines changed

mesos/jenkins/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ RUN chmod a+x /usr/local/bin/connect-slave.sh
5757
COPY jenkins.sh /usr/local/bin/jenkins.sh
5858
RUN chmod a+x /usr/local/bin/jenkins.sh
5959

60-
COPY gitconfig $JENKINS_HOME/.gitconfig
61-
RUN chown jenkins:jenkins $JENKINS_HOME/.gitconfig
62-
6360
ENV REF_DIR /usr/share/jenkins/ref
6461
ADD defaults.tgz $REF_DIR
6562
COPY plugins.txt $REF_DIR/

mesos/jenkins/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MARATHON ?= localhost:8080
77
.PHONY = install push deploy clean
88

99
defaults.tgz:
10-
tar zcvf $(@) *.xml init.groovy.d/
10+
tar zcvf $(@) *.xml gitconfig init.groovy.d/
1111

1212
install: defaults.tgz
1313
docker build -t $(TAG) .

mesos/jenkins/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
12
# Jenkins on Mesos
23

34
Jenkins is deployed on Mesos using a Docker image deployed through Marathon. The image contains some basic configuration and an init script that produces a fully-functioning server, including connected build slaves, OOTB.
45

6+
## Running localy on marathon 127.0.0.1
7+
8+
Run ```make deploy```
9+
10+
## Running on remote marathon (other than 127.0.0.1)
11+
12+
As soon as a jenkins installation with all required plugins can crash sometimes, and running on remote marathon leades to unPERSISTENT jenkins home directory. To make the system tolerant to jenkins restart several tricks should apply.
13+
14+
1 Edit ```marathon-remote.json.example``` to replace {{PERSISTENT_SLAVE_IP}} with IP of the mesos slave to use.
15+
2 Edit ```marathon-remote.json.example``` to replace {{PERSISTENT_SLAVE_PORT}} with port number you want to use to mke URL PERSISTENT.
16+
3 Connect with ssh to the slave you want to use for jenkins and create data only container ```jenkins-data``` with ```docker run -d -v /home/jenkins_home:/var/jenkins_home --name=jenkins-data --entrypoint=/bin/echo alpine "jenkins data-only container"```
17+
4 Edit ```marathon-remote.json.example``` to replace {{JENKINS_DATA_CONTAINER}} with jenkins-data
18+
5 Replace ```marathon.json``` with ```marathon-remote.json.example```
19+
520
### Building the image
621

722
First check out the source from GitHub so you can modify the base config to suit your deployment scenario:

mesos/jenkins/connect-slave.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
curl -sSL -XPOST -H "Content-Type: application/json" -d @- "http://marathon.mesos:8080/v2/apps" <<END
33
{
4-
"id": "/jenkins/build/$3",
4+
"id": "/jenkins/slaves/$3",
55
"cpus": 1,
66
"mem": 8192,
77
"instances": 1,

mesos/jenkins/jenkins.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,29 @@ copy_reference_file() {
2525
: ${JENKINS_HOME:="/var/jenkins_home"}
2626
export -f copy_reference_file
2727
touch "${COPY_REFERENCE_FILE_LOG}" || (echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?" && exit 1)
28-
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
29-
find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
3028

31-
sed -i "s#\${JENKINS_CONFIG_REPO}#$JENKINS_CONFIG_REPO#g" $JENKINS_HOME/scm-sync-configuration.xml
32-
cp -R $MESOS_SANDBOX/.ssh $JENKINS_HOME/.ssh
29+
if [ "x$USE_PERSISTENT_JENKINS_HOME" == "x" ]; then
30+
rm -f $JENKINS_HOME/.USE_PERSISTENT_JENKINS_HOME
31+
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
32+
find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
33+
sed -i "s#\${JENKINS_CONFIG_REPO}#$JENKINS_CONFIG_REPO#g" $JENKINS_HOME/scm-sync-configuration.xml
34+
cp -R $MESOS_SANDBOX/.ssh $JENKINS_HOME/.ssh
35+
elif [ ! -f $JENKINS_HOME/.USE_PERSISTENT_JENKINS_HOME ]; then
36+
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
37+
find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
38+
sed -i "s#\${JENKINS_CONFIG_REPO}#$JENKINS_CONFIG_REPO#g" $JENKINS_HOME/scm-sync-configuration.xml
39+
cp -R $MESOS_SANDBOX/.ssh $JENKINS_HOME/.ssh
40+
touch $JENKINS_HOME/.USE_PERSISTENT_JENKINS_HOME
41+
fi
42+
43+
if [ [ ! -f $JENKINS_HOME/.gitconfig ] -a [ -f $JENKINS_HOME/gitconfig ] ]; then
44+
mv -f $JENKINS_HOME/gitconfig $JENKINS_HOME/.gitconfig
45+
fi
3346

3447
# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
3548
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
3649
eval "exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS \"\$@\""
37-
fi
38-
50+
else
3951
# As argument is not jenkins, assume user want to run his own process, for sample a `bash` shell to explore this image
40-
exec "$@"
52+
exec "$@"
53+
fi
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"id": "/jenkins/master",
3+
"cmd": null,
4+
"cpus": 2,
5+
"mem": 4096,
6+
"disk": 0,
7+
"instances": 1,
8+
"constraints": [
9+
[
10+
"hostname",
11+
"CLUSTER",
12+
"{{PERSISTENT_SLAVE_IP}}"
13+
]
14+
],
15+
"container": {
16+
"type": "DOCKER",
17+
"volumes": [
18+
{
19+
"containerPath": "/var/run/docker.sock",
20+
"hostPath": "/var/run/docker.sock",
21+
"mode": "RW"
22+
}
23+
],
24+
"docker": {
25+
"image": "jenkins-mesos-local",
26+
"network": "BRIDGE",
27+
"portMappings": [
28+
{
29+
"containerPort": 8080,
30+
"hostPort": {{PERSISTENT_SLAVE_PORT}},
31+
"servicePort": 10002,
32+
"protocol": "tcp",
33+
"labels": {}
34+
},
35+
{
36+
"containerPort": 0,
37+
"hostPort": 0,
38+
"servicePort": 10003,
39+
"protocol": "tcp",
40+
"labels": {}
41+
}
42+
],
43+
"privileged": true,
44+
"parameters": [],
45+
"forcePullImage": false,
46+
"parameters": [
47+
{ "key": "volumes-from", "value": "{{JENKINS_DATA_CONTAINER}}" }
48+
]
49+
}
50+
},
51+
"env": {
52+
"JENKINS_CONFIG_REPO": "jbrisbin/jenkins-mesos-softlayer",
53+
"JENKINS_OPTS": "--prefix=/jenkins",
54+
"USE_PERSISTENT_JENKINS_HOME": "yes"
55+
},
56+
"healthChecks": [
57+
{
58+
"path": "/jenkins/",
59+
"protocol": "HTTP",
60+
"portIndex": 0,
61+
"gracePeriodSeconds": 300,
62+
"intervalSeconds": 300,
63+
"timeoutSeconds": 300,
64+
"maxConsecutiveFailures": 25,
65+
"ignoreHttp1xx": false
66+
}
67+
],
68+
"portDefinitions": [
69+
{
70+
"port": 10002,
71+
"protocol": "tcp",
72+
"labels": {}
73+
},
74+
{
75+
"port": 10003,
76+
"protocol": "tcp",
77+
"labels": {}
78+
}
79+
],
80+
"fetch": [
81+
{
82+
"uri": "file:///home/jenkins/ssh.tar.gz",
83+
"extract": true,
84+
"executable": false,
85+
"cache": false
86+
}
87+
]
88+
}

0 commit comments

Comments
 (0)