Dockerfile 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. FROM python:3.10-slim
  2. WORKDIR /app
  3. # https://github.com/aptible/supercronic
  4. ARG TARGETARCH
  5. ENV SUPERCRONIC_VERSION=v0.2.34
  6. # supercronic + locale + 编译依赖
  7. RUN set -ex && \
  8. apt-get update && \
  9. apt-get install -y --no-install-recommends \
  10. curl \
  11. ca-certificates \
  12. locales \
  13. gcc \
  14. python3-dev \
  15. libffi-dev \
  16. build-essential && \
  17. sed -i -e 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen && \
  18. sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
  19. locale-gen && \
  20. # 根据架构选择并下载 supercronic
  21. case ${TARGETARCH} in \
  22. amd64) \
  23. export SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/${SUPERCRONIC_VERSION}/supercronic-linux-amd64; \
  24. export SUPERCRONIC_SHA1SUM=e8631edc1775000d119b70fd40339a7238eece14; \
  25. export SUPERCRONIC=supercronic-linux-amd64; \
  26. ;; \
  27. arm64) \
  28. export SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/${SUPERCRONIC_VERSION}/supercronic-linux-arm64; \
  29. export SUPERCRONIC_SHA1SUM=4ab6343b52bf9da592e8b4bb7ae6eb5a8e21b71e; \
  30. export SUPERCRONIC=supercronic-linux-arm64; \
  31. ;; \
  32. arm) \
  33. export SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/${SUPERCRONIC_VERSION}/supercronic-linux-arm; \
  34. export SUPERCRONIC_SHA1SUM=4ba4cd0da62082056b6def085fa9377d965fbe01; \
  35. export SUPERCRONIC=supercronic-linux-arm; \
  36. ;; \
  37. 386) \
  38. export SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/${SUPERCRONIC_VERSION}/supercronic-linux-386; \
  39. export SUPERCRONIC_SHA1SUM=80b4fff03a8d7bf2f24a1771f37640337855e949; \
  40. export SUPERCRONIC=supercronic-linux-386; \
  41. ;; \
  42. *) \
  43. echo "Unsupported architecture: ${TARGETARCH}"; \
  44. exit 1; \
  45. ;; \
  46. esac && \
  47. echo "Downloading supercronic for ${TARGETARCH} from ${SUPERCRONIC_URL}" && \
  48. for i in 1 2 3 4 5; do \
  49. echo "Download attempt $i/5"; \
  50. if curl --fail --silent --show-error --location --retry 3 --retry-delay 2 --connect-timeout 30 --max-time 120 -o "$SUPERCRONIC" "$SUPERCRONIC_URL"; then \
  51. echo "Download successful"; \
  52. break; \
  53. else \
  54. echo "Download attempt $i failed, exit code: $?"; \
  55. if [ $i -eq 5 ]; then \
  56. echo "All download attempts failed"; \
  57. exit 1; \
  58. fi; \
  59. sleep $((i * 2)); \
  60. fi; \
  61. done && \
  62. echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - && \
  63. chmod +x "$SUPERCRONIC" && \
  64. mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" && \
  65. ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic && \
  66. supercronic -version && \
  67. apt-get remove -y curl gcc python3-dev libffi-dev build-essential && \
  68. apt-get autoremove -y && \
  69. apt-get clean && \
  70. rm -rf /var/lib/apt/lists/*
  71. COPY requirements.txt .
  72. RUN pip install --no-cache-dir -r requirements.txt
  73. COPY main.py .
  74. COPY docker/manage.py .
  75. # 复制 entrypoint.sh 并强制转换为 LF 格式
  76. COPY docker/entrypoint.sh /entrypoint.sh.tmp
  77. RUN sed -i 's/\r$//' /entrypoint.sh.tmp && \
  78. mv /entrypoint.sh.tmp /entrypoint.sh && \
  79. chmod +x /entrypoint.sh && \
  80. chmod +x manage.py && \
  81. mkdir -p /app/config /app/output
  82. ENV PYTHONUNBUFFERED=1 \
  83. CONFIG_PATH=/app/config/config.yaml \
  84. FREQUENCY_WORDS_PATH=/app/config/frequency_words.txt \
  85. LANG=zh_CN.UTF-8 \
  86. LANGUAGE=zh_CN:zh:en_US:en \
  87. LC_ALL=zh_CN.UTF-8 \
  88. PYTHONIOENCODING=utf-8
  89. ENTRYPOINT ["/entrypoint.sh"]