Skip to content

Commit 4ca64b4

Browse files
Reuse existing base image groups safely
1 parent 58cd020 commit 4ca64b4

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ RUN apt-get update \
3232
gosu \
3333
tini \
3434
&& rm -rf /var/lib/apt/lists/* \
35-
&& groupadd --gid "${TRUTHGATE_GID}" truthgate \
36-
&& useradd --uid "${TRUTHGATE_UID}" --gid truthgate --create-home --shell /usr/sbin/nologin truthgate \
35+
&& if ! getent group "${TRUTHGATE_GID}" >/dev/null; then groupadd --gid "${TRUTHGATE_GID}" truthgate; fi \
36+
&& if existing_user="$(getent passwd "${TRUTHGATE_UID}" | cut -d: -f1)" && [ -n "${existing_user}" ]; then \
37+
usermod --login truthgate --home /home/truthgate --move-home --shell /usr/sbin/nologin "${existing_user}"; \
38+
else \
39+
useradd --uid "${TRUTHGATE_UID}" --gid "${TRUTHGATE_GID}" --create-home --shell /usr/sbin/nologin truthgate; \
40+
fi \
3741
&& mkdir -p /home/truthgate/.aspnet \
3842
&& ln -s /data/truthgate/secrets/data-protection-keys /home/truthgate/.aspnet/DataProtection-Keys
3943

@@ -77,10 +81,14 @@ RUN apt-get update \
7781
gosu \
7882
tini \
7983
&& rm -rf /var/lib/apt/lists/* \
80-
&& groupadd --gid "${TRUTHGATE_GID}" truthgate \
81-
&& useradd --uid "${TRUTHGATE_UID}" --gid truthgate --create-home --shell /bin/bash truthgate \
84+
&& if ! getent group "${TRUTHGATE_GID}" >/dev/null; then groupadd --gid "${TRUTHGATE_GID}" truthgate; fi \
85+
&& if existing_user="$(getent passwd "${TRUTHGATE_UID}" | cut -d: -f1)" && [ -n "${existing_user}" ]; then \
86+
usermod --login truthgate --home /home/truthgate --move-home --shell /bin/bash "${existing_user}"; \
87+
else \
88+
useradd --uid "${TRUTHGATE_UID}" --gid "${TRUTHGATE_GID}" --create-home --shell /bin/bash truthgate; \
89+
fi \
8290
&& mkdir -p /workspace /home/truthgate/.aspnet \
83-
&& chown truthgate:truthgate /workspace \
91+
&& chown "${TRUTHGATE_UID}:${TRUTHGATE_GID}" /workspace \
8492
&& ln -s /data/truthgate/secrets/data-protection-keys /home/truthgate/.aspnet/DataProtection-Keys
8593

8694
COPY --from=kubo /usr/local/bin/ipfs /usr/local/bin/ipfs

0 commit comments

Comments
 (0)