Skip to content

Commit 0d1964d

Browse files
authored
docker: slim image, use rustup, build deps only on armv7 (#352)
1 parent 7fcb409 commit 0d1964d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ jobs:
6767
TAG_NAME=${GITHUB_REF##*/}
6868
# Change slashes to hyphens
6969
TAG_NAME=${TAG_NAME//\//-}
70-
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t flyte/mqtt-io:${TAG_NAME} -t flyte/mqtt-io:latest --push --build-arg BUILDX_QEMU_ENV=true .
70+
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t flyte/mqtt-io:${TAG_NAME} -t flyte/mqtt-io:latest --push .
7171
- if: github.event_name == 'push'
7272
run: |
7373
# Remove prefix push
7474
TAG_NAME=${GITHUB_REF##*/}
7575
# Change slashes to hyphens
7676
TAG_NAME=${TAG_NAME//\//-}
77-
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t flyte/mqtt-io:${TAG_NAME} --push --build-arg BUILDX_QEMU_ENV=true .
77+
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t flyte/mqtt-io:${TAG_NAME} --push .
7878
7979
generate_docs:
8080
name: Generate Documentation

Dockerfile

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
# when building multiarch using buildx, then try this:
44
# https://github.com/docker/buildx/issues/495#issuecomment-761562905
55

6-
FROM python:3.8-buster AS base
6+
FROM python:3.8-slim-buster AS base
77

88
ENV LANG C.UTF-8
99
ENV LC_ALL C.UTF-8
1010

1111

1212
FROM base AS requirements
1313

14-
ARG BUILDX_QEMU_ENV
15-
RUN apt-get update && \
16-
apt-get install -y lsb-release rustc libssl-dev libffi-dev python3-venv && \
17-
apt-get clean && \
18-
rm -rf /var/lib/apt-/lists/*
14+
# On linux/arm/v7 the cryptography package has no binary wheel, so we need its build
15+
# dependencies. For rust, install the latest from rustup to avoid issues.
16+
ARG TARGETPLATFORM
17+
RUN if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
18+
apt-get update && \
19+
apt-get install -y lsb-release curl g++ pkg-config libssl-dev libffi-dev && \
20+
\
21+
(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y) \
22+
fi
23+
ENV PATH="/root/.cargo/bin:${PATH}"
1924

20-
# This nonsense is required for this reason:
21-
# https://github.com/JonasAlfredsson/docker-nginx-certbot/issues/30
22-
23-
RUN pip install --no-cache-dir wheel setuptools-rust && \
24-
if [ "${BUILDX_QEMU_ENV}" = "true" -a "$(getconf LONG_BIT)" = "32" ]; then \
25-
pip install --no-cache-dir cryptography==3.3.2; \
26-
fi && \
27-
pip install --no-cache-dir poetry
2825

2926
COPY pyproject.toml ./
30-
RUN poetry export -o /requirements.txt && \
27+
RUN pip install --no-cache-dir poetry && \
28+
poetry export -o /requirements.txt && \
3129
mkdir -p /home/mqtt_io && \
3230
python -m venv /home/mqtt_io/venv && \
3331
/home/mqtt_io/venv/bin/pip install wheel
@@ -41,8 +39,8 @@ WORKDIR /home/mqtt_io
4139

4240
COPY --from=requirements --chown=mqtt_io /home/mqtt_io/venv ./venv
4341
COPY --from=requirements /requirements.txt ./
44-
RUN venv/bin/python -m pip install --upgrade pip
45-
RUN venv/bin/pip install -r requirements.txt
42+
RUN venv/bin/python -m pip install --no-cache-dir --upgrade pip
43+
RUN venv/bin/pip install --no-cache-dir -r requirements.txt
4644

4745
COPY --chown=mqtt_io mqtt_io mqtt_io
4846

0 commit comments

Comments
 (0)