Skip to content

Commit ff018cd

Browse files
author
Moaad Khamlich
committed
ENH: optimize Docker workflow for testing
1 parent 52d03d9 commit ff018cd

5 files changed

Lines changed: 193 additions & 38 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Push Multi-Arch Docker Images
2+
3+
on:
4+
push:
5+
branches: [ "Docker" ]
6+
7+
env:
8+
REGISTRY: docker.io
9+
IMAGE_NAME: ithacafv/ithaca-fv
10+
11+
jobs:
12+
build-ithaca:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Log into registry ${{ env.REGISTRY }}
26+
if: github.event_name != 'pull_request'
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ secrets.DOCKER_USERNAME }}
31+
password: ${{ secrets.DOCKER_PASSWORD }}
32+
33+
- name: Extract metadata for ITHACA-FV image
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
tags: |
39+
type=ref,event=branch
40+
type=ref,event=pr
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=raw,value=latest,enable={{is_default_branch}}
44+
45+
- name: Build and push ITHACA-FV image
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: ./dockerfiles/OF2412
49+
platforms: linux/amd64,linux/arm64
50+
push: ${{ github.event_name != 'pull_request' }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max

dockerfiles/OF2412/Dockerfile

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,75 @@
1-
# Start from the ubuntu Openfoam 2106 image
2-
FROM opencfd/openfoam-dev:2412
1+
# Multi-architecture Dockerfile for ITHACA-FV
2+
# Automatically selects the correct base image based on target platform
3+
ARG TARGETARCH
4+
FROM ithacafv/openfoam2412-muq2-pytorch:${TARGETARCH} AS base
5+
6+
LABEL maintainer="moaadkhamlich@gmail.com"
7+
8+
USER root
9+
10+
# Install additional packages
11+
RUN apt-get update && \
12+
apt-get install -y \
13+
git \
14+
vim \
15+
ssh \
16+
sudo \
17+
wget \
18+
software-properties-common && \
19+
rm -rf /var/lib/apt/lists/*
20+
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+
37+
# 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
42+
43+
# Environment variables for bashrc
44+
ARG of_var="source /usr/lib/openfoam/openfoam2412/etc/bashrc"
45+
ARG ithaca_var="source /opt/ITHACA-FV/etc/bashrc"
46+
47+
# Update bashrc with OpenFOAM and ITHACA-FV sources
48+
RUN echo $of_var >> /etc/bash.bashrc && \
49+
echo $ithaca_var >> /etc/bash.bashrc
50+
51+
# Switch to ithacafv user
52+
USER $USER
53+
54+
# Build ITHACA-FV
55+
RUN /bin/bash -c "source /usr/lib/openfoam/openfoam2412/etc/bashrc && \
56+
cd ITHACA-FV && \
57+
git submodule update --init && \
58+
source etc/bashrc && \
59+
./Allwmake -au -j 4"
60+
61+
# Copy binaries and libraries to system paths (as root)
362
USER root
4-
ARG PYTHON_VERSION=3.7
5-
ENV PATH="/root/miniconda3/bin:${PATH}"
6-
7-
RUN rm /etc/apt/sources.list.d/openfoam.list && \
8-
cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
9-
grep -v -e "openfoam" /etc/apt/sources.list.backup > /etc/apt/sources.list && \
10-
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
11-
apt-get update && \
12-
apt-get install -yy -q pwgen npm nodejs cmake git wget bzip2 unzip && \
13-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
14-
15-
# Anaconda installing
16-
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
17-
bash Miniconda3-latest-Linux-x86_64.sh -b && \
18-
rm Miniconda3-latest-Linux-x86_64.sh && \
19-
. /root/miniconda3/etc/profile.d/conda.sh && \
20-
export PATH=/root/miniconda3/bin:$PATH && \
21-
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.7.1%2Bcpu.zip && \
22-
unzip libtorch-cxx11-abi-shared-with-deps-2.7.1+cpu.zip && \
23-
rm libtorch-cxx11-abi-shared-with-deps-2.7.1+cpu.zip && \
24-
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
25-
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
26-
conda install -y -c conda-forge muq cmake pybind11 && \
27-
conda clean -y --all
28-
ENV TORCH_LIBRARIES=/libtorch
29-
ENV MUQ_LIBRARIES=/root/miniconda3
30-
RUN echo 'source /usr/lib/openfoam/openfoam2412/etc/bashrc' >> ~/.bashrc
63+
RUN if [ -d "/home/$USER/OpenFOAM/$USER-openfoam2412/platforms/linux64GccDPInt32Opt/bin" ]; then \
64+
cp -r /home/$USER/OpenFOAM/$USER-openfoam2412/platforms/linux64GccDPInt32Opt/bin/* /usr/local/bin/ || true; \
65+
cp -r /home/$USER/OpenFOAM/$USER-openfoam2412/platforms/linux64GccDPInt32Opt/lib/* /usr/local/lib/ || true; \
66+
fi
67+
68+
# Final setup
69+
USER $USER
70+
WORKDIR $HOME
71+
72+
# Source bashrc on container start
73+
RUN /bin/bash -c "source /etc/bash.bashrc"
3174

75+
ENTRYPOINT ["/bin/bash"]

dockerfiles/OF2412/Makefile

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Start from the ubuntu Openfoam 2106 image
2+
FROM opencfd/openfoam-dev:2412
3+
USER root
4+
ARG PYTHON_VERSION=3.7
5+
ENV PATH="/root/miniconda3/bin:${PATH}"
6+
7+
RUN rm /etc/apt/sources.list.d/openfoam.list && \
8+
cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
9+
grep -v -e "openfoam" /etc/apt/sources.list.backup > /etc/apt/sources.list && \
10+
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
11+
apt-get update && \
12+
apt-get install -yy -q pwgen npm nodejs cmake git wget bzip2 unzip && \
13+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
14+
15+
# Anaconda installing
16+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
17+
bash Miniconda3-latest-Linux-x86_64.sh -b && \
18+
rm Miniconda3-latest-Linux-x86_64.sh && \
19+
. /root/miniconda3/etc/profile.d/conda.sh && \
20+
export PATH=/root/miniconda3/bin:$PATH && \
21+
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.7.1%2Bcpu.zip && \
22+
unzip libtorch-cxx11-abi-shared-with-deps-2.7.1+cpu.zip && \
23+
rm libtorch-cxx11-abi-shared-with-deps-2.7.1+cpu.zip && \
24+
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
25+
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
26+
conda install -y -c conda-forge muq cmake pybind11 && \
27+
conda clean -y --all
28+
ENV TORCH_LIBRARIES=/libtorch
29+
ENV MUQ_LIBRARIES=/root/miniconda3
30+
RUN echo 'source /usr/lib/openfoam/openfoam2412/etc/bashrc' >> ~/.bashrc
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Start from the ubuntu Openfoam 2106 image
2+
FROM opencfd/openfoam-dev:2412
3+
USER root
4+
ARG PYTHON_VERSION=3.7
5+
ENV PATH="/root/miniconda3/bin:${PATH}"
6+
7+
RUN rm /etc/apt/sources.list.d/openfoam.list && \
8+
cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
9+
grep -v -e "openfoam" /etc/apt/sources.list.backup > /etc/apt/sources.list && \
10+
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
11+
apt-get update && \
12+
apt-get install -yy -q pwgen npm nodejs cmake git wget bzip2 unzip libc6-dev && \
13+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
14+
15+
# Anaconda installing
16+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh && \
17+
bash Miniconda3-latest-Linux-aarch64.sh -b && \
18+
rm Miniconda3-latest-Linux-aarch64.sh && \
19+
. /root/miniconda3/etc/profile.d/conda.sh && \
20+
export PATH=/root/miniconda3/bin:$PATH && \
21+
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.7.1%2Bcpu.zip && \
22+
unzip libtorch-cxx11-abi-shared-with-deps-2.7.1+cpu.zip && \
23+
rm libtorch-cxx11-abi-shared-with-deps-2.7.1+cpu.zip && \
24+
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
25+
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
26+
conda install -y -c conda-forge cmake pybind11 eigen hdf5 nlopt && \
27+
git clone https://bitbucket.org/mituq/muq2.git /tmp/muq2 && \
28+
cd /tmp/muq2 && rm -rf build && mkdir build && cd build && \
29+
cmake -DCMAKE_INSTALL_PREFIX=/root/miniconda3 -DMUQ_USE_PYTHON=ON .. && \
30+
make -j4 && make install && \
31+
cd / && rm -rf /tmp/muq2 && \
32+
conda clean -y --all
33+
ENV TORCH_LIBRARIES=/libtorch
34+
ENV MUQ_LIBRARIES=/root/miniconda3
35+
RUN echo 'source /usr/lib/openfoam/openfoam2412/etc/bashrc' >> ~/.bashrc
36+

0 commit comments

Comments
 (0)