Dockerfile 3.5 KB

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