This commit is contained in:
cheney 2025-07-21 22:37:18 +08:00
parent 6ff6c0e8b0
commit 59815d685f
4 changed files with 50 additions and 3 deletions

View File

@ -0,0 +1,20 @@
name: Build and Push Docker Image
on:
push:
branches:
- main # 只在 main 分支推送时触发
tags:
- v* # 推送 v* 标签时也触发(如 v1.0.0
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .

View File

@ -1,4 +1,28 @@
FROM ubuntu:latest # 使用 Python 3.13 的基础镜像注意3.13可能尚未正式发布,这里使用可能的最新开发版本)
LABEL authors="Cheney" FROM python:3.13-rc-slim
ENTRYPOINT ["top", "-b"] # 安装必要的软件包
RUN apt-get update && \
apt-get install -y --no-install-recommends cron && \
rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /app
# 复制Python脚本和其他必要文件
COPY *.py /app/
COPY cronjob /etc/cron.d/cronjob
# 设置cron作业文件权限
RUN chmod 0644 /etc/cron.d/cronjob && \
crontab /etc/cron.d/cronjob
# 安装Python依赖如果有
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
# 创建日志文件用于cron输出
RUN touch /var/log/cron.log
# 保持容器运行的命令
CMD tail -f /var/log/cron.log

2
cronjob Normal file
View File

@ -0,0 +1,2 @@
# 设置每天 14:45 执行
45 14 * * * root /usr/local/bin/python /app/main.py >> /var/log/cron.log 2>&1

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
akshare