Dockerfile 2.9 KB

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