Skip to content

Commit 9a1a7f3

Browse files
committed
Adding persistant JENKINS_HOME support
1 parent 3872da1 commit 9a1a7f3

File tree

5 files changed

+111
-12
lines changed

5 files changed

+111
-12
lines changed

mesos/jenkins/Dockerfile

-3
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

+1-1
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/connect-slave.sh

+1-1
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

+21-7
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,30 @@ 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_PERSISTANT_JENKINS_HOME" == "x" ]; then
30+
rm -f $JENKINS_HOME/.USE_PERSISTANT_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+
else
36+
if [ ! -f $JENKINS_HOME/.USE_PERSISTANT_JENKINS_HOME ]; then
37+
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
38+
find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
39+
sed -i "s#\${JENKINS_CONFIG_REPO}#$JENKINS_CONFIG_REPO#g" $JENKINS_HOME/scm-sync-configuration.xml
40+
cp -R $MESOS_SANDBOX/.ssh $JENKINS_HOME/.ssh
41+
touch $JENKINS_HOME/.USE_PERSISTANT_JENKINS_HOME
42+
fi
43+
fi
44+
if [ [ ! -f $JENKINS_HOME/.gitconfig ] -a [ -f $JENKINS_HOME/gitconfig ] ]; then
45+
mv -f $JENKINS_HOME/gitconfig $JENKINS_HOME/.gitconfig
46+
fi
3347

3448
# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
3549
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
3650
eval "exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS \"\$@\""
37-
fi
38-
51+
else
3952
# As argument is not jenkins, assume user want to run his own process, for sample a `bash` shell to explore this image
40-
exec "$@"
53+
exec "$@"
54+
fi
+88
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+
"10.0.24.35"
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": 31325,
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-home" }
48+
]
49+
}
50+
},
51+
"env": {
52+
"JENKINS_CONFIG_REPO": "jbrisbin/jenkins-mesos-softlayer",
53+
"JENKINS_OPTS": "--prefix=/jenkins",
54+
"USE_PERSISTANT_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)