diff --git a/Dockerfile b/Dockerfile index 2300991..5096b08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,4 +49,4 @@ RUN --mount=type=bind,from=build,target=/tmp/build-layer,ro \ && rm -rf /tmp/r8 ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["/opt/r8/monobase/build.sh", "--help"] +CMD ["/opt/r8/monobase/run.sh", "monobase.build", "--help"] diff --git a/mini.Dockerfile b/mini.Dockerfile index 8c5370a..ba00f10 100644 --- a/mini.Dockerfile +++ b/mini.Dockerfile @@ -21,4 +21,4 @@ RUN /opt/r8/monobase/build.sh --skip-cuda --mini # Install a user venv # Do not reinstall uv & pget -RUN NO_REINSTALL=1 /opt/r8/monobase/build.sh --skip-cuda --mini --requirements /tmp/requirements.txt +RUN /opt/r8/monobase/run.sh monobase.build --skip-cuda --mini --requirements /tmp/requirements.txt diff --git a/script/build-prod b/script/build-prod index e1498d0..27ad3ff 100755 --- a/script/build-prod +++ b/script/build-prod @@ -7,7 +7,7 @@ main() { cd "$(git rev-parse --show-toplevel)" printf '# ---> using kubectl context "%s"\n' "$(kubectl config current-context)" - exec ./script/run-oneoff-pod build /opt/r8/monobase/build.sh "${@}" + exec ./script/run-oneoff-pod build /opt/r8/monobase/run.sh monobase.build "${@}" } main "${@}" diff --git a/script/test b/script/test index 235b98c..5fcaa8e 100755 --- a/script/test +++ b/script/test @@ -21,7 +21,8 @@ docker run --rm \ --volume "$PWD/build/nfd-features.d:/etc/kubernetes/node-feature-discovery/features.d" \ -e OTEL_EXPORTER_OTLP_ENDPOINT \ monobase:latest \ - /opt/r8/monobase/build.sh \ + /opt/r8/monobase/run.sh \ + monobase.build \ --environment test \ --skip-cuda \ --cog-versions \ diff --git a/script/test-mini b/script/test-mini index 628aed0..23974f3 100755 --- a/script/test-mini +++ b/script/test-mini @@ -26,7 +26,8 @@ docker run --rm \ --volume "$PWD/build/monobase:/srv/r8/monobase" \ --volume "$PWD/build/cache:/var/cache/monobase" \ monobase:latest \ - /opt/r8/monobase/build.sh \ + /opt/r8/monobase/run.sh \ + monobase.build \ --environment test \ --skip-cuda \ --mini \ diff --git a/src/monobase/build.sh b/src/monobase/run.sh similarity index 68% rename from src/monobase/build.sh rename to src/monobase/run.sh index 7aedb85..7d4fe43 100755 --- a/src/monobase/build.sh +++ b/src/monobase/run.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Build monobase +# Run Python modules in monobase set -euo pipefail @@ -15,10 +15,15 @@ log() { echo "$(date --iso-8601=seconds --utc) $*" } +if [ $# -lt 1 ]; then + echo "Usage: $(basename "$0") [arg]..." + exit 1 +fi + # Always install latest uv and pget first # Unless explicitly disabled, e.g. in Dockerfile # So that we do not repack these into a user layer -if [ -z "${NO_REINSTALL:-}" ]; then +if ! [ -f "$MONOBASE_PREFIX/bin/uv" ] || ! [ -f "$MONOBASE_PREFIX/bin/pget-bin" ]; then mkdir -p "$MONOBASE_PREFIX/bin" log "Installing uv..." @@ -34,8 +39,12 @@ if [ -z "${NO_REINSTALL:-}" ]; then cp /opt/r8/monobase/pget "$MONOBASE_PREFIX/bin/pget" fi -uv venv /var/tmp/.venv --python='3.13' -VIRTUAL_ENV=/var/tmp/.venv uv pip install --link-mode=copy "$(find /opt/r8 -name '*.whl' | head -1)" +if ! [ -d /var/tmp/.venv ]; then + uv venv /var/tmp/.venv --python='3.13' + VIRTUAL_ENV=/var/tmp/.venv uv pip install --link-mode=copy "$(find /opt/r8 -name '*.whl' | head -1)" +fi -log "Running monobase.build..." -exec /var/tmp/.venv/bin/python -m monobase.build "$@" +module="$1" +shift +log "Running $module..." +exec /var/tmp/.venv/bin/python -m "$module" "$@"