Dockerfile (3732B)
1 # The MIT License 2 # 3 # Copyright (c) 2015-2020, CloudBees, Inc. and other Jenkins contributors 4 # 5 # Permission is hereby granted, free of charge, to any person obtaining a copy 6 # of this software and associated documentation files (the "Software"), to deal 7 # in the Software without restriction, including without limitation the rights 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 # copies of the Software, and to permit persons to whom the Software is 10 # furnished to do so, subject to the following conditions: 11 # 12 # The above copyright notice and this permission notice shall be included in 13 # all copies or substantial portions of the Software. 14 # 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 # THE SOFTWARE. 22 23 # Based on: 24 # https://github.com/jenkinsci/docker-agent/blob/master/alpine/Dockerfile 25 # https://github.com/jenkinsci/docker-inbound-agents/blob/master/docker/Dockerfile 26 27 ## Agent image target 28 FROM docker.io/alpine:latest AS agent 29 30 ARG user=jenkins 31 ARG group=jenkins 32 ARG uid=1000 33 ARG gid=1000 34 ARG AGENT_WORKDIR="/home/${user}/agent" 35 36 RUN addgroup -g "${gid}" "${group}" 37 RUN adduser -h "/home/${user}" -u "${uid}" -G "${group}" -D "${user}" 38 39 ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' 40 ENV TZ=Etc/UTC 41 42 RUN apk update && apk add --no-cache \ 43 curl bash git git-lfs musl-locales openssh-client openssl \ 44 procps tzdata tzdata-utils 45 46 RUN apk add openjdk24 \ 47 --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing 48 49 # Download Jenkins remoting agent 50 ARG VERSION=3327.v868139a_d00e0 51 ADD --chown="${user}":"${group}" "https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar" /usr/share/jenkins/agent.jar 52 RUN chmod 0644 /usr/share/jenkins/agent.jar \ 53 && ln -sf /usr/share/jenkins/agent.jar /usr/share/jenkins/slave.jar 54 55 USER "${user}" 56 ENV AGENT_WORKDIR="${AGENT_WORKDIR}" 57 RUN mkdir -p "/home/${user}/.jenkins" && mkdir -p "${AGENT_WORKDIR}" 58 59 VOLUME "/home/${user}/.jenkins" 60 VOLUME "${AGENT_WORKDIR}" 61 WORKDIR "/home/${user}" 62 ENV user="${user}" 63 64 ## Inbound Agent image target 65 FROM agent AS inbound-agent 66 67 USER root 68 69 # Install docker command for docker-workflow Jenkins plugin and buildah to 70 # build and push containers. 71 RUN apk add --no-cache docker buildah netavark 72 73 # Set up environment variables to note that this is not starting with user 74 # namespace and default to isolate the filesystem with chroot. 75 # https://developers.redhat.com/blog/2019/08/14/best-practices-for-running-buildah-in-a-container 76 ENV _BUILDAH_STARTED_IN_USERNS="" BUILDAH_ISOLATION=chroot 77 78 # 'overlay' is not supported over overlayfs without fuse-overlayfs. VFS is the alternative. 79 # - https://docs.gitlab.com/ci/docker/using_docker_build/#buildah-example 80 # - https://wiki.alpinelinux.org/wiki/Podman 81 # - https://github.com/containers/storage/blob/main/docs/containers-storage.conf.5.md 82 # - https://docs.podman.io/en/latest/markdown/podman.1.html#environment-variables 83 ENV STORAGE_DRIVER=vfs 84 85 # Configure missing subuid/subgids for rootless podman builds 86 # https://docs.podman.io/en/latest/markdown/podman.1.html#rootless-mode 87 RUN echo "${user}:10000:65536" >> /etc/subuid 88 RUN echo "${user}:10000:65536" >> /etc/subgid 89 90 USER ${user} 91 92 CMD ["/bin/sh", "-c", "java -jar /usr/share/jenkins/agent.jar ${REMOTING_OPTS} $@"]