Dockerfile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # base image
  2. FROM python:3.10-slim-bookworm AS base
  3. WORKDIR /app/api
  4. # Install Poetry
  5. ENV POETRY_VERSION=1.8.4
  6. # if you located in China, you can use aliyun mirror to speed up
  7. # RUN pip install --no-cache-dir poetry==${POETRY_VERSION} -i https://mirrors.aliyun.com/pypi/simple/
  8. RUN pip install --no-cache-dir poetry==${POETRY_VERSION}
  9. # Configure Poetry
  10. ENV POETRY_CACHE_DIR=/tmp/poetry_cache
  11. ENV POETRY_NO_INTERACTION=1
  12. ENV POETRY_VIRTUALENVS_IN_PROJECT=true
  13. ENV POETRY_VIRTUALENVS_CREATE=true
  14. ENV POETRY_REQUESTS_TIMEOUT=15
  15. FROM base AS packages
  16. # if you located in China, you can use aliyun mirror to speed up
  17. # RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
  18. RUN apt-get update \
  19. && apt-get install -y --no-install-recommends gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev
  20. # Install Python dependencies
  21. COPY pyproject.toml poetry.lock ./
  22. RUN poetry install --sync --no-cache --no-root
  23. # production stage
  24. FROM base AS production
  25. ENV FLASK_APP=app.py
  26. ENV EDITION=SELF_HOSTED
  27. ENV DEPLOY_ENV=PRODUCTION
  28. ENV CONSOLE_API_URL=http://127.0.0.1:5001
  29. ENV CONSOLE_WEB_URL=http://127.0.0.1:3000
  30. ENV SERVICE_API_URL=http://127.0.0.1:5001
  31. ENV APP_WEB_URL=http://127.0.0.1:3000
  32. EXPOSE 5001
  33. # set timezone
  34. ENV TZ=UTC
  35. WORKDIR /app/api
  36. RUN apt-get update \
  37. && apt-get install -y --no-install-recommends curl nodejs libgmp-dev libmpfr-dev libmpc-dev \
  38. # if you located in China, you can use aliyun mirror to speed up
  39. # && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list \
  40. && echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
  41. && apt-get update \
  42. # For Security
  43. && 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 \
  44. # install a chinese font to support the use of tools like matplotlib
  45. && apt-get install -y fonts-noto-cjk \
  46. && apt-get autoremove -y \
  47. && rm -rf /var/lib/apt/lists/*
  48. # Copy Python environment and packages
  49. ENV VIRTUAL_ENV=/app/api/.venv
  50. COPY --from=packages ${VIRTUAL_ENV} ${VIRTUAL_ENV}
  51. ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
  52. # Download nltk data
  53. RUN python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger')"
  54. # Copy source code
  55. COPY . /app/api/
  56. # Copy entrypoint
  57. COPY docker/entrypoint.sh /entrypoint.sh
  58. RUN chmod +x /entrypoint.sh
  59. ARG COMMIT_SHA
  60. ENV COMMIT_SHA=${COMMIT_SHA}
  61. ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]