Skip to content

Instantly share code, notes, and snippets.

@juniorz
Last active December 28, 2015 11:39
Show Gist options
  • Save juniorz/7494802 to your computer and use it in GitHub Desktop.
Save juniorz/7494802 to your computer and use it in GitHub Desktop.
Jenkins
# -------------------------------------------------------------------
# docker build -t juniorz/jenkins git://gist.github.com/7494802.git
# -------------------------------------------------------------------
FROM phusion/baseimage:0.9.1
MAINTAINER Reinaldo Junior <juniorz@gmail.com>
RUN apt-get update && apt-get upgrade -y
# Remove authentication rights for insecure_key.
RUN echo /bin/sh -c \"rm -f /root/.ssh/authorized_keys /home/*/.ssh/authorized_keys\" > /sbin/remove_authorized_keys &&\
chmod 0700 /sbin/remove_authorized_keys
# To remove the key, run:
# curl https://raw.github.com/phusion/baseimage-docker/master/image/insecure_key |\
# ssh -i /dev/stdin root@$(docker inspect $CID | grep IPAddress | cut -d '"' -f 4) /sbin/remove_authorized_keys
# Set correct environment variables.
ENV HOME /root
# Installs jenkins (http://pkg.jenkins-ci.org/debian/)
# - `RUNLEVEL=1` prevents the init.d service to start (http://askubuntu.com/a/75560)
# - `LC_ALL=en_US.UTF-8` and `DEBIAN_FRONTEND=noninteractive` provide defaults to unattended installation
RUN curl http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add - &&\
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list &&\
apt-get update -y &&\
mkdir -p /var/lib/jenkins /var/run/jenkins &&\
export LC_ALL=en_US.UTF-8 DEBIAN_FRONTEND=noninteractive RUNLEVEL=0 &&\
apt-get install -y --no-install-recommends jenkins
# Disables init
RUN /etc/init.d/jenkins stop &&\
update-rc.d -f jenkins remove &&\
rm /etc/init.d/jenkins
# Adds jenkins service
RUN mkdir /etc/service/jenkins
ADD jenkins.sh /etc/service/jenkins/run
RUN chmod 0755 /etc/service/jenkins/run
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
EXPOSE 8080
#!/bin/sh
set -xeu
# From /etc/init.d/jenkins
JAVA_ARGS=""
[ -r /etc/default/jenkins ] && . /etc/default/jenkins
exec chpst -u $JENKINS_USER $JAVA $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_ARGS >> $JENKINS_LOG 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment