Skip to content

Commit e216848

Browse files
authored
Merge pull request #932 from ianmcorvidae/fixup-container
Fix up the container build
2 parents 8f0faf5 + dd1df47 commit e216848

4 files changed

Lines changed: 41 additions & 23 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
!Containerfile*
33
!Dockerfile
44
!README.md
5+
!LICENSE.md
56
!bin/container-entrypoint.sh
67
!examples/
78
!extra/

.github/workflows/container-build.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ jobs:
7575
push: ${{ github.event_name != 'pull_request' }}
7676
tags: ${{ steps.meta.outputs.tags }}
7777
labels: ${{ steps.meta.outputs.labels }}
78+
cache-from: type=gha
79+
cache-to: type=gha,mode=max

Containerfile.alpine

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,31 @@
55
ARG TARGET_VERSION="3.11-alpine"
66
ARG TARGET_ARCH="library"
77

8-
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
8+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION} AS builder
99

1010
WORKDIR /tmp/build
1111

12-
COPY . /tmp/build
12+
COPY pyproject.toml poetry.lock /tmp/build/
13+
14+
RUN apk add --no-cache --virtual .build-deps build-base libffi-dev && \
15+
pip install --no-cache-dir 'poetry==2.4.1' && \
16+
poetry config virtualenvs.create false && \
17+
poetry install --without dev --extras cli --extras tunnel --no-interaction --no-ansi --no-root
18+
19+
COPY . /tmp/build/
20+
21+
RUN poetry build --format wheel --no-interaction
1322

14-
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
15-
apk add --no-cache libffi && \
16-
apk add --no-cache --virtual .build-deps build-base libffi-dev && \
17-
python -m 'venv' "${_poetry_venv_dir}" && \
18-
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
19-
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
20-
"${_poetry_venv_dir}/bin/poetry" install --without dev --extras cli --extras tunnel --no-interaction --no-ansi && \
21-
apk del .build-deps && \
23+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
24+
25+
RUN apk add --no-cache libffi && \
2226
addgroup -S meshtastic && \
23-
adduser -S -G meshtastic -h /home/meshtastic meshtastic && \
24-
rm -f -r "${_poetry_venv_dir}" && \
25-
rm -f -r "/tmp/build"
27+
adduser -S -G meshtastic -h /home/meshtastic meshtastic
28+
29+
COPY --from=builder /tmp/build/dist/*.whl /tmp/
30+
31+
RUN wheel=$(echo /tmp/meshtastic-*.whl) && pip install --no-cache-dir "${wheel}[cli,tunnel]" && \
32+
rm -f /tmp/meshtastic-*.whl
2633

2734
COPY "./bin/container-entrypoint.sh" "/init"
2835
RUN chmod 0755 /init

Containerfile.debian

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@
55
ARG TARGET_VERSION="3.11"
66
ARG TARGET_ARCH="library"
77

8-
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
8+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION} AS builder
99

1010
WORKDIR /tmp/build
1111

12-
COPY . /tmp/build
12+
COPY pyproject.toml poetry.lock /tmp/build/
13+
14+
RUN pip install --no-cache-dir 'poetry==2.4.1' && \
15+
poetry config virtualenvs.create false && \
16+
poetry install --without dev --extras cli --extras tunnel --no-interaction --no-ansi --no-root
17+
18+
COPY . /tmp/build/
19+
20+
RUN poetry build --format wheel --no-interaction
21+
22+
FROM docker.io/${TARGET_ARCH}/python:${TARGET_VERSION}
23+
24+
RUN useradd --system --create-home --home-dir /home/meshtastic meshtastic
25+
26+
COPY --from=builder /tmp/build/dist/*.whl /tmp/
1327

14-
RUN _poetry_venv_dir="$(mktemp -d -p "${TMPDIR:-/tmp}" 'poetry_venv.XXXXXX')" && \
15-
python -m 'venv' "${_poetry_venv_dir}" && \
16-
"${_poetry_venv_dir}/bin/pip" install --no-cache-dir 'poetry' && \
17-
"${_poetry_venv_dir}/bin/poetry" config --local virtualenvs.create false && \
18-
"${_poetry_venv_dir}/bin/poetry" install --without dev --extras cli --extras tunnel --no-interaction --no-ansi && \
19-
useradd --system --create-home --home-dir /home/meshtastic meshtastic && \
20-
rm -f -r "${_poetry_venv_dir}" && \
21-
rm -f -r "/tmp/build"
28+
RUN wheel=$(echo /tmp/meshtastic-*.whl) && pip install --no-cache-dir "${wheel}[cli,tunnel]" && \
29+
rm -f /tmp/meshtastic-*.whl
2230

2331
COPY "./bin/container-entrypoint.sh" "/init"
2432
RUN chmod 0755 /init

0 commit comments

Comments
 (0)