fix(ci): write requirements.txt in Python; bust DinD COPY cache
DinD legacy builder left requirements.txt empty when using shell redirect on a cached COPY pyproject.toml layer. Write deps from Python directly, add .ci-build-id COPY in CI, and preflight grep asyncpg in buildctx.
This commit is contained in:
parent
96b730653f
commit
1ac39da511
2 changed files with 20 additions and 11 deletions
|
|
@ -53,7 +53,10 @@ jobs:
|
||||||
# Runner DinD has legacy docker (no buildx); vendor hub-core into context.
|
# Runner DinD has legacy docker (no buildx); vendor hub-core into context.
|
||||||
mkdir -p buildctx/_hub_core_src
|
mkdir -p buildctx/_hub_core_src
|
||||||
cp -r /tmp/ctx-hub_core_src/pyproject.toml /tmp/ctx-hub_core_src/hub_core buildctx/_hub_core_src/
|
cp -r /tmp/ctx-hub_core_src/pyproject.toml /tmp/ctx-hub_core_src/hub_core buildctx/_hub_core_src/
|
||||||
|
echo "${SHORT}" > buildctx/.ci-build-id
|
||||||
|
grep -q 'asyncpg' buildctx/pyproject.toml
|
||||||
sed \
|
sed \
|
||||||
|
-e 's|^COPY pyproject.toml|COPY .ci-build-id /tmp/.ci-build-id\nCOPY pyproject.toml|' \
|
||||||
-e 's|COPY --from=hub_core_src pyproject.toml|COPY _hub_core_src/pyproject.toml|' \
|
-e 's|COPY --from=hub_core_src pyproject.toml|COPY _hub_core_src/pyproject.toml|' \
|
||||||
-e 's|COPY --from=hub_core_src hub_core/|COPY _hub_core_src/hub_core/|' \
|
-e 's|COPY --from=hub_core_src hub_core/|COPY _hub_core_src/hub_core/|' \
|
||||||
buildctx/Dockerfile > buildctx/Dockerfile.ci
|
buildctx/Dockerfile > buildctx/Dockerfile.ci
|
||||||
|
|
@ -62,7 +65,7 @@ jobs:
|
||||||
export PATH="${HOME}/bin:${PATH}"
|
export PATH="${HOME}/bin:${PATH}"
|
||||||
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" -u "${REGISTRY_USER}" --password-stdin
|
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" -u "${REGISTRY_USER}" --password-stdin
|
||||||
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
||||||
docker build --build-arg DEPS_LOCK_ID=2 -f buildctx/Dockerfile.ci \
|
docker build --build-arg DEPS_LOCK_ID=3 -f buildctx/Dockerfile.ci \
|
||||||
-t "${IMAGE}:latest" -t "${IMAGE}:main-${SHORT}" buildctx
|
-t "${IMAGE}:latest" -t "${IMAGE}:main-${SHORT}" buildctx
|
||||||
docker push "${IMAGE}:latest"
|
docker push "${IMAGE}:latest"
|
||||||
docker push "${IMAGE}:main-${SHORT}"
|
docker push "${IMAGE}:main-${SHORT}"
|
||||||
|
|
|
||||||
26
Dockerfile
26
Dockerfile
|
|
@ -14,10 +14,11 @@ RUN apt-get update \
|
||||||
COPY pyproject.toml ./
|
COPY pyproject.toml ./
|
||||||
|
|
||||||
# Bump DEPS_LOCK_ID when dependency wiring changes (busts DinD layer cache).
|
# Bump DEPS_LOCK_ID when dependency wiring changes (busts DinD layer cache).
|
||||||
ARG DEPS_LOCK_ID=2
|
ARG DEPS_LOCK_ID=3
|
||||||
RUN echo "deps-lock=${DEPS_LOCK_ID}" && python - <<'PY' > /tmp/requirements.txt
|
RUN echo "deps-lock=${DEPS_LOCK_ID}" && python - <<'PY'
|
||||||
import sys
|
import sys
|
||||||
import tomllib
|
import tomllib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
with open("pyproject.toml", "rb") as f:
|
with open("pyproject.toml", "rb") as f:
|
||||||
project = tomllib.load(f)["project"]
|
project = tomllib.load(f)["project"]
|
||||||
|
|
@ -26,15 +27,20 @@ deps = project.get("dependencies") or []
|
||||||
if not deps:
|
if not deps:
|
||||||
sys.exit("pyproject.toml has no dependencies")
|
sys.exit("pyproject.toml has no dependencies")
|
||||||
|
|
||||||
for dep in deps:
|
skip = {"llm-connect", "hub-core"}
|
||||||
# llm-connect is a local editable test integration and must not be pulled
|
lines = [
|
||||||
# into the production image. hub-core is runtime code, but it is installed
|
dep
|
||||||
# from the named Docker build context below because it is not published yet.
|
for dep in deps
|
||||||
if dep in {"llm-connect", "hub-core"}:
|
if dep not in skip
|
||||||
continue
|
]
|
||||||
print(dep)
|
if not lines:
|
||||||
|
sys.exit("no installable dependencies after filter")
|
||||||
|
|
||||||
|
Path("/tmp/requirements.txt").write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||||
|
if Path("/tmp/requirements.txt").stat().st_size == 0:
|
||||||
|
sys.exit("requirements.txt is empty")
|
||||||
|
print(f"wrote {len(lines)} requirements")
|
||||||
PY
|
PY
|
||||||
RUN test -s /tmp/requirements.txt
|
|
||||||
|
|
||||||
RUN uv venv /app/.venv \
|
RUN uv venv /app/.venv \
|
||||||
&& uv pip install --python /app/.venv/bin/python --no-cache -r /tmp/requirements.txt
|
&& uv pip install --python /app/.venv/bin/python --no-cache -r /tmp/requirements.txt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue