Dockerfile 2.4 KB

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