Dockerfile 4.2 KB

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