Skip to content

Commit c0fb195

Browse files
committed
simulation steps are moved inside the dockerfile
1 parent 12895f8 commit c0fb195

File tree

5 files changed

+215
-157
lines changed

5 files changed

+215
-157
lines changed

.github/workflows/docker_ci.yml

Lines changed: 72 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,91 @@ name: Docker-based CI
22

33
on:
44
push:
5-
branches:
6-
- dumux_and_rotating_cylinder
5+
branches: [ main ]
76
pull_request:
8-
branches:
9-
- dumux_and_rotating_cylinder
7+
branches: [ main ]
108
workflow_dispatch:
11-
schedule:
12-
- cron: '3 16 * * *'
9+
# schedule:
10+
# - cron: '3 16 * * *'
11+
12+
permissions:
13+
contents: write
1314

1415
jobs:
15-
# -----------------------------
16-
# Build Docker images (Linux only)
17-
# -----------------------------
1816
build-docker:
1917
runs-on: ubuntu-latest
2018
steps:
2119
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
2222

23-
- name: Build base image
24-
id: base
25-
run: |
26-
docker build -t ci-base -f dockerfiles/Dockerfile.base .
23+
# -----------------------------
24+
# Build Docker images
25+
# -----------------------------
26+
- name: Build base image (mesh generation included)
27+
run: docker build -t ci-base -f dockerfiles/Dockerfile.base .
2728

28-
- name: Build Docker images
29+
- name: Build Fenics image (simulations included)
30+
run: docker build -t ci-fenics -f dockerfiles/Dockerfile.fenics .
31+
32+
- name: Build Kratos image (simulations included)
33+
run: docker build -t ci-kratos -f dockerfiles/Dockerfile.kratos .
34+
35+
# -----------------------------
36+
# Extract Fenics results
37+
# -----------------------------
38+
- name: Extract Results from Fenics container
2939
run: |
30-
docker build -t ci-mesh -f dockerfiles/Dockerfile.mesh .
31-
docker build -t ci-fenics -f dockerfiles/Dockerfile.fenics .
32-
docker build -t ci-kratos -f dockerfiles/Dockerfile.kratos .
33-
docker build -t ci-postprocessing -f dockerfiles/Dockerfile.postprocessing .
40+
docker create --name fenics_temp ci-fenics
41+
# Copy the results folder as-is from container to host
42+
docker cp fenics_temp:/sim/benchmarks/linear-elastic-plate-with-hole/results ./benchmarks/linear-elastic-plate-with-hole/
43+
docker rm fenics_temp
3444
35-
- name: Generate config and mesh
45+
# -----------------------------
46+
# Extract Kratos results
47+
# -----------------------------
48+
- name: Extract Kratos results
3649
run: |
37-
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace/benchmarks/linear-elastic-plate-with-hole ci-mesh \
38-
python generate_config.py
50+
docker create --name kratos_temp ci-kratos
51+
# Copy the results folder as-is from container to host
52+
docker cp kratos_temp:/sim/benchmarks/linear-elastic-plate-with-hole/results ./benchmarks/linear-elastic-plate-with-hole/
53+
docker rm kratos_temp
3954
40-
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace/benchmarks/linear-elastic-plate-with-hole ci-mesh \
41-
bash -c 'mkdir -p results/linear-elastic-plate-with-hole/mesh && \
42-
for f in parameters_*.json; do \
43-
python create_mesh.py --input_parameter_file "$f" \
44-
--output_mesh_file "results/linear-elastic-plate-with-hole/mesh/mesh_${f%.json}.msh"; \
45-
done'
55+
# -----------------------------
56+
# Upload Artifacts
57+
# -----------------------------
58+
- name: Upload Artifacts
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: workflow-results
62+
path: |
63+
benchmarks/linear-elastic-plate-with-hole/results/fenics
64+
benchmarks/linear-elastic-plate-with-hole/results/kratos
4665
47-
- name: Run Kratos simulations
48-
run: |
49-
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace/benchmarks/linear-elastic-plate-with-hole ci-kratos \
50-
bash -c 'mkdir -p results/linear-elastic-plate-with-hole/kratos && \
51-
for f in parameters_*.json; do \
52-
# Convert mesh to MDPA
53-
python kratos/msh_to_mdpa.py \
54-
--input_parameter_file "$f" \
55-
--input_mesh_file "results/linear-elastic-plate-with-hole/mesh/mesh_${f%.json}.msh" \
56-
--output_mdpa_file "results/linear-elastic-plate-with-hole/kratos/mesh_${f%.json}.mdpa"; \
57-
\
58-
# Create Kratos input and run simulation
59-
python kratos/create_kratos_input.py \
60-
--input_parameter_file "$f" \
61-
--input_mdpa_file "results/linear-elastic-plate-with-hole/kratos/mesh_${f%.json}.mdpa" \
62-
--input_kratos_input_template kratos/input_template.json \
63-
--input_material_template kratos/StructuralMaterials_template.json \
64-
--output_kratos_inputfile "results/linear-elastic-plate-with-hole/kratos/ProjectParameters_${f%.json}.json" \
65-
--output_kratos_materialfile "results/linear-elastic-plate-with-hole/kratos/MaterialParameters_${f%.json}.json"; \
66-
\
67-
python kratos/run_kratos_simulation.py \
68-
--input_parameter_file "$f" \
69-
--input_kratos_inputfile "results/linear-elastic-plate-with-hole/kratos/ProjectParameters_${f%.json}.json" \
70-
--input_kratos_materialfile "results/linear-elastic-plate-with-hole/kratos/MaterialParameters_${f%.json}.json"; \
71-
done'
66+
# # -----------------------------
67+
# # Optional: commit generated results to GitHub
68+
# # -----------------------------
69+
# - name: Commit generated results
70+
# env:
71+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
# run: |
73+
# git config --global user.name "github-actions[bot]"
74+
# git config --global user.email "github-actions[bot]@users.noreply.github.com"
7275

