Fix up the container build to use a multi-stage build, cache better, and most importantly actually keep the library in the final image (fixes #931)

This commit is contained in:
Ian McEwen
2026-06-08 13:28:09 -07:00
parent 8f0faf5c3f
commit dd1df473c7
4 changed files with 41 additions and 23 deletions

View File

@@ -5,20 +5,28 @@
ARG TARGET_VERSION="3.11"
ARG TARGET_ARCH="library"
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION} AS builder
WORKDIR /tmp/build
COPY . /tmp/build
COPY pyproject.toml poetry.lock /tmp/build/
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
python -m 'venv' "${_poetry_venv_dir}" && \
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
"${_poetry_venv_dir}/bin/poetry" install --without dev --extras cli --extras tunnel --no-interaction --no-ansi && \
useradd --system --create-home --home-dir /home/meshtastic meshtastic && \
rm -f -r "${_poetry_venv_dir}" && \
rm -f -r "/tmp/build"
RUN pip install --no-cache-dir 'poetry==2.4.1' && \
poetry config virtualenvs.create false && \
poetry install --without dev --extras cli --extras tunnel --no-interaction --no-ansi --no-root
COPY . /tmp/build/
RUN poetry build --format wheel --no-interaction
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
RUN useradd --system --create-home --home-dir /home/meshtastic meshtastic
COPY --from=builder /tmp/build/dist/*.whl /tmp/
RUN wheel=$(echo /tmp/meshtastic-*.whl) && pip install --no-cache-dir "${wheel}[cli,tunnel]" && \
rm -f /tmp/meshtastic-*.whl
COPY "./bin/container-entrypoint.sh" "/init"
RUN chmod 0755 /init