From d39e06ae077f80e6be72dea01d1ee938d3d551fb Mon Sep 17 00:00:00 2001 From: Matteo Saloni Date: Mon, 24 Jun 2024 16:22:41 +0200 Subject: [PATCH] fix: fix python build issues with requirements --- .../src/main/resources/application.yml | 4 ++-- .../runtime/python/model/PythonVersion.java | 4 ++-- .../python/runners/PythonBuildRunner.java | 24 ++++++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/application/src/main/resources/application.yml b/application/src/main/resources/application.yml index d635bb13f..7414daa51 100644 --- a/application/src/main/resources/application.yml +++ b/application/src/main/resources/application.yml @@ -68,8 +68,8 @@ runtime: image: ${RUNTIME_KFP_IMAGE:ghcr.io/scc-digitalhub/digitalhub-core-wrapper-kfp:latest} python: images: - PYTHON_3_9: ${RUNTIME_PYTHON_IMAGE_3_9:ghcr.io/scc-digitalhub/digitalhub-serverless/python-runtime-3.9:latest} - PYTHON_3_10: ${RUNTIME_PYTHON_IMAGE_3_10:ghcr.io/scc-digitalhub/digitalhub-serverless/python-runtime-3.10:latest} + PYTHON3_9: ${RUNTIME_PYTHON_IMAGE_3_9:ghcr.io/scc-digitalhub/digitalhub-serverless/python-runtime-3.9:latest} + PYTHON3_10: ${RUNTIME_PYTHON_IMAGE_3_10:ghcr.io/scc-digitalhub/digitalhub-serverless/python-runtime-3.10:latest} command: /usr/local/bin/processor diff --git a/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/model/PythonVersion.java b/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/model/PythonVersion.java index 357ba5d44..33af4181c 100644 --- a/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/model/PythonVersion.java +++ b/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/model/PythonVersion.java @@ -1,8 +1,8 @@ package it.smartcommunitylabdhub.runtime.python.model; public enum PythonVersion { - PYTHON_3_9("3.9"), - PYTHON_3_10("3.10"); + PYTHON3_9("3.9"), + PYTHON3_10("3.10"); private final String version; diff --git a/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/runners/PythonBuildRunner.java b/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/runners/PythonBuildRunner.java index 5b84c451b..5209ac381 100644 --- a/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/runners/PythonBuildRunner.java +++ b/modules/runtime-python/src/main/java/it/smartcommunitylabdhub/runtime/python/runners/PythonBuildRunner.java @@ -145,6 +145,20 @@ public K8sKanikoRunnable produce(Run run) { } } + // install all requirements + dockerfileGenerator.run( + "python /opt/nuclio/whl/$(basename /opt/nuclio/whl/pip-*.whl)/pip install pip --no-index --find-links /opt/nuclio/whl " + + "&& python -m pip install -r /opt/nuclio/requirements/common.txt" + + "&& python -m pip install -r /opt/nuclio/requirements/" + + functionSpec.getPythonVersion().name().toLowerCase() + + ".txt" + ); + + // Add user instructions + Optional + .ofNullable(taskSpec.getInstructions()) + .ifPresent(instructions -> instructions.forEach(i -> dockerfileGenerator.run(i))); + // If requirements.txt are defined add to build if (functionSpec.getRequirements() != null && !functionSpec.getRequirements().isEmpty()) { //write file @@ -158,17 +172,9 @@ public K8sKanikoRunnable produce(Run run) { .build() ); // install all requirements - dockerfileGenerator.run( - "python /opt/nuclio/whl/$(basename /opt/nuclio/whl/pip-*.whl)/pip install pip --no-index --find-links /opt/nuclio/whl " + - "&& python -m pip install -r /shared/requirements.txt" - ); + dockerfileGenerator.run("python -m pip install -r /shared/requirements.txt"); } - // Add user instructions - Optional - .ofNullable(taskSpec.getInstructions()) - .ifPresent(instructions -> instructions.forEach(i -> dockerfileGenerator.run(i))); - // Set entry point dockerfileGenerator.entrypoint(List.of(command));