2024-01-25 12:44:15 +08:00
|
|
|
# base image
|
2024-11-06 15:10:47 +08:00
|
|
|
FROM python:3.12-slim-bookworm AS base
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
WORKDIR /app/api
|
|
|
|
|
|
|
|
# Install Poetry
|
|
|
|
ENV POETRY_VERSION=1.8.3
|
2024-08-26 14:45:28 +08:00
|
|
|
|
|
|
|
# if you located in China, you can use aliyun mirror to speed up
|
|
|
|
# RUN pip install --no-cache-dir poetry==${POETRY_VERSION} -i https://mirrors.aliyun.com/pypi/simple/
|
|
|
|
|
2024-07-06 14:17:34 +08:00
|
|
|
RUN pip install --no-cache-dir poetry==${POETRY_VERSION}
|
2024-06-22 01:34:08 +08:00
|
|
|
|
|
|
|
# Configure Poetry
|
|
|
|
ENV POETRY_CACHE_DIR=/tmp/poetry_cache
|
|
|
|
ENV POETRY_NO_INTERACTION=1
|
|
|
|
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
|
|
|
|
ENV POETRY_VIRTUALENVS_CREATE=true
|
2024-08-08 14:17:29 +08:00
|
|
|
ENV POETRY_REQUESTS_TIMEOUT=15
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-06-24 00:45:33 +08:00
|
|
|
FROM base AS packages
|
2024-01-25 12:44:15 +08:00
|
|
|
|
2024-08-26 14:45:28 +08:00
|
|
|
# if you located in China, you can use aliyun mirror to speed up
|
|
|
|
# RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
|
|
|
|
|
2023-09-10 12:20:58 +08:00
|
|
|
RUN apt-get update \
|
2024-01-26 03:09:24 +08:00
|
|
|
&& apt-get install -y --no-install-recommends gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev
|
2023-09-01 11:13:22 +08:00
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
# Install Python dependencies
|
|
|
|
COPY pyproject.toml poetry.lock ./
|
|
|
|
RUN poetry install --sync --no-cache --no-root
|
2023-09-01 11:13:22 +08:00
|
|
|
|
2024-01-25 12:44:15 +08:00
|
|
|
# production stage
|
|
|
|
FROM base AS production
|
2024-01-19 20:30:36 +08:00
|
|
|
|
2024-06-24 00:45:33 +08:00
|
|
|
ENV FLASK_APP=app.py
|
|
|
|
ENV EDITION=SELF_HOSTED
|
|
|
|
ENV DEPLOY_ENV=PRODUCTION
|
|
|
|
ENV CONSOLE_API_URL=http://127.0.0.1:5001
|
|
|
|
ENV CONSOLE_WEB_URL=http://127.0.0.1:3000
|
|
|
|
ENV SERVICE_API_URL=http://127.0.0.1:5001
|
|
|
|
ENV APP_WEB_URL=http://127.0.0.1:3000
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
EXPOSE 5001
|
|
|
|
|
2024-01-19 20:30:36 +08:00
|
|
|
# set timezone
|
2024-06-24 00:45:33 +08:00
|
|
|
ENV TZ=UTC
|
2024-01-19 20:30:36 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
WORKDIR /app/api
|
|
|
|
|
2023-09-10 12:16:21 +08:00
|
|
|
RUN apt-get update \
|
2024-08-05 20:21:08 +08:00
|
|
|
&& apt-get install -y --no-install-recommends curl nodejs libgmp-dev libmpfr-dev libmpc-dev \
|
2024-08-26 14:45:28 +08:00
|
|
|
# if you located in China, you can use aliyun mirror to speed up
|
|
|
|
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list \
|
2024-08-05 20:21:08 +08:00
|
|
|
&& echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
|
|
|
|
&& apt-get update \
|
|
|
|
# For Security
|
2024-11-04 17:48:10 +08:00
|
|
|
&& apt-get install -y --no-install-recommends expat=2.6.3-2 libldap-2.5-0=2.5.18+dfsg-3+b1 perl=5.40.0-6 libsqlite3-0=3.46.1-1 zlib1g=1:1.3.dfsg+really1.3.1-1+b1 \
|
2024-10-24 18:49:49 +08:00
|
|
|
# install a chinese font to support the use of tools like matplotlib
|
|
|
|
&& apt-get install -y fonts-noto-cjk \
|
2024-08-05 20:21:08 +08:00
|
|
|
&& apt-get autoremove -y \
|
2023-09-01 11:13:22 +08:00
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
# Copy Python environment and packages
|
|
|
|
ENV VIRTUAL_ENV=/app/api/.venv
|
|
|
|
COPY --from=packages ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
|
|
|
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
|
|
|
|
|
2024-08-08 14:23:22 +08:00
|
|
|
# Download nltk data
|
2024-08-26 15:14:05 +08:00
|
|
|
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger')"
|
2024-08-08 14:23:22 +08:00
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
# Copy source code
|
2023-05-15 08:51:32 +08:00
|
|
|
COPY . /app/api/
|
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
# Copy entrypoint
|
2023-05-15 08:51:32 +08:00
|
|
|
COPY docker/entrypoint.sh /entrypoint.sh
|
|
|
|
RUN chmod +x /entrypoint.sh
|
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
ARG COMMIT_SHA
|
2024-06-24 00:45:33 +08:00
|
|
|
ENV COMMIT_SHA=${COMMIT_SHA}
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-06-22 01:34:08 +08:00
|
|
|
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
|