Skip to content

Commit

Permalink
fix dockerfile to install dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
blefnk committed Mar 26, 2024
1 parent 1395c0e commit 44fc291
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 52 deletions.
77 changes: 39 additions & 38 deletions backend/dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
# Using a slim version for a smaller base image
FROM python:3.11.6-slim-bullseye@sha256:0c1fbb294096d842ad795ee232d783cab436c90b034210fe894f2bb2f2be7626

RUN useradd -ms /bin/bash user
USER user

# Define development mode environment variables
ARG DEV_MODE
ENV DEV_MODE=$DEV_MODE

# Install GEOS library, Rust, and other dependencies, then clean up
# RUN apt-get clean && apt-get update && apt-get install -y \
# libgeos-dev \
# libcurl4-openssl-dev \
# libssl-dev \
# binutils \
# pandoc \
# curl \
# git \
# poppler-utils \
# tesseract-ocr \
# autoconf \
# automake \
# build-essential \
# libtool \
# python-dev \
# build-essential \
# # Additional dependencies for document handling
# libmagic-dev \
# poppler-utils \
# tesseract-ocr \
# libreoffice \
# libpq-dev \
# gcc \
# pandoc && \
# rm -rf /var/lib/apt/lists/* && apt-get clean

# Add Rust binaries to the PATH
# ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /home/user
# Install geos, rust, and other dependencies, then clean up
RUN apt-get clean && apt-get update && apt-get install -y \
libgeos-dev \
libcurl4-openssl-dev \
libssl-dev \
binutils \
pandoc \
curl \
git \
poppler-utils \
tesseract-ocr \
autoconf \
automake \
build-essential \
libtool \
python-dev \
build-essential \
# Additional dependencies
# for document handling
libmagic-dev \
poppler-utils \
tesseract-ocr \
libreoffice \
libpq-dev \
gcc \
pandoc && \
rm -rf /var/lib/apt/lists/* && apt-get clean

# Add rust binaries to the path
ENV PATH="/root/.cargo/bin:${PATH}"

# Create and select workspace dir
WORKDIR /code

# Copy just the requirements first
COPY requirements.txt .

# Upgrade pip
# Upgrade pip to the latest version
RUN pip install --upgrade pip

# Increase timeout to wait for the new installation
# RUN pip install --no-cache-dir -r requirements.txt --timeout 20000 && rm requirements.txt
RUN pip install -r requirements.txt && rm requirements.txt
# RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 200; fi
RUN pip install --no-cache-dir -r requirements.txt --timeout 20000 && rm requirements.txt
RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 200; fi

# Copy the rest of the application
COPY . .

# Listen on 10000 port instead 8080
EXPOSE 10000

# Launch the dockerized application
ENTRYPOINT [ "python", "main.py"]
59 changes: 59 additions & 0 deletions backend/dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Using a slim version for a smaller base image
FROM python:3.11.6-slim-bullseye@sha256:0c1fbb294096d842ad795ee232d783cab436c90b034210fe894f2bb2f2be7626

# Define development mode environment variables
ARG DEV_MODE
ENV DEV_MODE=$DEV_MODE

# Install geos, rust, and other dependencies, then clean up
RUN apt-get clean && apt-get update && apt-get install -y \
libgeos-dev \
libcurl4-openssl-dev \
libssl-dev \
binutils \
pandoc \
curl \
git \
poppler-utils \
tesseract-ocr \
autoconf \
automake \
build-essential \
libtool \
python-dev \
build-essential \
# Additional dependencies
# for document handling
libmagic-dev \
poppler-utils \
tesseract-ocr \
libreoffice \
libpq-dev \
gcc \
pandoc && \
rm -rf /var/lib/apt/lists/* && apt-get clean

# Add rust binaries to the path
ENV PATH="/root/.cargo/bin:${PATH}"

# Create and select workspace dir
WORKDIR /code

# Copy just the requirements first
COPY requirements.txt .

# Upgrade pip to the latest version
RUN pip install --upgrade pip

# Increase timeout to wait for the new installation
RUN pip install --no-cache-dir -r requirements.txt --timeout 200 && rm requirements.txt
RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 200; fi

# Copy the rest of the application
COPY . .

# Listen on 10000 port instead 8080
EXPOSE 10000

# Launch the dockerized application
ENTRYPOINT [ "python", "main.py"]
7 changes: 2 additions & 5 deletions backend/logger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging
from logging.handlers import RotatingFileHandler

from colorlog import (
ColoredFormatter,
) # You need to install this
# package: pip install colorlog
from colorlog import ColoredFormatter

def get_logger(logger_name, log_level=logging.INFO, log_file="application.log"):
logger = logging.getLogger(logger_name)
logger.setLevel(log_level)

# Prevent log propagation
# to avoid double logging
logger.propagate = False
Expand Down
6 changes: 3 additions & 3 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ def abc_test():

def debug_setup():
if getenv("DEV_MODE") == "true":
import debugpy # logger has flyctl crash
# logger.debug("👨‍💻 Running in dev mode")
import debugpy
logger.debug("👨‍💻 Running in dev mode")
debugpy.listen(("0.0.0.0", 5678))

def run_app():
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=10000)

if __name__ == "__main__":
# import needed here when running main.py to debug
# import needed here if you want debug main.py
from dotenv import load_dotenv # type: ignore
load_dotenv()
debug_setup()
Expand Down
11 changes: 5 additions & 6 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-i https://pypi.org/simple
# Ensure PyTorch, along with its required dependencies, is explicitly installed in 'CPU-only' mode to optimize compatibility and performance for systems without GPU support.
# Ensure pytorch, along with required dependencies, is explicitly installed in CPU-only
# mode to optimize the compatibility and performance for systems without GPU support.
--extra-index-url https://download.pytorch.org/whl/cpu
aiohttp==3.9.3; python_version >= '3.8'
aiosignal==1.3.1; python_version >= '3.7'
Expand Down Expand Up @@ -86,7 +87,6 @@ jieba3k==0.35.1
jinja2==3.1.3; python_version >= '3.7'
jmespath==1.0.1; python_version >= '3.7'
joblib==1.3.2; python_version >= '3.7'
### jq==1.6.0; python_version >= '3.5' ### 🔴 ERROR on Windows or flyctl
jsonpatch==1.33; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'
jsonpath-python==1.0.6; python_version >= '3.6'
jsonpointer==2.4; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'
Expand All @@ -102,7 +102,6 @@ langfuse==2.20.1; python_version < '4.0' and python_full_version >= '3.8.1'
langsmith==0.1.23; python_version < '4.0' and python_full_version >= '3.8.1'
layoutparser[layoutmodels,tesseract]==0.3.4; python_version >= '3.6'
litellm==1.31.2; python_version not in '2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7' and python_version >= '3.8'
### lxml==5.1.0; python_version >= '3.6' ### 🔴 newspaper3k 0.2.8 depends on lxml>=3.6.0 // pikepdf 8.13.0 depends on lxml<5 and >=4.8; python_version < "3.10"
markdown==3.5.2
markupsafe==2.1.5; python_version >= '3.7'
marshmallow==3.21.1; python_version >= '3.8'
Expand All @@ -115,7 +114,7 @@ msg-parser==1.2.0
multidict==6.0.5; python_version >= '3.7'
mypy-extensions==1.0.0; python_version >= '3.5'
nest-asyncio==1.5.6; python_version >= '3.5'
### networkx==3.2.1 ### 🔴 ERROR on Windows or flyctl
networkx==3.2.1
newspaper3k==0.2.8
nltk==3.8.1; python_version >= '3.7'
nodeenv==1.8.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'
Expand Down Expand Up @@ -149,14 +148,14 @@ prometheus-client==0.20.0; python_version >= '3.8'
prompt-toolkit==3.0.43; python_full_version >= '3.7.0'
protobuf==4.25.3; python_version >= '3.8'
psycopg2-binary==2.9.9; python_version >= '3.7'
### psycopg2==2.9.9; python_version >= '3.7' ### 🔴 ERROR on Windows or flyctl
psycopg2==2.9.9; python_version >= '3.7'
ptyprocess==0.7.0
pure-eval==0.2.2
pyasn1==0.5.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
pycocotools==2.0.7; python_version >= '3.5'
pycodestyle==2.11.1; python_version >= '3.8'
pycparser==2.21
### pycurl==7.45.3 ### 🔴 ERROR on Windows or flyctl
pycurl==7.45.3
pydantic-core==2.16.3; python_version >= '3.8'
pydantic-settings==2.2.1; python_version >= '3.8'
pydantic==2.6.3; python_version >= '3.8'
Expand Down

0 comments on commit 44fc291

Please sign in to comment.