Dockerfile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. FROM python:3.12-slim-bookworm
  2. WORKDIR /app
  3. # Latest releases available at https://github.com/aptible/supercronic/releases
  4. ARG TARGETARCH
  5. ENV SUPERCRONIC_VERSION=v0.2.39
  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=c98bbf82c5f648aaac8708c182cc83046fe48423; \
  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=5ef4ccc3d43f12d0f6c3763758bc37cc4e5af76e; \
  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. # 重试机制:最多3次,每次超时30秒
  27. for i in 1 2 3; do \
  28. echo "Download attempt $i/3"; \
  29. if curl -fsSL --connect-timeout 30 --max-time 60 -o "$SUPERCRONIC" "$SUPERCRONIC_URL"; then \
  30. echo "Download successful"; \
  31. break; \
  32. else \
  33. echo "Download attempt $i failed"; \
  34. if [ $i -eq 3 ]; then \
  35. echo "All download attempts failed"; \
  36. exit 1; \
  37. fi; \
  38. sleep 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. supercronic -version && \
  46. apt-get remove -y curl && \
  47. apt-get clean && \
  48. rm -rf /var/lib/apt/lists/*
  49. COPY requirements.txt .
  50. RUN pip install --no-cache-dir -r requirements.txt
  51. COPY docker/manage.py .
  52. COPY trendradar/ ./trendradar/
  53. # 复制 entrypoint.sh 并强制转换为 LF 格式
  54. COPY docker/entrypoint.sh /entrypoint.sh.tmp
  55. RUN sed -i 's/\r$//' /entrypoint.sh.tmp && \
  56. mv /entrypoint.sh.tmp /entrypoint.sh && \
  57. chmod +x /entrypoint.sh && \
  58. chmod +x manage.py && \
  59. mkdir -p /app/config /app/output
  60. ENV PYTHONUNBUFFERED=1 \
  61. CONFIG_PATH=/app/config/config.yaml \
  62. FREQUENCY_WORDS_PATH=/app/config/frequency_words.txt
  63. ENTRYPOINT ["/entrypoint.sh"]