-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
48 lines (39 loc) · 1.47 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
FROM python:3.12.5-alpine AS deps
# Rust and Cargo are required to build `pyndatic-core` on ARM platforms
RUN apk add -U cargo git rust \
&& pip install build \
&& apk cache clean
# Limit use of the build context to the requirements file only, to avoid cache
# invalidation when other files get changed
COPY requirements.txt .
# Install dependencies in a separate layer to cache them
RUN pip install --root /tmp/target/ -r requirements.txt
FROM python:3.12.5-alpine AS build
RUN pip install build
# Build the package
ARG VERSION
RUN test -z "${VERSION}" && echo "No 'VERSION' argument provided, exiting" \
&& exit 1 || true
# Writeable mount is needed for src/*.egg-info the `setup` module wants to
# create. `pip install --no-deps` is to skip installing dependencies to the
# package thus requiring extra prerequisites and extending the build time -
# those already fulfilled by `deps` stage
RUN \
--mount=type=bind,target=source/,rw \
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_ENERGOMERA_HASS_MQTT=${VERSION} \
python -m build --outdir /tmp/dist/ source/ \
&& pip install --no-deps --root /tmp/target/ /tmp/dist/*-${VERSION}*.whl
FROM python:3.12.5-alpine
# Ensure all the OS updates are applied to the resulting image
RUN apk -U upgrade \
&& apk cache clean
COPY --from=deps \
/tmp/target/usr/local/lib/ \
/usr/local/lib/
COPY --from=build \
/tmp/target/usr/local/lib/ \
/usr/local/lib/
COPY --from=build \
/tmp/target/usr/local/bin/ \
/usr/local/bin/
ENTRYPOINT ["energomera-hass-mqtt"]