From da8bce74ae6944176d74a8fe8087e6961deb5b3e Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Thu, 9 Jan 2025 16:34:39 +0100
Subject: [PATCH] pip container: Build from Poetry and install wheel (#498)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

For some reasons, pip/setuptools was installing
g1_monetary_license directory alongside Silkaj sources
It does not seems to be the case anymore,
I can’t find this information in setuptools changelog

In pyproject.toml, [tool.poetry.include] field is for Poetry usage
There is a way with setuptools I did not manage to make it work
https://setuptools.pypa.io/en/latest/userguide/datafiles.html

Instead, build wheel from Poetry, copy it and install it to Py image

Keep the image standalone, independent from poetry image (#483)
Install Poetry v1 (#499)

Remove unnecessary duplicate ARG argument
---
 image/pip | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/image/pip b/image/pip
index bac7d01d..ff099e56 100644
--- a/image/pip
+++ b/image/pip
@@ -4,19 +4,22 @@
 ARG PYTHON_VERS
 FROM python:${PYTHON_VERS}-slim AS build
 
+# Install Poetry
+RUN pip install "poetry>=1.8,<2.0"
+
 WORKDIR /silkaj
 
 # Copy source tree
 COPY ./ ./
 
 # Install Silkaj
-RUN pip install . silkaj[deathreaper]
+RUN poetry install --only main --extras deathreaper
+RUN poetry build
 
 # ------------------------------------------------------------------------------
 # Final Stage
 # ------------------------------------------------------------------------------
 FROM python:${PYTHON_VERS}-slim
-ARG PYTHON_VERS
 
 # Set timezone to Paris for DeathReaper
 ENV TZ=Europe/Paris
@@ -31,8 +34,8 @@ RUN apt update && \
     rm -rf /var/lib/apt/lists
 
 # Copy the build artifact from the build stage
-COPY --from=build /usr/local/bin/silkaj /usr/local/bin/silkaj
-COPY --from=build /usr/local/lib/python${PYTHON_VERS}/site-packages/ /usr/local/lib/python${PYTHON_VERS}/site-packages/
+COPY --from=build "/silkaj/dist/silkaj-*-py3-none-any.whl" .
+RUN pip install silkaj-*-py3-none-any.whl
 
 # Use silkaj user
 USER silkaj
-- 
GitLab