aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Andrew D. France 2025-07-22 21:00:10 -0500
committerGravatar Andrew D. France 2025-07-22 21:00:10 -0500
commitbac1f1c73db9c55a18b41b76922572fd2620f3d5 (patch)
tree8b7527fc22e9b16d5604121ddff2219bcdd9162c
parentAdded Jenkins files for local CI testing (diff)
Fixing Jenkins Setup: Attempt2
-rw-r--r--Dockerfile.jenkins27
-rw-r--r--docker-compose.yml7
2 files changed, 23 insertions, 11 deletions
diff --git a/Dockerfile.jenkins b/Dockerfile.jenkins
index 874941a..23a95f1 100644
--- a/Dockerfile.jenkins
+++ b/Dockerfile.jenkins
@@ -2,10 +2,12 @@
# Use the official Jenkins image as a base
FROM jenkins/jenkins:lts-jdk17
-# Pass the Docker group ID from the host as a build argument
+# Pass Host User, Group, and Docker Group IDs as build arguments
+ARG UID
+ARG GID
ARG DOCKER_GID
-# Switch to root user to install dependencies
+# Switch to root user to install dependencies and manage users
USER root
# Install Docker CLI so Jenkins can interact with the host's Docker daemon
@@ -18,12 +20,21 @@ RUN echo "deb [arch=$(dpkg --print-architecture) \
$(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce-cli
-# Create a 'docker' group with the host's GID to match permissions
-# This is the key step to prevent the container from exiting
-RUN if [ -n "$DOCKER_GID" ]; then groupadd -g $DOCKER_GID docker; else groupadd -g 999 docker; fi
+# Create a docker group with the host's GID to match permissions
+# and add the jenkins user to it.
+RUN if [ -n "$DOCKER_GID" ]; then \
+ groupadd -g $DOCKER_GID docker && \
+ usermod -aG docker jenkins; \
+ fi
-# Add the 'jenkins' user to the docker group
-RUN usermod -aG docker jenkins
+# Change the jenkins user and group to match the host.
+# This should ensure file permissions for the jenkins_home volume are correct.
+RUN if [ -n "$GID" ] && [ "$(getent group jenkins | cut -d: -f3)" != "$GID" ]; then \
+ groupmod -g $GID jenkins; \
+ fi
+RUN if [ -n "$UID" ] && [ "$(id -u jenkins)" != "$UID" ]; then \
+ usermod -u $UID jenkins; \
+ fi
-# Switch back to the jenkins user
+# Switch to the newly configured jenkins user
USER jenkins
diff --git a/docker-compose.yml b/docker-compose.yml
index 77dfb90..0cccadc 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,13 +5,14 @@ services:
context: .
dockerfile: Dockerfile.jenkins
args:
- # Pass the host's docker group ID to the build
+ # Pass all necessary host IDs to the build
+ UID: ${UID}
+ GID: ${GID}
DOCKER_GID: ${DOCKER_GID}
- user: "${UID}:${GID}" # Run the container as the current host user
ports:
- "8080:8080"
- "50000:50000"
container_name: jenkins
volumes:
- ./jenkins_home:/var/jenkins_home
- - /var/run/docker.sock:/var/run/docker.sock
+ - /var/run/docker.sock:/var/run/docker.sock \ No newline at end of file