Skip to content

Commit 011c183

Browse files
author
Moaad Khamlich
committed
ENH: improve Dockerfile portability and robustness
- Use FOAM_ETC environment variable instead of hardcoded OpenFOAM path - Make binary/library copying more flexible across OpenFOAM versions
1 parent d8267d0 commit 011c183

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

dockerfiles/Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ RUN git clone https://github.com/mathLab/ITHACA-FV.git && \
4141
chown -R $USER:$USER /home/$USER
4242

4343
# Environment variables for bashrc
44-
ARG of_var="source /usr/lib/openfoam/openfoam2412/etc/bashrc"
44+
ARG of_var="source \$FOAM_ETC/bashrc"
4545
ARG ithaca_var="source /opt/ITHACA-FV/etc/bashrc"
4646

4747
# Update bashrc with OpenFOAM and ITHACA-FV sources
@@ -52,22 +52,26 @@ RUN echo $of_var >> /etc/bash.bashrc && \
5252
USER $USER
5353

5454
# Build ITHACA-FV with architecture-specific flags
55-
RUN /bin/bash -c "source /usr/lib/openfoam/openfoam2412/etc/bashrc && \
55+
RUN /bin/bash -c "source \$FOAM_ETC/bashrc && \
5656
cd ITHACA-FV && \
5757
git submodule update --init && \
5858
source etc/bashrc && \
5959
if [ \"$TARGETARCH\" = \"amd64\" ]; then \
6060
./Allwmake -taumq -j 4; \
6161
else \
62-
./Allwmake -tau -j 4; \
62+
./Allwmake -au -j 4; \
6363
fi"
6464

6565
# Copy binaries and libraries to system paths (as root)
6666
USER root
67-
RUN if [ -d "/home/$USER/OpenFOAM/$USER-openfoam2412/platforms/linux64GccDPInt32Opt/bin" ]; then \
68-
cp -r /home/$USER/OpenFOAM/$USER-openfoam2412/platforms/linux64GccDPInt32Opt/bin/* /usr/local/bin/ || true; \
69-
cp -r /home/$USER/OpenFOAM/$USER-openfoam2412/platforms/linux64GccDPInt32Opt/lib/* /usr/local/lib/ || true; \
70-
fi
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
7175

7276
# Final setup
7377
USER $USER

dockerfiles/OF2412/amd64-deps/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@ conda install -y -c conda-forge muq cmake pybind11 && \
2727
conda clean -y --all
2828
ENV TORCH_LIBRARIES=/libtorch
2929
ENV MUQ_LIBRARIES=/root/miniconda3
30+
31+
# Export OpenFOAM environment variables for use in subsequent builds
32+
RUN /bin/bash -c "source /usr/lib/openfoam/openfoam2412/etc/bashrc && \
33+
echo 'export FOAM_ETC=${FOAM_ETC}' >> /etc/environment && \
34+
echo 'export FOAM_APP=${FOAM_APP}' >> /etc/environment && \
35+
echo 'export FOAM_APPBIN=${FOAM_APPBIN}' >> /etc/environment && \
36+
echo 'export FOAM_LIBBIN=${FOAM_LIBBIN}' >> /etc/environment && \
37+
echo 'export FOAM_SRC=${FOAM_SRC}' >> /etc/environment && \
38+
echo 'export WM_PROJECT_DIR=${WM_PROJECT_DIR}' >> /etc/environment"
39+
40+
ENV FOAM_ETC=/usr/lib/openfoam/openfoam2412/etc
3041
RUN echo 'source /usr/lib/openfoam/openfoam2412/etc/bashrc' >> ~/.bashrc

dockerfiles/OF2412/arm64-deps/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,16 @@ make -j4 && make install && \
2828
cd / && rm -rf /tmp/muq2 && \
2929
conda clean -y --all
3030
ENV MUQ_LIBRARIES=/root/miniconda3
31+
32+
# Export OpenFOAM environment variables for use in subsequent builds
33+
RUN /bin/bash -c "source /usr/lib/openfoam/openfoam2412/etc/bashrc && \
34+
echo 'export FOAM_ETC=${FOAM_ETC}' >> /etc/environment && \
35+
echo 'export FOAM_APP=${FOAM_APP}' >> /etc/environment && \
36+
echo 'export FOAM_APPBIN=${FOAM_APPBIN}' >> /etc/environment && \
37+
echo 'export FOAM_LIBBIN=${FOAM_LIBBIN}' >> /etc/environment && \
38+
echo 'export FOAM_SRC=${FOAM_SRC}' >> /etc/environment && \
39+
echo 'export WM_PROJECT_DIR=${WM_PROJECT_DIR}' >> /etc/environment"
40+
41+
ENV FOAM_ETC=/usr/lib/openfoam/openfoam2412/etc
3142
RUN echo 'source /usr/lib/openfoam/openfoam2412/etc/bashrc' >> ~/.bashrc
3243

dockerfiles/OF2506/amd64-deps/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@ conda install -y -c conda-forge muq cmake pybind11 && \
2727
conda clean -y --all
2828
ENV TORCH_LIBRARIES=/libtorch
2929
ENV MUQ_LIBRARIES=/root/miniconda3
30+
31+
# Export OpenFOAM environment variables for use in subsequent builds
32+
RUN /bin/bash -c "source /usr/lib/openfoam/openfoam2506/etc/bashrc && \
33+
echo 'export FOAM_ETC=${FOAM_ETC}' >> /etc/environment && \
34+
echo 'export FOAM_APP=${FOAM_APP}' >> /etc/environment && \
35+
echo 'export FOAM_APPBIN=${FOAM_APPBIN}' >> /etc/environment && \
36+
echo 'export FOAM_LIBBIN=${FOAM_LIBBIN}' >> /etc/environment && \
37+
echo 'export FOAM_SRC=${FOAM_SRC}' >> /etc/environment && \
38+
echo 'export WM_PROJECT_DIR=${WM_PROJECT_DIR}' >> /etc/environment"
39+
40+
ENV FOAM_ETC=/usr/lib/openfoam/openfoam2506/etc
3041
RUN echo 'source /usr/lib/openfoam/openfoam2506/etc/bashrc' >> ~/.bashrc

dockerfiles/OF2506/arm64-deps/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,16 @@ make -j4 && make install && \
2828
cd / && rm -rf /tmp/muq2 && \
2929
conda clean -y --all
3030
ENV MUQ_LIBRARIES=/root/miniconda3
31+
32+
# Export OpenFOAM environment variables for use in subsequent builds
33+
RUN /bin/bash -c "source /usr/lib/openfoam/openfoam2506/etc/bashrc && \
34+
echo 'export FOAM_ETC=${FOAM_ETC}' >> /etc/environment && \
35+
echo 'export FOAM_APP=${FOAM_APP}' >> /etc/environment && \
36+
echo 'export FOAM_APPBIN=${FOAM_APPBIN}' >> /etc/environment && \
37+
echo 'export FOAM_LIBBIN=${FOAM_LIBBIN}' >> /etc/environment && \
38+
echo 'export FOAM_SRC=${FOAM_SRC}' >> /etc/environment && \
39+
echo 'export WM_PROJECT_DIR=${WM_PROJECT_DIR}' >> /etc/environment"
40+
41+
ENV FOAM_ETC=/usr/lib/openfoam/openfoam2506/etc
3142
RUN echo 'source /usr/lib/openfoam/openfoam2506/etc/bashrc' >> ~/.bashrc
3243

0 commit comments

Comments
 (0)