# The MIT License # # Copyright (c) 2015-2017, CloudBees, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE.
ARG version=3107.v665000b_51092-10 FROM jenkins/agent:${version}-jdk11
ARG version=3107.v665000b_51092-10 LABEL Description="This is a base image, which allows connecting Jenkins agents via JNLP protocols" Vendor="Jenkins project" Version="$version"
ARGuser=jenkins
USER root COPY ../../jenkins-agent /usr/local/bin/jenkins-agent RUN chmod +x /usr/local/bin/jenkins-agent &&\ ln -s /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-slave USER ${user}
ENTRYPOINT ["/usr/local/bin/jenkins-agent"]
我们来分析这个 Dockerfile 是如何制作一个 jenkins agent 的:
FROM jenkins/agent:3107.v665000b_51092-10-jdk11 首先使用的是这个上层镜像作为基础镜像,jdk 版本为 11
USER root 其次将身份切换为 root,再把项目根路径下的 jenkins-agent 启动脚本放进容器并授权
# The MIT License # # Copyright (c) 2015-2023, CloudBees, Inc. and other Jenkins contributors # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE.
ARG JAVA_VERSION=17.0.7_7 FROM eclipse-temurin:"${JAVA_VERSION}"-jdk-focal AS jre-build
# This Build ARG is populated by Docker # Ref. https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope ARG TARGETPLATFORM
# Generate smaller java runtime without unneeded files # for now we include the full module path to maintain compatibility # while still saving space (approx 200mb from the full distribution) RUNiftest"${TARGETPLATFORM}" != 'linux/arm/v7'; then \ case"$(jlink --version 2>&1)"in \ # jlink version 11 has less features than jdk11+ "11."*) strip_java_debug_flags=("--strip-debug") ;; \ *) strip_java_debug_flags=("--strip-java-debug-attributes") ;; \ esac; \ jlink \ --add-modules ALL-MODULE-PATH \ "${strip_java_debug_flags[@]}" \ --no-man-pages \ --no-header-files \ --compress=2 \ --output /javaruntime; \ # It is acceptable to have a larger image in arm/v7 (arm 32 bits) environment. # Because jlink fails with the error "jmods: Value too large for defined data type" error. else cp -r /opt/java/openjdk /javaruntime; \ fi
# https://hub.docker.com/r/bitnami/kubectl FROM uhub.service.ucloud.cn/gao7public/kubectl:1.20.6 as kubectl # https://hub.docker.com/r/jenkins/agent FROM uhub.service.ucloud.cn/gao7public/agent:3107.v665000b_51092-10-jdk11
Started by user admin [Pipeline] Start of Pipeline [Pipeline] node Running on inbound-agent in /home/jenkins/agent/workspace/workspace/test1 [Pipeline] { [Pipeline] stage [Pipeline] { (build) [Pipeline] script [Pipeline] { [Pipeline] sh + pwd /home/jenkins/agent/workspace/workspace/test1 + whoami root + rsync --version rsync version 3.2.3 protocol version 31 Copyright (C) 1996-2020 by Andrew Tridgell, Wayne Davison, and others. Web site: https://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, hardlink-specials, symlinks, IPv6, atimes, batchfiles, inplace, append, ACLs, xattrs, optional protect-args, iconv, symtimes, prealloc, stop-at, no crtimes Optimizations: SIMD, asm, openssl-crypto Checksum list: xxh128 xxh3 xxh64 (xxhash) md5 md4 none Compress list: zstd lz4 zlibx zlib none
rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details. + python3 -V Python 3.9.2 + node -v v12.22.12 + npm -v 7.5.2 + /kaniko/executor version Kaniko version : v1.9.0 + helm version version.BuildInfo{Version:"v3.8.1", GitCommit:"5cb9af4b1b271d11d7a97a71df3ac337dd94ad37", GitTreeState:"clean", GoVersion:"go1.17.5"} + kubectl version Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.6", GitCommit:"8a62859e515889f07e3e3be6a1080413f17cf2c3", GitTreeState:"clean", BuildDate:"2021-04-15T03:28:42Z", GoVersion:"go1.15.10", Compiler:"gc", Platform:"linux/amd64"} The connection to the server localhost:8080 was refused - did you specify the right host or port? [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE