Allow build with host network

This commit is contained in:
benjibc 2025-01-13 21:44:26 +00:00
parent 78727aad26
commit c01a89c0e8
3 changed files with 16 additions and 1 deletions

View file

@ -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:

View file

@ -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 <build_name> <docker_base> <pip_dependencies> [<special_pip_deps>]" >&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

View file

@ -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",
)