Skip to content

Commit d749fd9

Browse files
committed
feat: override default package sources to build plugin testbeds
1 parent f13c321 commit d749fd9

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ARG APK_BUILD_DEPS=""
2323
ARG DEFAULT_PIP_SOURCES="beets-beatport4 beets-filetote git+https://github.com/edgars-supe/beets-importreplace.git requests requests_oauthlib beautifulsoup4 pyacoustid pylast python3-discogs-client langdetect flask Pillow"
2424
# Space-separated distribution names installed in the runtime stage
2525
ARG DEFAULT_PIP_PACKAGES="beets-beatport4 beets-filetote beets-importreplace requests requests_oauthlib beautifulsoup4 pyacoustid pylast python3-discogs-client langdetect flask Pillow"
26+
# Space-separated override mappings ("pkg=spec") replacing sources in DEFAULT_PIP_SOURCES
27+
ARG PIP_SOURCE_OVERRIDES=""
2628
# Space-separated user Python packages to bundle (wheels built & installed)
2729
ARG USER_PIP_PACKAGES=""
2830
# -----------------------------------------------------------
@@ -93,6 +95,30 @@ RUN --mount=type=cache,id=builder-pip,target=/root/.cache/pip,sharing=locked \
9395
done; \
9496
default_packages="${filtered# }"; \
9597
fi; \
98+
overrides="${PIP_SOURCE_OVERRIDES}"; \
99+
if [ -n "${overrides}" ]; then \
100+
for override in ${overrides}; do \
101+
pkg="${override%%=*}"; \
102+
src="${override#*=}"; \
103+
if [ -z "${pkg}" ] || [ -z "${src}" ] || [ "${pkg}" = "${src}" ]; then \
104+
echo "Invalid pip override '${override}'. Expected key=value." >&2; \
105+
exit 1; \
106+
fi; \
107+
filtered=''; \
108+
for entry in ${default_sources}; do \
109+
if [ "${entry}" = "${pkg}" ]; then \
110+
continue; \
111+
fi; \
112+
filtered="${filtered} ${entry}"; \
113+
done; \
114+
default_sources="${filtered# }"; \
115+
if [ -n "${default_sources}" ]; then \
116+
default_sources="${default_sources} ${src}"; \
117+
else \
118+
default_sources="${src}"; \
119+
fi; \
120+
done; \
121+
fi; \
96122
tmp_dir="$(mktemp -d)"; \
97123
mv "${beets_wheel}" "${tmp_dir}/"; \
98124
if [ -n "${default_sources}" ]; then \

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,29 @@ docker build \
183183
| `BEETS_REF` | The git ref of [`beetbox/beets`](https://github.com/beetbox/beets) to build (tag, branch, or SHA) |
184184
| `APK_BUILD_DEPS` | Space-separated list of Alpine packages to install at build time |
185185
| `APK_RUNTIME_EXTRAS` | Space-separated list of Alpine packages to include in the final image |
186+
| `PIP_SOURCE_OVERRIDES` | Space-separated overrides in the form `package=spec`, replacing entries in `DEFAULT_PIP_SOURCES` |
186187
| `USER_PIP_PACKAGES` | Space-separated list of user Python packages (wheels). Must already exist on PyPI or a compatible index so they can be wheeled offline. |
187188

189+
#### Overriding default pip sources
190+
191+
Set `PIP_SOURCE_OVERRIDES` to point specific packages at alternative sources (e.g., Git forks) without editing the Dockerfile:
192+
193+
```bash
194+
docker build \
195+
--build-arg PIP_SOURCE_OVERRIDES="beets-beatport4=git+https://github.com/you/beets-beatport4.git@testing" \
196+
-t treyturner/beets:test-fork .
197+
```
198+
199+
For sources already specified as full VCS URLs (like `importreplace`, which defaults to `git+https://github.com/edgars-supe/beets-importreplace.git`), you need to match the exact token:
200+
201+
```bash
202+
docker build \
203+
--build-arg PIP_SOURCE_OVERRIDES="git+https://github.com/edgars-supe/beets-importreplace.git=git+https://github.com/you/beets-importreplace.git@integration-tests" \
204+
-t treyturner/beets:test-importreplace .
205+
```
206+
207+
Multiple overrides can be separated by spaces, as long as each value has no whitespace.
208+
188209
### Container Lifecycle Overview
189210

190211
Where each build argument and environment variable applies during the image build and container startup sequence.
@@ -202,7 +223,7 @@ Where each build argument and environment variable applies during the image buil
202223
flowchart TD
203224
A1["<strong>Build Args</strong><br/>PYTHON_VERSION<br/>PYTHON_BASE_SUFFIX"] --> B0
204225
A2["<strong>Build Arg</strong><br/>APK_BUILD_DEPS"] --> B1
205-
A3["<strong>Build Args</strong><br/>BEETS_REF<br/>DEFAULT_PIP_SOURCES<br/>DEFAULT_PIP_PACKAGES<br/>USER_PIP_PACKAGES"] --> B2
226+
A3["<strong>Build Args</strong><br/>BEETS_REF<br/>DEFAULT_PIP_SOURCES<br/>PIP_SOURCE_OVERRIDES<br/>DEFAULT_PIP_PACKAGES<br/>USER_PIP_PACKAGES"] --> B2
206227
A4["<strong>Build Arg</strong><br/>APK_RUNTIME_EXTRAS"] --> R1
207228
A5["<strong>Build Args</strong><br/>DEFAULT_PIP_PACKAGES<br/>USER_PIP_PACKAGES"] --> R2
208229
A6["<strong>Env. Vars</strong><br/>PUID<br/>PGID<br/>UMASK"] --> E1

0 commit comments

Comments
 (0)