88# (No error and it worked!)
99ARG PYTHON_RELEASE=3.12 ALPINE_VERSION=3.21
1010ARG BASE_IMAGE=python:${PYTHON_RELEASE}-alpine${ALPINE_VERSION}
11+ # ARG BASE_IMAGE=ghcr.io/astral-sh/uv:alpine${ALPINE_VERSION}
12+ # ARG BASE_IMAGE=ghcr.io/astral-sh/uv:python${PYTHON_RELEASE}-alpine
1113# Image for building dependencies (on architectures that don't provide a ready-made Python wheel)
1214FROM ${BASE_IMAGE} AS builder
1315
@@ -16,6 +18,20 @@ FROM ${BASE_IMAGE} AS builder
1618# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
1719ARG TARGETARCH
1820ARG TARGETVARIANT
21+ ARG PYTHON_RELEASE
22+
23+ ENV UV_LOCKED=true
24+ ENV UV_COMPILE_BYTECODE=true
25+ ENV UV_LINK_MODE=copy
26+ ENV UV_PROJECT_ENVIRONMENT=/usr/local
27+ ENV UV_SYSTEM_PYTHON=true
28+ ENV UV_NO_MANAGED_PYTHON=true
29+ ENV PYTHONPATH="/usr/lib/python${PYTHON_RELEASE}/site-packages"
30+
31+ RUN --mount=type=cache,id=apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk/ \
32+ apk add curl && curl -LsSf https://astral.sh/uv/install.sh | ash
33+
34+ ENV PATH="/root/.local/bin/:$PATH"
1935
2036# A workaround for compiling the `orsjson` package with rust: see https://github.com/rust-lang/cargo/issues/6513#issuecomment-1440029221
2137ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
@@ -26,19 +42,21 @@ ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
2642# Install system dependencies, saving the apk cache with docker mount: https://docs.docker.com/build/cache/#keep-layers-small
2743# Specify the architecture in the cache id, otherwise the apk cache of different architectures will conflict
2844RUN --mount=type=cache,id=apk-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/var/cache/apk/ \
29- if [ "$TARGETARCH" = "arm" ]; then\
30- apk add git rust cargo &&\
31- apk add build-base cython;\
32- fi
33-
34- # Copy requirements file of AppDaemon
35- COPY ./requirements.txt /usr/src/app/
45+ if [ "$TARGETARCH" = "arm" ]; then apk add git build-base cython rust cargo; fi
3646
3747# Install the Python dependencies of AppDaemon
3848# Save the pip cache with docker mount: https://docs.docker.com/build/cache/#keep-layers-small
3949# (specify the architecture in the cache id, otherwise the pip cache of different architectures will conflict)
40- RUN --mount=type=cache,id=pip-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache/pip \
41- pip install --disable-pip-version-check -r /usr/src/app/requirements.txt
50+ RUN --mount=type=cache,id=uv-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache/uv \
51+ --mount=type=bind,source=uv.lock,target=uv.lock \
52+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
53+ uv sync --inexact --no-install-project --no-dev --no-editable
54+
55+ RUN --mount=type=cache,id=uv-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache/uv \
56+ --mount=type=bind,source=./dist,target=/dist \
57+ uv pip install /dist/*.whl
58+
59+ ENTRYPOINT [ "/bin/ash" ]
4260
4361# ##################################
4462# Runtime image
@@ -48,21 +66,17 @@ ARG TARGETARCH
4866ARG TARGETVARIANT
4967ARG PYTHON_RELEASE
5068
51- # Copy the python dependencies built and installed in the previous stage
52- COPY --from=builder /usr/local/lib/python${PYTHON_RELEASE}/site-packages /usr/local/lib/python${PYTHON_RELEASE}/site-packages
69+ # Install curl to allow for healthchecks
70+ RUN apk --no-cache add curl
5371
54- WORKDIR /usr/src/app
72+ # Copy sample configuration directory and entrypoint script
73+ COPY ./conf /opt/conf
74+ COPY ./scripts/start.sh /start.sh
5575
56- # Install Appdaemon from the Python package built in the project `dist/` folder
57- RUN --mount=type=cache,id=pip-${TARGETARCH}-${TARGETVARIANT},sharing=locked,target=/root/.cache/pip,from=builder \
58- # Mount the project directory containing the built Python package, so it is available for pip install inside the container
59- --mount=type=bind,source=./dist/,target=/usr/src/app/ \
60- # Install the package
61- pip --disable-pip-version-check install *.whl
76+ # Copy the python dependencies built and installed in the previous stage
77+ COPY --from=builder /usr/local /usr/local
6278
63- # Copy sample configuration directory and entrypoint script
64- COPY ./conf ./conf
65- COPY ./dockerStart.sh .
79+ ENV PYTHONPATH="/usr/lib/python${PYTHON_RELEASE}/site-packages"
6680
6781# API Port
6882EXPOSE 5050
@@ -71,11 +85,5 @@ EXPOSE 5050
7185VOLUME /conf
7286VOLUME /certs
7387
74- # Add paths used by alpine python packages to python search path
75- ENV PYTHONPATH=/usr/lib/python${PYTHON_RELEASE}:/usr/lib/python${PYTHON_RELEASE}/site-packages
76-
77- # Define entrypoint script
78- ENTRYPOINT ["./dockerStart.sh" ]
79-
80- # Install curl to allow for healthchecks
81- RUN apk --no-cache add curl
88+ WORKDIR /conf
89+ ENTRYPOINT [ "/start.sh" ]
0 commit comments