Improve permissions and cleanup

Signed-off-by: Benoit Donneaux <benoit@leastauthority.com>
This commit is contained in:
Benoit Donneaux 2024-05-23 11:21:02 +02:00
parent 444b318ee3
commit 4c11a160f4
3 changed files with 18 additions and 17 deletions

View file

@ -14,10 +14,11 @@ ARG user=ubuntu
ARG gid=1000
ARG group=ubuntu
# Add or modify user and group for build and runtime (convenient)
#RUN id ${user} > /dev/null 2>&1 && \
# { groupmod -g "${gid}" "${group}" && usermod -md /home/${user} -s /bin/bash -g "${group}" -u "${uid}" "${user}"; } || \
# { groupadd -g "${gid}" "${group}" && useradd -md /home/${user} -s /bin/bash -g "${group}" -u "${uid}" "${user}"; }
# Ensure desired user and group for build and runtime (convenient)
RUN userdel --force --remove $(getent passwd ${uid} | cut -d: -f1) || true; \
groupdel $(getent group ${gid} | cut -d: -f1) || true; \
groupadd -g "${gid}" "${group}" && \
useradd -md /home/${user} -s /bin/bash -g "${group}" -u "${uid}" "${user}";
# Copy requirements in non-root user home directory
COPY Gemfile Gemfile.lock "/home/${user}/"