Skip to content

Commit

Permalink
Generalize build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
nevillelyh committed Jan 14, 2025
1 parent 1b2d87e commit 19302f0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion mini.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion script/build-prod
Original file line number Diff line number Diff line change
Expand Up @@ -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 "${@}"
3 changes: 2 additions & 1 deletion script/test
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion script/test-mini
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
21 changes: 15 additions & 6 deletions src/monobase/build.sh → src/monobase/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Build monobase
# Run Python modules in monobase

set -euo pipefail

Expand All @@ -15,10 +15,15 @@ log() {
echo "$(date --iso-8601=seconds --utc) $*"
}

if [ $# -lt 1 ]; then
echo "Usage: $(basename "$0") <module> [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..."
Expand All @@ -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" "$@"

0 comments on commit 19302f0

Please sign in to comment.