Skip to content

Commit 553dc4c

Browse files
author
Moaad Khamlich
committed
FIX: simplify Dockerfile user management and build process
Streamlined the build process by removing complex user management, fixing duplicate bashrc entries, and improving working directory structure.
1 parent 011c183 commit 553dc4c

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

dockerfiles/Dockerfile

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ FROM ithacafv/ithacafv-dependencies:${TARGETARCH} AS base
55

66
LABEL maintainer="[email protected]"
77

8-
USER root
9-
108
# Install additional packages
119
RUN apt-get update && \
1210
apt-get install -y \
@@ -18,27 +16,9 @@ RUN apt-get update && \
1816
software-properties-common && \
1917
rm -rf /var/lib/apt/lists/*
2018

21-
# Create ithacafv user and group
22-
ARG USER=ithacafv
23-
RUN if id -u 1000 >/dev/null 2>&1; then \
24-
userdel $(id -nu 1000) || true; \
25-
fi && \
26-
if getent group 1000 >/dev/null 2>&1; then \
27-
groupdel $(getent group 1000 | cut -d: -f1) || true; \
28-
fi && \
29-
adduser --disabled-password --gecos '' --uid 1000 $USER && \
30-
adduser $USER sudo && \
31-
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
32-
33-
# Set environment variables
34-
ENV HOME=/home/$USER
35-
ENV USER=$USER
36-
3719
# Set working directory and clone ITHACA-FV
38-
WORKDIR /opt
39-
RUN git clone https://github.com/mathLab/ITHACA-FV.git && \
40-
chown -R $USER:$USER ITHACA-FV && \
41-
chown -R $USER:$USER /home/$USER
20+
WORKDIR /usr/dir
21+
RUN git clone https://github.com/ITHACA-FV/ITHACA-FV.git
4222

4323
# Environment variables for bashrc
4424
ARG of_var="source \$FOAM_ETC/bashrc"
@@ -48,36 +28,20 @@ ARG ithaca_var="source /opt/ITHACA-FV/etc/bashrc"
4828
RUN echo $of_var >> /etc/bash.bashrc && \
4929
echo $ithaca_var >> /etc/bash.bashrc
5030

51-
# Switch to ithacafv user
52-
USER $USER
31+
# Update bashrc with OpenFOAM and ITHACA-FV sources
32+
RUN echo $of_var >> /etc/bash.bashrc && \
33+
echo $ithaca_var >> /etc/bash.bashrc
34+
5335

54-
# Build ITHACA-FV with architecture-specific flags
55-
RUN /bin/bash -c "source \$FOAM_ETC/bashrc && \
56-
cd ITHACA-FV && \
57-
git submodule update --init && \
58-
source etc/bashrc && \
36+
RUN /bin/bash -c "source \$FOAM_ETC/bashrc && \
37+
cd ITHACA-FV && git submodule update --init && source etc/bashrc && \
5938
if [ \"$TARGETARCH\" = \"amd64\" ]; then \
6039
./Allwmake -taumq -j 4; \
6140
else \
6241
./Allwmake -au -j 4; \
6342
fi"
6443

65-
# Copy binaries and libraries to system paths (as root)
66-
USER root
67-
RUN for openfoam_dir in /home/$USER/OpenFOAM/$USER-openfoam*/platforms/*/; do \
68-
if [ -d "$openfoam_dir/bin" ]; then \
69-
cp -r "$openfoam_dir/bin"/* /usr/local/bin/ 2>/dev/null || true; \
70-
fi; \
71-
if [ -d "$openfoam_dir/lib" ]; then \
72-
cp -r "$openfoam_dir/lib"/* /usr/local/lib/ 2>/dev/null || true; \
73-
fi; \
74-
done
75-
76-
# Final setup
77-
USER $USER
78-
WORKDIR $HOME
7944

8045
# Source bashrc on container start
8146
RUN /bin/bash -c "source /etc/bash.bashrc"
82-
8347
ENTRYPOINT ["/bin/bash"]

0 commit comments

Comments
 (0)