Skip to content

feat(images): add apt_sources_mirror() chainable method for Debian builds - #5668

Open
Goutham-Annem wants to merge 1 commit into
bentoml:mainfrom
Goutham-Annem:feat/apt-sources-mirror
Open

feat(images): add apt_sources_mirror() chainable method for Debian builds#5668
Goutham-Annem wants to merge 1 commit into
bentoml:mainfrom
Goutham-Annem:feat/apt-sources-mirror

Conversation

@Goutham-Annem

Copy link
Copy Markdown

Summary

Adds a new chainable apt_sources_mirror(url: str) method to the Image builder class (closes #5374).

  • Users in regions with slow Debian mirrors can now call .apt_sources_mirror("https://...") on their image to swap the default http://deb.debian.org/debian URL before any apt-get invocation.
  • The implementation inserts a sed command that tries the Debian 12+ debian.sources file first, then falls back to the legacy sources.list, so it works across Debian releases without any extra configuration.
  • Two unit tests are added in tests/unit/_bentoml_sdk/test_images.py to verify the generated command and that the method returns self for chaining.

Usage example:

from _bentoml_sdk.images import Image

image = (
    Image("debian:latest")
    .apt_sources_mirror("https://mirrors.tuna.tsinghua.edu.cn/debian")
    .system_packages("curl", "git")
)

Test plan

  • pytest tests/unit/_bentoml_sdk/test_images.py — all three tests pass (existing + two new ones).
  • Manually verify the generated Dockerfile contains the sed line before apt-get install.

Note: This PR was developed with AI assistance (Claude Code).

…ilds

Add a new chainable method `apt_sources_mirror(url)` to the `Image` class
that inserts a `sed` command before `apt-get update` to swap the default
Debian mirror URL (http://deb.debian.org/debian) with a user-supplied URL.

The command handles both Debian 12+ (debian.sources format) and older
Debian releases (sources.list format) via a fallback OR expression.

Closes bentoml#5374
@Goutham-Annem
Goutham-Annem requested a review from a team as a code owner July 23, 2026 05:34
@Goutham-Annem
Goutham-Annem requested review from parano and removed request for a team July 23, 2026 05:34
@Goutham-Annem

Copy link
Copy Markdown
Author

Hi — the Veracode SCA and Static Analysis failures appear to be pre-existing and unrelated to this PR's changes (they fire on all recent PRs). Could a maintainer confirm whether these are expected to pass before merge, or if they can be waived? Happy to address any actual code feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: How to change APT source when building BentoML container image? Slow build due to using deb.debian.org

1 participant