-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
59 lines (42 loc) · 1.51 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
FROM python:3.12 as base
ENV WORKDIR=/app \
CONFIG=/data/settings.yaml \
LOG_LEVEL=ERROR \
LOG_FILE=/data/logs/plejd.log \
LOG_FILE_HC=/data/logs/healthcheck.log \
CACHE_FILE=/data/site.json
RUN apt-get update \
&& apt-get --no-install-recommends install -y bluez=5.66-1 bluetooth=5.66-1 \
&& rm -rf /var/lib/apt/lists/* \
&& adduser --disabled-password --gecos '' plejd
WORKDIR $WORKDIR
RUN chown plejd:plejd $WORKDIR
# Start building stage
FROM base as builder
USER plejd
RUN pip install --no-cache-dir --user poetry==1.7.1
# Ensure the poetry command is available
ENV PATH="/home/plejd/.local/bin:${POETRY_HOME}/bin:${PATH}"
# Copy poetry files
COPY poetry.lock pyproject.toml README.md $WORKDIR/
# Copy application files
COPY ./plejd_mqtt_ha $WORKDIR/plejd_mqtt_ha
# Install and build dependencies using poetry
RUN poetry config virtualenvs.in-project true && \
poetry install --only=main --no-root && \
poetry build
# Start final stage
FROM base as final
RUN adduser plejd bluetooth
ENV PYTHONPATH="$WORKDIR/.venv/lib/python3.12/site-packages:${PYTHONPATH}"
# Copy the built virtualenv deps from the builder stage
COPY --from=builder /app/.venv $WORKDIR/.venv
COPY --from=builder /app/dist $WORKDIR/
COPY docker-entrypoint.sh $WORKDIR/
RUN ./.venv/bin/pip install "$WORKDIR"/*.whl
# Healthcheck
COPY healthcheck.py $WORKDIR/healthcheck.py
HEALTHCHECK --interval=1m --timeout=1s \
CMD su plejd -c "python healthcheck.py" || exit 1
# Set the entrypoint
ENTRYPOINT ["./docker-entrypoint.sh"]