diff --git a/llama_stack/distribution/build.py b/llama_stack/distribution/build.py index f376301f9..64e96f4b8 100644 --- a/llama_stack/distribution/build.py +++ b/llama_stack/distribution/build.py @@ -120,6 +120,7 @@ def build_image(build_config: BuildConfig, build_file_path: Path): docker_image, str(build_file_path), str(BUILDS_BASE_DIR / ImageType.docker.value), + "--use-host-network" if build_config.use_host_network else "", " ".join(normal_deps), ] elif build_config.image_type == ImageType.conda.value: diff --git a/llama_stack/distribution/build_container.sh b/llama_stack/distribution/build_container.sh index 49e65b8cb..d6e160fc5 100755 --- a/llama_stack/distribution/build_container.sh +++ b/llama_stack/distribution/build_container.sh @@ -10,6 +10,7 @@ LLAMA_MODELS_DIR=${LLAMA_MODELS_DIR:-} LLAMA_STACK_DIR=${LLAMA_STACK_DIR:-} TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-} BUILD_PLATFORM=${BUILD_PLATFORM:-} +USE_HOST_NETWORK=${USE_HOST_NETWORK:-} if [ "$#" -lt 4 ]; then echo "Usage: $0 []" >&2 @@ -163,14 +164,23 @@ if [ -n "$BUILD_PLATFORM" ]; then elif [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then PLATFORM="--platform linux/arm64" elif [ "$ARCH" = "x86_64" ]; then + # TODO: This is a hack, make the network host into a flag PLATFORM="--platform linux/amd64" else echo "Unsupported architecture: $ARCH" exit 1 fi +# Optionally add host network flag if requested. +# Set USE_HOST_NETWORK=1 (or "true") in the environment to enable it. +if [ "${USE_HOST_NETWORK:-}" = "1" ] || [ "${USE_HOST_NETWORK:-}" = "true" ]; then + HOST_NETWORK="--network host" +else + HOST_NETWORK="" +fi + set -x -$DOCKER_BINARY build $DOCKER_OPTS $PLATFORM -t $image_tag -f "$TEMP_DIR/Dockerfile" "$REPO_DIR" $mounts +$DOCKER_BINARY build $DOCKER_OPTS $PLATFORM $HOST_NETWORK -t $image_tag -f "$TEMP_DIR/Dockerfile" "$REPO_DIR" $mounts # clean up tmp/configs set +x diff --git a/llama_stack/distribution/datatypes.py b/llama_stack/distribution/datatypes.py index d0ccd6cd1..b6380b355 100644 --- a/llama_stack/distribution/datatypes.py +++ b/llama_stack/distribution/datatypes.py @@ -174,3 +174,7 @@ class BuildConfig(BaseModel): default="conda", description="Type of package to build (conda | docker | venv)", ) + use_host_network: bool = Field( + default=False, + description="Use host network for the build", + )