Skip to content

Commit 3a05179

Browse files
read dependencies from centralized xml
1 parent c8c30b7 commit 3a05179

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

dockers/deploy.bat

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
set krversion=10.3.0
2-
set pyversion=3.11
2+
set pyversion=3.12
33
@REM 3.10.10-alpine3.17
44
echo "Building kratos %krversion% on python %pyversion%"
5-
docker build --build-arg krversion=%krversion% --build-arg pyversion=%pyversion% -t kratos-run:%krversion% -t kratos-run:latest .
5+
set SCRIPT_DIR=%~dp0
6+
set ROOT_DIR=%SCRIPT_DIR%..
7+
8+
docker build --build-arg pyversion=%pyversion% -f "%ROOT_DIR%\dockers\dockerfile" -t kratos-run:%krversion% -t kratos-run:latest "%ROOT_DIR%"
69

710
docker tag kratos-run:%krversion% fjgarate/kratos-run:%krversion%
811
docker push fjgarate/kratos-run:%krversion%

dockers/dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# Default values. Use --build-arg on build to change
2-
ARG pyversion=3.11
2+
ARG pyversion=3.12
33

44
# Base pyton image
55
FROM python:$pyversion
6-
# FROM python:3.10.10-alpine3.17
76

87
# Update pip
98
RUN pip install --upgrade pip
109

11-
ARG krversion=10.3.0
12-
1310
# WORKDIR /tmp
1411
# COPY ./wheels/ ./wheels/
1512

16-
# Install Kratos and dependencies
17-
RUN python3 -m pip install KratosMultiphysics-all==$krversion numpy
13+
# Copy dependency manifest from Kratos GiD
14+
COPY kratos.gid/kratos.xml /tmp/kratos.xml
15+
COPY dockers/generate_requirements_from_xml.py /tmp/generate_requirements_from_xml.py
16+
17+
# Install Kratos packages listed in kratos.xml
18+
RUN python3 /tmp/generate_requirements_from_xml.py --xml /tmp/kratos.xml --out /tmp/requirements.txt \
19+
&& python3 -m pip install --no-cache-dir -r /tmp/requirements.txt
1820
# RUN python3 -m pip install ./wheels/*.whl
1921

2022
# Prepare run folder
@@ -24,5 +26,5 @@ RUN chmod 777 /model
2426
# Kratos will start on docker run
2527
CMD [ "python3", "MainKratos.py" ]
2628

27-
# docker build -t kratos-run .
29+
# docker build -t kratos-run -f dockers/dockerfile .
2830
# docker run -rm -it --entrypoint bash kratos-run
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import argparse
2+
import xml.etree.ElementTree as ET
3+
from pathlib import Path
4+
5+
6+
def build_requirements(xml_path: Path) -> list[str]:
7+
root = ET.parse(xml_path).getroot()
8+
requirements: list[str] = []
9+
seen: set[str] = set()
10+
11+
for package in root.findall("./Program/PythonPackages/Package"):
12+
name = (package.get("Name") or "").strip()
13+
version = (package.get("Version") or "").strip()
14+
if not name:
15+
continue
16+
17+
requirement = f"{name}=={version}" if version else name
18+
if requirement in seen:
19+
continue
20+
21+
requirements.append(requirement)
22+
seen.add(requirement)
23+
24+
return requirements
25+
26+
27+
def main() -> None:
28+
parser = argparse.ArgumentParser()
29+
parser.add_argument("--xml", required=True)
30+
parser.add_argument("--out", required=True)
31+
args = parser.parse_args()
32+
33+
xml_path = Path(args.xml)
34+
out_path = Path(args.out)
35+
requirements = build_requirements(xml_path)
36+
requirements.append("numpy")
37+
38+
out_path.write_text("\n".join(requirements) + "\n", encoding="utf-8")
39+
40+
41+
if __name__ == "__main__":
42+
main()

0 commit comments

Comments
 (0)