diff --git a/Dockerfile b/Dockerfile index 7930a3e..054f037 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM python:3.12-slim +FROM ghcr.io/astral-sh/uv:latest AS uv -ENV PYTHONDONTWRITEBYTECODE=1 \ - PYTHONUNBUFFERED=1 \ +FROM python:3.12-slim-bookworm + +COPY --from=uv /uv /bin/uv + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ UV_SYSTEM_PYTHON=1 \ UV_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple" \ - TZ=Asia/Shanghai - -WORKDIR /app - -COPY requirements-docker.txt /app/requirements-docker.txt + TZ=Asia/Shanghai \ + PYTHONPATH="/app:${PYTHONPATH}" RUN echo "# 清华大学 Debian 镜像源配置\n\ # 主软件源\n\ @@ -23,12 +24,26 @@ deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bookworm-security deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware\n\ deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" > /etc/apt/sources.list -RUN pip install --no-cache-dir --upgrade pip \ - && pip install --no-cache-dir -r /app/requirements-docker.txt +RUN apt-get update && apt-get install -y --no-install-recommends \ + supervisor \ + tzdata \ + && ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY pyproject.toml /app/pyproject.toml + +RUN uv pip install -r /app/pyproject.toml COPY . /app -RUN chmod +x /app/docker-entrypoint.sh +RUN chmod +x /app/docker-entrypoint.sh \ + && mkdir -p /app/logs \ + && mkdir -p /var/log/supervisor + +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf ENTRYPOINT ["/app/docker-entrypoint.sh"] -CMD ["python", "prefect_gmv_scheduler.py", "--serve"] +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/prefect.yaml b/prefect.yaml index fefc022..ac1f5a7 100644 --- a/prefect.yaml +++ b/prefect.yaml @@ -22,11 +22,11 @@ deployments: - bitable - sync schedules: - - cron: "0 17 * * *" + - cron: "0 17 10 * *" timezone: "Asia/Shanghai" active: true work_pool: - name: default-agent-pool + name: gmv-analytics-pool - name: gmv-daily-notify-9am version: "1.0.0" @@ -43,8 +43,8 @@ deployments: - feishu - notify schedules: - - cron: "0 17 40 * *" + - cron: "0 17 50 * *" timezone: "Asia/Shanghai" active: true work_pool: - name: default-agent-pool + name: gmv-analytics-pool diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fc87d38 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +[project] +name = "prefect-etl-worker" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.12" +dependencies = [ + "httpx>=0.25.0", + "openpyxl>=3.1.2", + "pandas", + "prefect==3.6.8", + "psycopg2-binary>=2.9.9", + "python-dotenv>=1.2.1", + "python-socks>=2.7.3", + "requests>=2.31.0", + "pendulum>=3.1.0", + "psycopg-pool>=3.3.0", + "psycopg>=3.3.1", + "psycopg-binary>=3.3.1" +] + +[dependency-groups] +dev = [ + "pytest>=9.0.2", +] diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..04108e1 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:gmv-analytics-worker] +command=prefect worker start --pool "gmv-analytics-pool" --type process +directory=/app +autostart=true +autorestart=true +stderr_logfile=/app/logs/prefect_worker.err.log +stdout_logfile=/app/logs/prefect_worker.out.log