Skip to content

Commit

Permalink
Dockerfiles: improve readability of user/group creation logic
Browse files Browse the repository at this point in the history
Signed-off-by: Yann Dirson <[email protected]>
Cc: Simone Conti <[email protected]>
  • Loading branch information
ydirson committed Nov 10, 2023
1 parent 2fe411b commit d198d4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Dockerfile-7.x
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.

# Set up the builder user
RUN bash -c ' \
OPTS=(); \
if [ -n "${CUSTOM_BUILDER_UID}" ]; then \
if [ -z "${CUSTOM_BUILDER_GID}" ]; then \
CUSTOM_BUILDER_GID="${CUSTOM_BUILDER_UID}"; \
fi; \
OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \
fi; \
if [ -n "${CUSTOM_BUILDER_GID}" ]; then \
OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \
if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \
groupadd -g "${CUSTOM_BUILDER_GID}" builder; \
fi; \
useradd -u "${CUSTOM_BUILDER_UID}" -g "${CUSTOM_BUILDER_GID}" builder; \
else \
useradd builder; \
fi; \
useradd "${OPTS[@]}" builder; \
' \
&& echo "builder:builder" | chpasswd \
&& echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers \
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile-8.x
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.

# Set up the builder user
RUN bash -c ' \
OPTS=(); \
if [ -n "${CUSTOM_BUILDER_UID}" ]; then \
if [ -z "${CUSTOM_BUILDER_GID}" ]; then \
CUSTOM_BUILDER_GID="${CUSTOM_BUILDER_UID}"; \
fi; \
OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \
fi; \
if [ -n "${CUSTOM_BUILDER_GID}" ]; then \
OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \
if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \
groupadd -g "${CUSTOM_BUILDER_GID}" builder; \
fi; \
useradd -u "${CUSTOM_BUILDER_UID}" -g "${CUSTOM_BUILDER_GID}" builder; \
else \
useradd builder; \
fi; \
useradd "${OPTS[@]}" builder; \
' \
&& echo "builder:builder" | chpasswd \
&& echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
Expand Down

0 comments on commit d198d4a

Please sign in to comment.