aboutsummaryrefslogtreecommitdiffstats
path: root/Dockerfile.jenkins
blob: 23a95f18355bf437ee503042f660d015ad313878 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Dockerfile.jenkins
# Use the official Jenkins image as a base
FROM jenkins/jenkins:lts-jdk17

# 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 and manage users
USER root

# Install Docker CLI so Jenkins can interact with the host's Docker daemon
RUN apt-get update && apt-get install -y lsb-release sudo
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
  https://download.docker.com/linux/debian/gpg
RUN echo "deb [arch=$(dpkg --print-architecture) \
  signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
  https://download.docker.com/linux/debian \
  $(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
# and add the jenkins user to it.
RUN if [ -n "$DOCKER_GID" ]; then \
        groupadd -g $DOCKER_GID docker && \
        usermod -aG docker jenkins; \
    fi

# 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 to the newly configured jenkins user
USER jenkins