-
Notifications
You must be signed in to change notification settings - Fork 168
feat(BA-2327): dockerize agent with DooD (Docker-out-of-Docker) #9596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
12406ad
17aeee4
400bb44
fd95f8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Dockerize the agent component with DooD (Docker-out-of-Docker) support, including krunner path sharing, REPL port binding fixes, and comprehensive Docker deployment documentation for all six components |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # DooD (Docker-out-of-Docker) krunner path setup | ||
| # | ||
| # In DooD mode, the agent creates session containers via the host Docker daemon. | ||
| # When the agent bind-mounts krunner files (runner, kernel, helpers) into session | ||
| # containers, Docker resolves the source paths on the HOST filesystem, not inside | ||
| # the agent container. To make these paths accessible from the host, we: | ||
| # 1. Copy krunner packages to a shared volume path (/tmp/backend-ai-krunner/) | ||
| # 2. Replace the originals with symlinks so importlib.resources.files() resolves | ||
| # to the shared path (via Path.resolve() in resolve_krunner_filepath) | ||
|
|
||
| KRUNNER_SHARED="/tmp/backend-ai-krunner" | ||
|
|
||
| if [ -d "$KRUNNER_SHARED" ]; then | ||
| SITE_PKG=$(python3 -c "import site; print(site.getsitepackages()[0])") | ||
| for pkg in runner kernel helpers; do | ||
| src="$SITE_PKG/ai/backend/$pkg" | ||
| dst="$KRUNNER_SHARED/$pkg" | ||
| if [ -d "$src" ] && [ ! -L "$src" ]; then | ||
| # First run: copy packages to shared volume and create symlinks | ||
| cp -r "$src" "$dst" | ||
| rm -rf "$src" | ||
| ln -s "$dst" "$src" | ||
| elif [ -L "$src" ]; then | ||
| # Already symlinked (container restart) | ||
| : | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| exec "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ARG PYTHON_VERSION | ||
| FROM python:${PYTHON_VERSION} AS builder | ||
| ARG PKGVER | ||
| COPY dist /dist | ||
| COPY requirements.txt /requirements.txt | ||
| # Install dependencies from requirements.txt to respect version constraints | ||
| RUN pip wheel --wheel-dir=/wheels --no-cache-dir -r /requirements.txt | ||
| # Install backend.ai packages from /dist (these are not in requirements.txt or PyPI) | ||
| RUN pip wheel --wheel-dir=/wheels --no-cache-dir backend.ai-agent==${PKGVER} --find-links=/dist --no-deps | ||
|
|
||
| FROM python:${PYTHON_VERSION} | ||
|
||
| COPY --from=builder /wheels /wheels | ||
| COPY dist /dist | ||
| # Install all wheels and also look in /dist for backend.ai packages | ||
| RUN pip install --no-cache-dir --find-links=/dist /wheels/*.whl | ||
|
|
||
| # Install Docker CLI for DooD (Docker-out-of-Docker) operations | ||
| RUN install -m 0755 -d /etc/apt/keyrings \ | ||
| && curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \ | ||
| && chmod a+r /etc/apt/keyrings/docker.asc \ | ||
| && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list \ | ||
| && apt-get update \ | ||
| && apt-get install -y --no-install-recommends docker-ce-cli \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
Comment on lines
+18
to
+24
|
||
|
|
||
| # Create necessary directories | ||
| RUN mkdir -p /tmp/backend.ai/ipc /var/log/backend.ai /etc/backend.ai \ | ||
| /var/lib/backend.ai | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| COPY docker/agent-entrypoint.sh /usr/local/bin/agent-entrypoint.sh | ||
| RUN chmod +x /usr/local/bin/agent-entrypoint.sh | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/agent-entrypoint.sh"] | ||
| CMD ["backend.ai", "ag", "start-server", "-f", "/etc/backend.ai/agent.toml"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the full
python:${PYTHON_VERSION}base for both stages significantly increases image size and pull time. If OS packages/build tooling aren’t required at runtime (beyond installingdocker-ce-cli), consider switching the runtime stage to a slimmer variant (e.g.,python:${PYTHON_VERSION}-slim) and only add the minimal apt packages needed for Docker CLI + certs.