-
Notifications
You must be signed in to change notification settings - Fork 435
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·90 lines (71 loc) · 3.6 KB
/
Dockerfile
File metadata and controls
executable file
·90 lines (71 loc) · 3.6 KB
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
# When changing this, make sure that the python major and minor version matches that provided by alpine's python3
# package (see https://pkgs.alpinelinux.org/packages), otherwise alpine py3-* packages won't work
# Due to incorrect PYTHONPATH
# Test from docker shell:
# $> apk add py3-scikit-learn
# $> python3
# >>> import sklearn
# (No error and it worked!)
ARG PYTHON_RELEASE=3.12 ALPINE_VERSION=3.22
ARG BASE_IMAGE=python:${PYTHON_RELEASE}-alpine${ALPINE_VERSION}
# Image for building dependencies (on architectures that don't provide a ready-made Python wheel)
FROM ${BASE_IMAGE} AS builder
# Build arguments populated automatically by docker during build with the target architecture we are building for (eg: 'amd64')
# Useful to differentiate the build process for each architecture
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH
ARG TARGETVARIANT
ARG PYTHON_RELEASE
ENV UV_LOCKED=true
ENV UV_COMPILE_BYTECODE=true
ENV UV_LINK_MODE=copy
ENV UV_PROJECT_ENVIRONMENT=/usr/local
ENV UV_SYSTEM_PYTHON=true
ENV UV_NO_MANAGED_PYTHON=true
ENV PYTHONPATH="/usr/lib/python${PYTHON_RELEASE}/site-packages"
RUN --mount=type=cache,id=apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk/ \
apk add uv
ENV PATH="/root/.local/bin/:$PATH"
# A workaround for compiling the `orsjson` package with rust: see https://github.com/rust-lang/cargo/issues/6513#issuecomment-1440029221
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
# If on ARM architecture install system packages to build native dependencies:
# - git and rust: build the `orsjson` package (required by `deepdiff`)
# - cython and build-base: build the `uvloop` package (build-base contains the set of basic tools to compile with gcc)
# Install system dependencies, saving the apk cache with docker mount: https://docs.docker.com/build/cache/#keep-layers-small
# Specify the architecture in the cache id, otherwise the apk cache of different architectures will conflict
RUN --mount=type=cache,id=apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk/ \
if [ "$TARGETARCH" = "arm" ]; then apk add git build-base cython rust cargo; fi
# Install the Python dependencies of AppDaemon
# Save the pip cache with docker mount: https://docs.docker.com/build/cache/#keep-layers-small
# (specify the architecture in the cache id, otherwise the pip cache of different architectures will conflict)
RUN --mount=type=cache,id=uv-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --inexact --no-install-project --no-dev --no-editable
RUN --mount=type=cache,id=uv-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache/uv \
--mount=type=bind,source=./dist,target=/dist \
uv pip install /dist/*.whl
ENTRYPOINT [ "/bin/ash" ]
###################################
# Runtime image
FROM ${BASE_IMAGE}
ARG TARGETARCH
ARG TARGETVARIANT
ARG PYTHON_RELEASE
# Install curl to allow for healthchecks
RUN apk --no-cache add curl
# Copy sample configuration directory and entrypoint script
COPY ./conf /opt/conf
COPY ./scripts/start.sh /start.sh
# Copy the python dependencies built and installed in the previous stage
COPY --from=builder /usr/local /usr/local
ENV PYTHONPATH="/usr/lib/python${PYTHON_RELEASE}/site-packages"
# API Port
EXPOSE 5050
# Mountpoints for configuration & certificates
VOLUME /conf
VOLUME /certs
WORKDIR /conf
ENTRYPOINT [ "/start.sh" ]
RUN --mount=type=cache,id=apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk/ \
apk add uv