修复构建镜像时所创建的 docker 用户组无效的问题。

This commit is contained in:
2023-03-27 02:35:19 +08:00
parent 2f5c99e4b7
commit 536344d7c7
2 changed files with 25 additions and 3 deletions

View File

@ -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

22
start-agent.sh Normal file
View File

@ -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 "$@"