-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
93 lines (63 loc) · 2.94 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# syntax=docker.io/docker/dockerfile:1.11.1@sha256:10c699f1b6c8bdc8f6b4ce8974855dd8542f1768c26eb240237b8f1c9c6c9976
# Building wheels for later useage
FROM python:3.12.5@sha256:11aa4b620c15f855f66f02a7f3c1cd9cf843cc10f3edbcf158e5ebcd98d1f549 as builder-base
RUN <<eot
apt update
apt install python3-dev pkg-config -y --no-install-recommends
rm -rf /var/lib/apt/lists/*
eot
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y --profile=minimal \
&& rm -rf /root/.rustup/tmp
ENV PATH="/root/.cargo/bin:${PATH}"
# used for building wheels out of requirements.txt
FROM builder-base as w-builder
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG REQUIREMENTS_FILE=requirements.txt
COPY ${REQUIREMENTS_FILE} ./
ARG CARGO_NET_GIT_FETCH_WITH_CLI=true
ARG RUSTFLAGS=" -C lto=no"
RUN --mount=type=bind,source=./wheelhouse/,target=/oldwheels <<eot
export CARGO_BUILD_TARGET="$(rustc -vV | sed -n 's|host: ||p')"
ARCHDIR=$(find /oldwheels -mindepth 1 -maxdepth 2 -regextype posix-extended -type d -regex ".*/${TARGETOS}_${TARGETARCH}(_${TARGETVARIANT})?$")
pip wheel --no-cache-dir --wheel-dir /wheels --find-links file:////$ARCHDIR/wheels -r ${REQUIREMENTS_FILE}
eot
# && pip wheel --wheel-dir /wheels
# pyaml
FROM scratch AS export-stage
COPY --from=w-builder /wheels ./wheels
# base fhempy will be installed
FROM python:3.12.5@sha256:11aa4b620c15f855f66f02a7f3c1cd9cf843cc10f3edbcf158e5ebcd98d1f549 as base
RUN apt update && \
apt install dbus python-dbus-dev curl -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./requirements.txt
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
RUN --mount=type=bind,source=./wheelhouse/,target=/wheels <<eot
ARCHDIR=$(find /wheels -mindepth 1 -maxdepth 2 -regextype posix-extended -type d -regex ".*/${TARGETOS}_${TARGETARCH}(_${TARGETVARIANT})?$")
pip install --no-index --find-links file:////$ARCHDIR/wheels --no-cache -r requirements.txt
eot
# image for fhempy modules (final stage) module will be installed here
FROM base as runtime
WORKDIR /usr/src/apps
#ARG PKGS=python3-dev
#RUN apt update && \
# apt install $PKGS -y --no-install-recommends \
# && rm -rf /var/lib/apt/lists/*
COPY requirements_mod.txt ./requirements.txt
#ARG CRYPTOGRAPHY_DONT_BUILD_RUST=1
# Disable installing from INDEX
ENV PIP_NO_INDEX=1
RUN --mount=type=bind,source=./wheelhouse/,target=/wheels <<eot
ARCHDIR=$(find /wheels -mindepth 1 -maxdepth 2 -regextype posix-extended -type d -regex ".*/${TARGETOS}_${TARGETARCH}(_${TARGETVARIANT})?$")
pip install --find-links file:////$ARCHDIR/wheels --no-cache -r requirements.txt
eot
#export RUSTFLAGS=" -C lto=no"
#export CARGO_BUILD_TARGET="$(rustc -vV | sed -n 's|host: ||p')"
COPY src/health-check.sh /health-check.sh
RUN chmod +x /health-check.sh
HEALTHCHECK --interval=50s --timeout=15s --start-period=10s --retries=3 CMD /health-check.sh
CMD [ "fhempy" ]