73-
- name: Run fenics simulations
74-
run: |
75-
docker run --rm -v ${{ github.workspace }}:/workspace \
76-
-w /workspace/benchmarks/linear-elastic-plate-with-hole ci-fenics \
77-
bash -c 'mkdir -p results/linear-elastic-plate-with-hole/fenics && \
78-
for f in parameters_*.json; do \
79-
config_name="${f%.json}"; \
80-
python fenics/run_fenics_simulation.py \
81-
--input_parameter_file "$f" \
82-
--input_mesh_file "results/linear-elastic-plate-with-hole/mesh/mesh_${config_name}.msh" \
83-
--output_solution_file_zip "results/linear-elastic-plate-with-hole/fenics/solution_field_data_${config_name}.zip" \
84-
--output_metrics_file "results/linear-elastic-plate-with-hole/fenics/solution_metrics_${config_name}.json"; \
85-
done'
76+
# # Create a flat zip of the simulation results
77+
# cd benchmarks/linear-elastic-plate-with-hole
78+
# tar -cJf simulation_results.tar.xz results
79+
# cd ../..
80+
81+
# # Add only the zip
82+
# git add -f benchmarks/linear-elastic-plate-with-hole/simulation_results.tar.xz
83+
84+
# git commit -m "Add generated simulation results" || echo "No changes to commit"
85+
# git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:main
86+
87+
# - name: Build Postprocessing image
88+
# run: |
89+
# docker build -t ci-postprocessing -f dockerfiles/Dockerfile.postprocessing .
8690

8791
# - name: Postprocessing (metadata + extraction + plot)
8892
# run: |
@@ -93,21 +97,11 @@ jobs:
9397
# bash -c '
9498
# echo "Generating metadata...";
9599
# python parameter_extractor.py ./results metadata4ing_provenance.zip;
96-
100+
#
97101
# echo "Extracting ZIP...";
98102
# mkdir -p ./metadata4ing_provenance;
99103
# unzip -o metadata4ing_provenance.zip -d ./metadata4ing_provenance;
100-
104+
#
101105
# echo "Plotting provenance...";
102106
# python plot_provenance.py ./metadata4ing_provenance
103-
# '
104-
105-
- name: Upload Artifacts
106-
uses: actions/upload-artifact@v4
107-
with:
108-
name: workflow-results
109-
path:
110-
benchmarks/linear-elastic-plate-with-hole/results
111-
# benchmarks/linear-elastic-plate-with-hole/metadata4ing_provenance/
112-
# benchmarks/linear-elastic-plate-with-hole/metadata4ing_provenance.zip
113-
# benchmarks/linear-elastic-plate-with-hole/*.pdf
107+
# '

dockerfiles/Dockerfile.base

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,70 @@
1-
# Base image for all other stages
2-
FROM ubuntu:22.04
1+
# Dockerfile.base
2+
# ci-base: ubuntu:22.04, installs system deps + python deps, generates config & meshes at build time
33

4-
# Set environment
5-
ENV DEBIAN_FRONTEND=noninteractive
4+
FROM ubuntu:22.04 AS ci-base
5+
ARG DEBIAN_FRONTEND=noninteractive
66

