Skip to content

Commit ac48e6b

Browse files
committed
Add non-root user already in first stage, to make it available in the fans-ci image as well
1 parent 4a27156 commit ac48e6b

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

docker/Dockerfile

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# to take effect)
33
ARG DEBIAN_FRONTEND=noninteractive
44
ARG UBUNTU_VERSION=noble
5+
ARG USER=fans
56

67
################################################################################
78

89
FROM ubuntu:${UBUNTU_VERSION} AS fans_base
910
ARG DEBIAN_FRONTEND
11+
ARG USER
1012

1113
# Context: https://askubuntu.com/questions/1513927/ubuntu-24-04-docker-images-now-includes-user-ubuntu-with-uid-gid-1000
1214
RUN bash -c 'if id "ubuntu" &>/dev/null; then \
@@ -16,6 +18,9 @@ RUN bash -c 'if id "ubuntu" &>/dev/null; then \
1618
echo "Deleted user ubuntu."; \
1719
fi'
1820

21+
# Create a non-root user
22+
RUN useradd -m -s /bin/bash ${USER}
23+
1924
################################################################################
2025

2126
FROM fans_base AS fans_ci
@@ -44,6 +49,8 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
4449

4550
FROM fans_ci AS fans_dev
4651
ARG DEBIAN_FRONTEND
52+
ARG USER
53+
ARG FANS_venv=FANS_venv
4754

4855
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
4956
# Packages required for setting up the non-root user
@@ -63,32 +70,20 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
6370
&& apt-get autoremove --purge -y \
6471
&& rm -rf /var/lib/apt/lists/*
6572

66-
# Create a non-root user
67-
ENV USER=develop
68-
ENV UID=1000
69-
ENV GID=100
70-
ENV HOME=/home/${USER}
71-
RUN adduser --disabled-password \
72-
--gecos "Non-root user" \
73-
--uid ${UID} \
74-
--gid ${GID} \
75-
--home ${HOME} \
76-
${USER} \
77-
#
78-
&& echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} \
79-
&& chmod 0440 /etc/sudoers.d/${USER}
80-
8173
# Create a python venv for test/h52xdmf.py script
8274
USER ${USER}
8375

84-
ARG FANS_venv=FANS_venv
8576
RUN python -m venv /home/${USER}/venvs/${FANS_venv} && \
8677
echo "\nsource /home/${USER}/venvs/${FANS_venv}/bin/activate\n" >> /home/${USER}/.bashrc && \
8778
. /home/${USER}/venvs/${FANS_venv}/bin/activate && \
8879
python -m pip install --no-cache-dir h5py lxml
8980

9081
USER root
9182

83+
# Add fans user to sudoers
84+
RUN echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} \
85+
&& chmod 440 /etc/sudoers.d/${USER}
86+
9287
# Entrypoint script changes UID and GID to match given host UID and GID
9388
COPY --chmod=755 docker/Dockerfile_user_env_entrypoint.sh /entrypoint.sh
9489
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)