From aa29eb27f88186185a9817c99f0d6314627bd3e4 Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 14 Jul 2025 14:30:42 +0100 Subject: [PATCH] multibuild and pin package --- dockerfile | 48 +++++++++++++++++++++++++++++------------------- requirements.txt | 2 +- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/dockerfile b/dockerfile index f4301dc..a412489 100644 --- a/dockerfile +++ b/dockerfile @@ -1,31 +1,41 @@ -FROM python:3.11-slim-bookworm +# ---- Builder Stage ---- +FROM python:3.11-slim-bookworm as builder -RUN apt-get update && apt-get install -y --no-install-recommends \ - git \ - libglib2.0-0 \ - libsm6 \ - libxrender1 \ - libxext6 \ - libgomp1 \ - libgl1 \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* +# Install git for fetching git-based dependencies +RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/* +# Create a virtual environment +RUN python -m venv /opt/venv + +# Activate the virtual environment +ENV PATH="/opt/venv/bin:$PATH" + +# Copy requirements and install dependencies WORKDIR /app - COPY requirements.txt . -RUN pip install --no-cache-dir requests stem -RUN pip install --no-cache-dir git+https://github.com/karl0ss/requests_tor.git@ae1e85abb3bb2c25f431bd031c6d881986c626f6 RUN pip install --no-cache-dir -r requirements.txt +# ---- Final Stage ---- +FROM python:3.11-slim-bookworm + +# Set working directory +WORKDIR /app + +# Copy virtual environment from builder stage +COPY --from=builder /opt/venv /opt/venv + +# Activate the virtual environment +ENV PATH="/opt/venv/bin:$PATH" +ENV FLASK_ENV=production + +# Copy application code COPY . . - +# Handle versioning ARG VERSION -RUN echo $VERSION > VERSION +RUN if [ -n "$VERSION" ]; then echo $VERSION > VERSION; fi -EXPOSE 3001 - -ENV FLASK_ENV=production +# Make run script executable and run the application RUN chmod +x run_docker.sh +EXPOSE 3001 CMD ["./run_docker.sh"] diff --git a/requirements.txt b/requirements.txt index a89131c..2ee7b48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,4 +17,4 @@ urllib3==2.4.0 gunicorn Flask PyJWT -pycryptodome \ No newline at end of file +pycryptodome==3.20.0 \ No newline at end of file