From 6cd0e677c802be15f637057ab3e6a5a3752b0e24 Mon Sep 17 00:00:00 2001
From: bennetrr <bennet@bennetr.me>
Date: Wed, 10 Apr 2024 13:48:38 +0200
Subject: [PATCH] chore: Use poetry in Dockerfile

---
 Dockerfile | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 004f60f..c3e7ced 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,18 +1,31 @@
 FROM python:3.12-slim
 
-# importing the action
-COPY ["src", "/action"]
+# Copy the action
+COPY ["src", "poetry.lock", "pyproject.toml", "/action/"]
 
-# installing the dependencies
-RUN pip install -r /action/requirements.txt
+# Install poetry
+# Thanks to Soof Golan and jjmerelo from StackOverflow: https://stackoverflow.com/a/72465422
+ARG POETRY_VERSION=1.8.2
+ENV POETRY_VENV=/opt/poetry-venv
+ENV POETRY_CACHE_DIR=/opt/.cache
+
+# Create a venv and install Poetry there
+RUN /usr/local/bin/python3.12 -m venv $POETRY_VENV
+RUN $POETRY_VENV/bin/python -m pip install -U pip setuptools
+RUN $POETRY_VENV/bin/python -m pip install poetry==${POETRY_VERSION}
+
+# Add Poetry to the PATH
+ENV PATH="${PATH}:${POETRY_VENV}/bin"
+
+RUN poetry -C /action install --no-interaction --no-cache --without dev
 
 # Print which git
 RUN echo "which git: $(which git)"
 
 # Install git
-RUN apt-get -yq update && apt-get -yq install git && rm -rf /var/lib/apt/lists/*
+RUN apt-get -yq update && \
+    apt-get -yq install git && \
+    rm -rf /var/lib/apt/lists/*
 
 RUN chmod +x /action/entrypoint.sh
-
-# Set the entrypoint
-ENTRYPOINT ["/action/entrypoint.sh"]
+ENTRYPOINT ["poetry", "-C", "/action", "run", "/action/entrypoint.sh"]