|
| 1 | +ARG PYTHON_VERSION=3.11-bullseye |
| 2 | + |
| 3 | +# define an alias for the specfic python version used in this file. |
| 4 | +FROM python:${PYTHON_VERSION} AS python |
| 5 | + |
| 6 | +# Python build stage |
| 7 | +FROM python AS python-build-stage |
| 8 | + |
| 9 | +ARG BUILD_ENVIRONMENT=local |
| 10 | + |
| 11 | +# Install apt packages |
| 12 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 13 | + # dependencies for building Python packages |
| 14 | + build-essential \ |
| 15 | + git \ |
| 16 | + # psycopg2 dependencies |
| 17 | + libpq-dev \ |
| 18 | + # other dependencies |
| 19 | + software-properties-common \ |
| 20 | + libopenblas-dev \ |
| 21 | + libomp-dev |
| 22 | + |
| 23 | +# Instalar gcc-10 y g++-10 en Debian Bullseye |
| 24 | +RUN apt-get update && \ |
| 25 | + apt-get install -y gcc-10 g++-10 ninja-build cmake && \ |
| 26 | + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 50 && \ |
| 27 | + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 50 && \ |
| 28 | + apt-get clean && rm -rf /var/lib/apt/lists/* |
| 29 | + |
| 30 | +# Configurar variables de entorno para compilar con BLAS y SIMD condicionalmente |
| 31 | +ARG ENABLE_OPTIMIZATIONS=true |
| 32 | +ENV CFLAGS="${ENABLE_OPTIMIZATIONS:+-mfma -mavx2}" \ |
| 33 | + CXXFLAGS="${ENABLE_OPTIMIZATIONS:+-mfma -mavx2}" \ |
| 34 | + CMAKE_ARGS="${ENABLE_OPTIMIZATIONS:+-DGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS}" |
| 35 | + |
| 36 | +# Actualizar pip, setuptools y wheel antes de instalar dependencias |
| 37 | +RUN python -m pip install --upgrade pip setuptools wheel |
| 38 | + |
| 39 | +# Requirements are installed here to ensure they will be cached. |
| 40 | +COPY ./requirements . |
| 41 | + |
| 42 | +# Create application directory to hold DOCX layouts |
| 43 | +COPY ./docx_layouts . |
| 44 | + |
| 45 | +# Update pip |
| 46 | +RUN python -m pip install --upgrade pip |
| 47 | + |
| 48 | +# Create Python Dependency and Sub-Dependency Wheels. |
| 49 | +RUN pip wheel --wheel-dir /usr/src/app/wheels \ |
| 50 | + -r ${BUILD_ENVIRONMENT}.txt \ |
| 51 | + -r extra-llama.txt |
| 52 | + |
| 53 | +# Python 'run' stage |
| 54 | +FROM python AS python-run-stage |
| 55 | + |
| 56 | +ARG BUILD_ENVIRONMENT=local |
| 57 | +ARG APP_HOME=/app |
| 58 | + |
| 59 | +ENV PYTHONUNBUFFERED 1 |
| 60 | +ENV PYTHONDONTWRITEBYTECODE 1 |
| 61 | +ENV BUILD_ENV ${BUILD_ENVIRONMENT} |
| 62 | + |
| 63 | +WORKDIR ${APP_HOME} |
| 64 | + |
| 65 | +RUN sed -i 's/main/main contrib non-free/' /etc/apt/sources.list |
| 66 | + |
| 67 | +# Install required system dependencies |
| 68 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 69 | + # psycopg2 dependencies |
| 70 | + libpq-dev \ |
| 71 | + # Translations dependencies |
| 72 | + gettext \ |
| 73 | + # libreoffice for document conversions |
| 74 | + default-jre libreoffice libreoffice-java-common ttf-mscorefonts-installer fonts-liberation fonts-liberation2 fonts-crosextra-carlito fonts-crosextra-caladea fonts-dejavu fonts-noto \ |
| 75 | + # cleaning up unused files |
| 76 | + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ |
| 77 | + && rm -rf /var/lib/apt/lists/* |
| 78 | + |
| 79 | +# All absolute dir copies ignore workdir instruction. All relative dir copies are wrt to the workdir instruction |
| 80 | +# copy python dependency wheels from python-build-stage |
| 81 | +COPY --from=python-build-stage /usr/src/app/wheels /wheels/ |
| 82 | + |
| 83 | +# Use wheels to install python dependencies |
| 84 | +RUN pip install --no-cache-dir --no-index --find-links=/wheels/ $(find /wheels/ -name "*.whl") \ |
| 85 | + && rm -rf /wheels/ |
| 86 | + |
| 87 | +COPY ./compose/production/django/entrypoint /entrypoint |
| 88 | +RUN sed -i 's/\r$//g' /entrypoint |
| 89 | +RUN chmod +x /entrypoint |
| 90 | + |
| 91 | +COPY ./compose/local/django/start /start |
| 92 | +RUN sed -i 's/\r$//g' /start |
| 93 | +RUN chmod +x /start |
| 94 | + |
| 95 | +COPY ./compose/local/django/celery/worker/start /start-celeryworker |
| 96 | +RUN sed -i 's/\r$//g' /start-celeryworker |
| 97 | +RUN chmod +x /start-celeryworker |
| 98 | + |
| 99 | +COPY ./compose/local/django/celery/beat/start /start-celerybeat |
| 100 | +RUN sed -i 's/\r$//g' /start-celerybeat |
| 101 | +RUN chmod +x /start-celerybeat |
| 102 | + |
| 103 | +COPY ./compose/local/django/celery/flower/start /start-flower |
| 104 | +RUN sed -i 's/\r$//g' /start-flower |
| 105 | +RUN chmod +x /start-flower |
| 106 | + |
| 107 | +# copy application code to WORKDIR |
| 108 | +COPY . ${APP_HOME} |
| 109 | + |
| 110 | +ENTRYPOINT ["/entrypoint"] |
0 commit comments