7-
# Install basic packages
8-
RUN apt-get update && apt-get install -y \
9-
python3 python3-pip python3-venv git unzip curl wget build-essential \
10-
&& ln -s /usr/bin/python3 /usr/bin/python \
7+
# -----------------------------
8+
# 1) Install system packages (kept together for caching)
9+
# -----------------------------
10+
RUN apt-get update && apt-get install -y --no-install-recommends \
11+
python3 python3-pip python3-venv \
12+
cmake gcc g++ git wget curl unzip build-essential \
13+
gmsh libgomp1 libxrender1 libxext6 libglu1-mesa \
14+
libgl1-mesa-glx libosmesa6 xvfb \
15+
libblas-dev liblapack-dev \
1116
&& rm -rf /var/lib/apt/lists/*
1217

13-
# Upgrade pip
14-
RUN python3 -m pip install --upgrade pip
18+
# -----------------------------
19+
# 2) Python & common pip packages (cache layer)
20+
# -----------------------------
21+
RUN python3 -m pip install --upgrade pip setuptools wheel
22+
# install packages needed by mesh generation (meshio, pyvista, etc.)
23+
RUN python3 -m pip install --no-cache-dir meshio pyvista pint sympy gmsh
1524

16-
WORKDIR /workspace
25+
# -----------------------------
26+
# 3) Create a non-root runtime user (do not use /sim as home to avoid overwrites)
27+
# -----------------------------
28+
RUN useradd -m -s /bin/bash sim
29+
# create workspace
30+
RUN mkdir -p /sim && chown sim:sim /sim
31+
WORKDIR /sim
32+
33+
# optional shared mount
34+
RUN mkdir -p /sim/shared
35+
VOLUME /sim/shared
36+
37+
# -----------------------------
38+
# 4) Copy only required files to optimize cache
39+
# (adjust these paths to match the repo)
40+
# -----------------------------
41+
COPY benchmarks/linear-elastic-plate-with-hole /sim/benchmarks/linear-elastic-plate-with-hole
42+
43+
# if we have a requirements.txt for additional packages used by mesh scripts, copy it:
44+
# COPY requirements_mesh.txt /sim/requirements_mesh.txt
45+
# RUN python3 -m pip install --no-cache-dir -r /sim/requirements_mesh.txt
46+
47+
# ensure ownership
48+
RUN chown -R sim:sim /sim
49+
50+
# -----------------------------
51+
# 5) Build-time mesh generation (runs as non-root)
52+
# This will bake meshes into the image layers.
53+
# -----------------------------
54+
USER sim
55+
WORKDIR /sim/benchmarks/linear-elastic-plate-with-hole
56+
57+
RUN cd /sim/benchmarks/linear-elastic-plate-with-hole && \
58+
ls && \
59+
python3 generate_config.py && \
60+
mkdir -p results/linear-elastic-plate-with-hole/mesh && \
61+
for f in parameters_*.json; do \
62+
python3 create_mesh.py --input_parameter_file "$f" \
63+
--output_mesh_file results/linear-elastic-plate-with-hole/mesh/mesh_${f%.json}.msh; \
64+
done
65+
66+
# -----------------------------
67+
# 6) Final workdir and entrypoint
68+
# -----------------------------
69+
WORKDIR /sim
70+
ENTRYPOINT ["/bin/bash"]

dockerfiles/Dockerfile.fenics

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
1+
# Dockerfile.fenics
2+
# Stage 1: reuse ci-base to get meshes & project
3+
FROM ci-base AS mesh-stage
4+
5+
# Stage 2: Fenics runtime image
16
FROM dolfinx/dolfinx:v0.9.0
7+
ARG DEBIAN_FRONTEND=noninteractive
8+
9+
# -----------------------------
10+
# 1) Copy project + generated meshes from ci-base
11+
# -----------------------------
12+
# copy the whole /sim produced by ci-base to /sim in final image
13+
COPY --from=mesh-stage /sim /sim
14+
15+
# -----------------------------
16+
# 2) Install any Python packages missing from dolfinx that fenics scripts need
17+
# -----------------------------
18+
RUN python3 -m pip install --upgrade pip setuptools wheel
19+
# add packages required by fenics scripts (meshio, pyvista, pint, sympy, gmsh python API if needed)
20+
RUN python3 -m pip install --no-cache-dir meshio pyvista pint sympy
221

322
# -----------------------------
4-
# Install system dependencies
23+
# 3) User + permissions (ensure sim exists)
524
# -----------------------------
6-
RUN apt-get update && apt-get install -y \
7-
cmake \
8-
gcc \
9-
g++ \
10-
git \
11-
gmsh \
12-
libgomp1 \
13-
libxrender1 \
14-
libxext6 \
15-
libglu1-mesa \
16-
&& rm -rf /var/lib/apt/lists/*
25+
# attempt to create sim user only if not present; avoid overwriting /sim
26+
RUN id -u sim >/dev/null 2>&1 || useradd -m -s /bin/bash sim
27+
RUN chown -R sim:sim /sim
1728

18-
# Install Python dependencies missing in the image
19-
RUN python3 -m pip install --upgrade pip
20-
RUN python3 -m pip install pint sympy pyvista gmsh
29+
WORKDIR /sim
30+
VOLUME /sim/shared
31+
USER sim
2132

22-
WORKDIR /workspace/benchmarks/linear-elastic-plate-with-hole
33+
# -----------------------------
34+
# 4) Build-time Fenics simulations (bake results into image)
35+
# -----------------------------
36+
WORKDIR /sim/benchmarks/linear-elastic-plate-with-hole
37+
38+
RUN mkdir -p results/fenics && \
39+
for f in parameters_*.json; do \
40+
cfg="${f%.json}"; \
41+
python3 fenics/run_fenics_simulation.py \
42+
--input_parameter_file "$f" \
43+
--input_mesh_file results/linear-elastic-plate-with-hole/mesh/mesh_${cfg}.msh \
44+
--output_solution_file_zip results/fenics/solution_field_data_${cfg}.zip \
45+
--output_metrics_file results/fenics/solution_metrics_${cfg}.json; \
46+
done
47+
48+
# -----------------------------
49+
# 5) Final
50+
# -----------------------------
51+
WORKDIR /sim
52+
ENTRYPOINT ["/bin/bash"]

dockerfiles/Dockerfile.kratos

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
FROM ci-base AS kratos
1+
FROM ci-base
22

3-
# -----------------------------
4-
# Install system dependencies
5-
# -----------------------------
6-
RUN apt-get update && apt-get install -y \
7-
cmake \
8-
gcc \
9-
g++ \
10-
git \
11-
gmsh \
12-
libgomp1 \
13-
libxrender1 \
14-
libxext6 \
15-
libglu1-mesa \
16-
&& rm -rf /var/lib/apt/lists/*
3+
ARG DEBIAN_FRONTEND=noninteractive
174

18-
# Python dependencies for Kratos simulations
19-
RUN pip install meshio pyvista pint sympy KratosMultiphysics-all gmsh
5+
# Only pip packages required
6+
RUN python3 -m pip install --upgrade pip setuptools wheel && \
7+
python3 -m pip install --no-cache-dir KratosMultiphysics-all meshio pyvista pint sympy
208

21-
WORKDIR /workspace/benchmarks/linear-elastic-plate-with-hole
9+
# User (already exists in ci-base)
10+
USER sim
11+
WORKDIR /sim
12+
VOLUME /sim/shared
13+
14+
# Run Kratos simulations
15+
WORKDIR /sim/benchmarks/linear-elastic-plate-with-hole
16+
RUN mkdir -p results/kratos && \
17+
for f in parameters_*.json; do \
18+
python3 kratos/msh_to_mdpa.py \
19+
--input_parameter_file "$f" \
20+
--input_mesh_file results/linear-elastic-plate-with-hole/mesh/mesh_${f%.json}.msh \
21+
--output_mdpa_file results/kratos/mesh_${f%.json}.mdpa; \
22+
python3 kratos/create_kratos_input.py \
23+
--input_parameter_file "$f" \
24+
--input_mdpa_file results/kratos/mesh_${f%.json}.mdpa \
25+
--input_kratos_input_template kratos/input_template.json \
26+
--input_material_template kratos/StructuralMaterials_template.json \
27+
--output_kratos_inputfile results/kratos/ProjectParameters_${f%.json}.json \
28+
--output_kratos_materialfile results/kratos/MaterialParameters_${f%.json}.json; \
29+
python3 kratos/run_kratos_simulation.py \
30+
--input_parameter_file "$f" \
31+
--input_kratos_inputfile results/kratos/ProjectParameters_${f%.json}.json \
32+
--input_kratos_materialfile results/kratos/MaterialParameters_${f%.json}.json; \
33+
done
34+
35+
ENTRYPOINT ["/bin/bash"]

0 commit comments

Comments
 (0)