From 536344d7c714ed19a57406e6f78bfe7e036c5841 Mon Sep 17 00:00:00 2001 From: LamGC Date: Mon, 27 Mar 2023 02:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=97=B6=E6=89=80=E5=88=9B=E5=BB=BA=E7=9A=84=20docker?= =?UTF-8?q?=20=E7=94=A8=E6=88=B7=E7=BB=84=E6=97=A0=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 +++--- start-agent.sh | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 start-agent.sh diff --git a/Dockerfile b/Dockerfile index 6a8b15d..7bfb88e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,8 @@ FROM jenkins/inbound-agent:${BASE_TAG} USER root -RUN groupadd -g 987 docker && usermod -aG docker jenkins +COPY start-agent.sh /usr/local/bin/start.sh +ENTRYPOINT [ "/usr/local/bin/start.sh" ] RUN apt-get update && apt-get install -y \ ca-certificates \ @@ -16,5 +17,4 @@ RUN apt-get update && apt-get install -y \ apt-get update && apt-get install -y docker-ce-cli docker-buildx-plugin docker-compose-plugin && \ apt-get clean && rm -rf /var/lib/apt/lists/* -USER jenkins - +ENV DOCKER_HOST=unix:///var/run/docker.sock diff --git a/start-agent.sh b/start-agent.sh new file mode 100644 index 0000000..31ec238 --- /dev/null +++ b/start-agent.sh @@ -0,0 +1,22 @@ +if [ $(whoami) != "jenkins" ] || [ $(id -u) == "0" ]; then + echo "This script must be run as jenkins" + exit 1 +fi + +if [ -z "$GID" ]; then + echo "GID is not set" + exit 1 +fi +if [ -z "$UID" ]; then + echo "UID is not set" + exit 1 +fi +if ! grep -q docker /etc/group; then + groupadd -g $GID docker && usermod -aG docker jenkins +fi +if [ $(id -u jenkins) -ne $UID ]; then + usermod -u $UID jenkins +fi + +# 使用传入的参数列表启动 Jenkins agent +exec /usr/local/bin/jenkins-agent "$@"