Dockerfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.3
  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 zlib1g=1:1.3.dfsg+really1.3.1-1 expat=2.6.2-1 libldap-2.5-0=2.5.18+dfsg-2 perl=5.38.2-5 libsqlite3-0=3.46.0-1 \
  44. && apt-get autoremove -y \
  45. && rm -rf /var/lib/apt/lists/*
  46. # Copy Python environment and packages
  47. ENV VIRTUAL_ENV=/app/api/.venv
  48. COPY --from=packages ${VIRTUAL_ENV} ${VIRTUAL_ENV}
  49. ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
  50. # Download nltk data
  51. RUN python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger')"
  52. # Copy source code
  53. COPY . /app/api/
  54. # Copy entrypoint
  55. COPY docker/entrypoint.sh /entrypoint.sh
  56. RUN chmod +x /entrypoint.sh
  57. ARG COMMIT_SHA
  58. ENV COMMIT_SHA=${COMMIT_SHA}
  59. ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]