From 5f30683e55c3d2ca47a5546e4443e8d3873610ba Mon Sep 17 00:00:00 2001
From: stynoo <17745813+stynoo@users.noreply.github.com>
Date: Sun, 15 Dec 2024 20:05:05 +0100
Subject: [PATCH] Dockerfile: best practices & prep for supercronic usage

---
 Dockerfile | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 1266019..80ec168 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,26 +1,32 @@
 FROM python:3.12-alpine
 
-RUN adduser -D withings-sync
+ENV PROJECT=withings-sync
+ENV PACKAGE=withings_sync
+ENV PROJECT_DIR=/home/$PROJECT
 
-USER withings-sync
-WORKDIR /home/withings-sync
+RUN apk --no-cache add supercronic
 
-ENV PATH="/home/withings-sync/.poetry/bin:${PATH}" \
-    PATH="/home/withings-sync/.local/bin:${PATH}" \
+RUN adduser -D $PROJECT
+
+USER $PROJECT
+WORKDIR $PROJECT_DIR
+
+ENV PATH="${PROJECT_DIR}/.poetry/bin:${PATH}" \
+    PATH="${PROJECT_DIR}/.local/bin:${PATH}" \
     PIP_ROOT_USER_ACTION=ignore \
     PIP_DISABLE_PIP_VERSION_CHECK=on \
-    POETRY_HOME=/home/withings-sync/.poetry \
+    POETRY_HOME="${PROJECT_DIR}/.poetry" \
     POETRY_NO_INTERACTION=1 \
     POETRY_VIRTUALENVS_IN_PROJECT=1 \
     POETRY_VIRTUALENVS_CREATE=1 \
-    POETRY_CACHE_DIR=/tmp/poetry_cache
+    POETRY_CACHE_DIR="/tmp/poetry_cache"
 
 RUN pip install poetry
 
-COPY --chown=withings-sync:withings-sync pyproject.toml poetry.lock README.md ./
+COPY --chown=$PROJECT:$PROJECT pyproject.toml poetry.lock README.md $PROJECT_DIR/
 RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
 
-COPY --chown=withings-sync:withings-sync withings_sync ./withings_sync/
+COPY --chown=$PROJECT:$PROJECT $PACKAGE ./$PACKAGE/
 RUN poetry install --without dev
 
 ENTRYPOINT ["poetry", "run", "withings-sync"]