Skip to content

Commit d815c09

Browse files
authored
Flatten published Docker image (#6812)
This flattens the Docker image from 9 layers to 5 by using multi-stage build that squashes layers into logical blocks. The first layer on top of the base image adds system-wide packages and uv (which is not updated so often - if it were, it may be wise to move it into the next or separate layer; it weights roughly 50 MB) which should be preserved between releases, while the next layer adds all Supervisor Python code and dependencies. This means that unless the base image or packages installed in the first stage are changed (or in other words, only Supervisor code is changed), only a single layer is pulled from the repository. Previously, it generally resulted in pull of all the following 4 layers, as just a change in the requirements invalidated the following layers. The fetched payload size remains roughly the same.
1 parent c772a9b commit d815c09

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

Dockerfile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
ARG BUILD_FROM=ghcr.io/home-assistant/base-python:3.14-alpine3.22-2026.04.0
2-
FROM ${BUILD_FROM}
2+
FROM ${BUILD_FROM} AS supervisor-base
33

44
ENV \
55
S6_SERVICES_GRACETIME=10000 \
66
SUPERVISOR_API=http://localhost \
77
CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 \
88
UV_SYSTEM_PYTHON=true
99

10-
# Install base
11-
WORKDIR /usr/src
10+
# Install OS packages used both by build and final image
1211
RUN \
1312
set -x \
1413
&& apk add --no-cache \
@@ -24,6 +23,14 @@ RUN \
2423
\
2524
&& pip3 install uv==0.10.9
2625

26+
#############################################
27+
# Install requirements and build Supervisor #
28+
#############################################
29+
30+
FROM supervisor-base AS supervisor-build
31+
32+
WORKDIR /usr/src
33+
2734
# Install requirements
2835
RUN \
2936
--mount=type=bind,source=./requirements.txt,target=/usr/src/requirements.txt \
@@ -47,10 +54,18 @@ RUN \
4754
&& uv pip install --no-cache -e ./supervisor \
4855
&& python3 -m compileall ./supervisor/supervisor
4956

50-
51-
WORKDIR /
57+
# Copy the rest of rootfs files
5258
COPY rootfs /
5359

60+
#########################
61+
# Final flattened image #
62+
#########################
63+
64+
FROM supervisor-base
65+
66+
# Copy everything from the build stage as a single layer
67+
COPY --from=supervisor-build / /
68+
5469
LABEL \
5570
io.hass.type="supervisor" \
5671
org.opencontainers.image.title="Home Assistant Supervisor" \

0 commit comments

Comments
 (0)