2022-12-13 12:46:08 +00:00
|
|
|
FROM python:3.10-slim as base
|
|
|
|
|
|
|
|
# Setup env
|
|
|
|
ENV LANG C.UTF-8
|
|
|
|
ENV LC_ALL C.UTF-8
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE 1
|
|
|
|
ENV PYTHONFAULTHANDLER 1
|
|
|
|
|
|
|
|
FROM base AS python-deps
|
|
|
|
|
|
|
|
# Install pipenv and compilation dependencies
|
2023-03-06 19:44:45 +00:00
|
|
|
RUN pip install pipenv nltk
|
2023-02-10 12:45:44 +00:00
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev build-essential linux-libc-dev python-dev gcc postgresql postgresql-contrib && rm -rf /var/lib/apt/lists/*
|
2022-12-13 12:46:08 +00:00
|
|
|
|
|
|
|
# Install python dependencies in /.venv
|
|
|
|
COPY Pipfile .
|
|
|
|
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --skip-lock --verbose
|
|
|
|
|
|
|
|
FROM base AS runtime
|
|
|
|
|
|
|
|
# Copy virtual env from python-deps stage
|
|
|
|
COPY --from=python-deps /.venv /.venv
|
|
|
|
ENV PATH="/.venv/bin:$PATH"
|
2023-02-10 12:45:44 +00:00
|
|
|
ENV PATH="$PATH:/usr/local/bin"
|
2022-12-13 12:46:08 +00:00
|
|
|
|
2023-02-10 12:45:44 +00:00
|
|
|
RUN apt-get update && apt-get install libpq5 -y
|
2023-03-06 19:44:45 +00:00
|
|
|
|
2022-12-13 12:46:08 +00:00
|
|
|
# Create and switch to a new user
|
|
|
|
RUN useradd --create-home appuser
|
|
|
|
WORKDIR /home/appuser
|
|
|
|
USER appuser
|
|
|
|
|
2023-03-06 19:44:45 +00:00
|
|
|
RUN [ "python", "-c", "import nltk; nltk.download('punkt', download_dir='/home/appuser/nltk_data'); nltk.download('stopwords', download_dir='/home/appuser/nltk_data')" ]
|
|
|
|
|
2023-02-10 12:45:44 +00:00
|
|
|
ENV PYTHONPATH="/home/appuser/src"
|
|
|
|
|
2022-12-13 12:46:08 +00:00
|
|
|
# Install application into container
|
|
|
|
COPY . .
|
|
|
|
|
2023-03-06 19:44:45 +00:00
|
|
|
USER root
|
|
|
|
|
|
|
|
RUN chmod -R +x scripts
|
|
|
|
|
|
|
|
USER appuser
|
|
|
|
|
2022-12-13 12:46:08 +00:00
|
|
|
# Run the application
|
2023-04-18 15:09:47 +00:00
|
|
|
ENTRYPOINT ["./scripts/run.sh"]
|