FROM python:3.7-alpine3.15

WORKDIR /app

COPY . /app/

RUN apk add --update --no-cache \
    git \
    build-base \
    openldap-dev \
    python3-dev \
    libpq-dev \
    libjpeg \
    libmemcached-dev \
    libxml2-dev \
    libxslt-dev \
    zlib \
    jpeg-dev \
    zlib-dev \
    && rm -rf /var/cache/apk/*

# FIX https://github.com/python-ldap/python-ldap/issues/432
RUN echo 'INPUT ( libldap.so )' > /usr/lib/libldap_r.so

#RUN LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pip install --no-cache-dir -r requirements.txt"

# Create a virtual environment
RUN python3 -m venv /venv

ENV PATH="/venv/bin:$PATH"

RUN pip install  --no-cache-dir --upgrade pip

#RUN CFLAGS="-Wno-cpp -Wno-unused-function -Wno-unused-variable -Wno-missing-noreturn -I/usr/include/libxml2" pip install lxml

RUN pip install --no-cache-dir -r requirements.txt

# Copy entrypoint.sh script and grant execute permissions
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Run migrations and start the server
ENTRYPOINT ["/entrypoint.sh"]