From 505922969967ca011431ef53f7121e934b999b15 Mon Sep 17 00:00:00 2001 From: Sphericalkat Date: Sat, 25 May 2024 13:40:59 +0530 Subject: [PATCH] feat: dockerize Signed-off-by: Sphericalkat --- .dockerignore | 4 ++++ Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + test.py | 0 4 files changed, 41 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 test.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ea47ffe --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.env +.venv +*.pyc +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1119a67 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Python 3.11 +FROM python@sha256:091e0f5da680e5c972c59cb7eca172141bb6350045b592c284e2fd3bf2916dd9 as build + +# Install OS dependencies +RUN apt-get update && apt-get install -y build-essential curl + +# Set venv +ENV VIRTUAL_ENV=/opt/venv \ + PATH="/opt/venv/bin:$PATH" + +# Install uv +ADD https://astral.sh/uv/install.sh /install.sh +RUN chmod -R 655 /install.sh && /install.sh && rm /install.sh + +# Create a virtual environment and install dependencies +COPY ./requirements.txt . +RUN /root/.cargo/bin/uv venv /opt/venv && \ + /root/.cargo/bin/uv pip install --no-cache -r requirements.txt + +# Python 3.11-slim-bookworm app image +FROM python@sha256:fc39d2e68b554c3f0a5cb8a776280c0b3d73b4c04b83dbade835e2a171ca27ef + +# Copy the virtual environment from the previous image +COPY --from=build /opt/venv /opt/venv + +# Activate the virtual environment +ENV PATH="/opt/venv/bin:$PATH" + +# Set the working directory +WORKDIR /app + +# Copy the code +COPY . . + +# Run the application +CMD ["python", "main.py"] diff --git a/requirements.txt b/requirements.txt index b7cc31c..03a48f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,6 +25,7 @@ pip==24.0 preshed==3.0.9 pydantic==2.7.1 pydantic-core==2.18.2 +pydantic-settings==2.2.1 python-telegram-bot==21.2 requests==2.32.2 setuptools==70.0.0 diff --git a/test.py b/test.py deleted file mode 100644 index e69de29..0000000