Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

Add GHCR Docker image publishing

harry0703fa1788454ed4
diff --git a/.dockerignore b/.dockerignore
index df67e1a2..b376cdbb 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,5 +1,6 @@
# Exclude common Python files and directories
venv/
+.venv/
__pycache__/
*.pyc
*.pyo
@@ -14,6 +15,11 @@ __pycache__/
.env.*
*.log
*.db
+.DS_Store
+.pytest_cache/
+.ruff_cache/
+.idea/
+logs/
# Exclude version control system files
.git/
diff --git a/.github/workflows/docker-ghcr.yml b/.github/workflows/docker-ghcr.yml
new file mode 100644
index 00000000..2882d8a5
--- /dev/null
+++ b/.github/workflows/docker-ghcr.yml
@@ -0,0 +1,69 @@
+name: Publish Docker image
+
+on:
+ push:
+ branches:
+ - main
+ tags:
+ - "v*"
+ workflow_dispatch:
+
+permissions:
+ contents: read
+ packages: write
+
+concurrency:
+ group: docker-ghcr-${{ github.ref }}
+ cancel-in-progress: true
+
+env:
+ IMAGE_NAME: ghcr.io/harry0703/moneyprinterturbo
+
+jobs:
+ publish:
+ name: Build and publish
+ runs-on: ubuntu-latest
+ timeout-minutes: 90
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v4
+
+ - name: Set up QEMU
+ uses: docker/setup-qemu-action@v3
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+
+ - name: Log in to GHCR
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Extract Docker metadata
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.IMAGE_NAME }}
+ tags: |
+ type=ref,event=branch
+ type=ref,event=tag
+ type=semver,pattern={{version}}
+ type=raw,value=latest,enable={{is_default_branch}}
+
+ - name: Build and push Docker image
+ uses: docker/build-push-action@v6
+ with:
+ context: .
+ file: ./Dockerfile
+ push: true
+ platforms: linux/amd64,linux/arm64
+ build-args: |
+ DOCKER_BUILD_MIRROR=default
+ PIP_USE_OFFICIAL=1
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
diff --git a/Dockerfile b/Dockerfile
index 7188db60..ebbf9719 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,18 +9,27 @@ RUN chmod 777 /MoneyPrinterTurbo
ENV PYTHONPATH="/MoneyPrinterTurbo"
-# Install system dependencies with domestic mirrors first for stability
-RUN echo "deb http://mirrors.aliyun.com/debian bullseye main" > /etc/apt/sources.list && \
- echo "deb http://mirrors.aliyun.com/debian-security bullseye-security main" >> /etc/apt/sources.list && \
+# 本地用户默认继续优先使用国内镜像;GitHub Actions 发布 GHCR 镜像时使用 default,
+# 避免海外 runner 访问国内镜像过慢导致镜像发布长时间卡住。
+ARG DOCKER_BUILD_MIRROR=china
+ARG PIP_USE_OFFICIAL=0
+
+# Install system dependencies with retry logic
+RUN if [ "$DOCKER_BUILD_MIRROR" = "china" ]; then \
+ echo "deb http://mirrors.aliyun.com/debian bullseye main" > /etc/apt/sources.list && \
+ echo "deb http://mirrors.aliyun.com/debian-security bullseye-security main" >> /etc/apt/sources.list; \
+ else \
+ echo "Using default Debian mirrors"; \
+ fi && \
( \
for i in 1 2 3; do \
- echo "Attempt $i: Using Aliyun mirror"; \
+ echo "Attempt $i: installing system dependencies"; \
apt-get update && apt-get install -y --no-install-recommends \
git \
imagemagick \
ffmpeg && break || \
echo "Attempt $i failed, retrying..."; \
- if [ $i -eq 3 ]; then \
+ if [ "$DOCKER_BUILD_MIRROR" = "china" ] && [ $i -eq 3 ]; then \
echo "Aliyun mirror failed, switching to Tsinghua mirror"; \
sed -i 's/mirrors.aliyun.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
sed -i 's/mirrors.aliyun.com\/debian-security/mirrors.tuna.tsinghua.edu.cn\/debian-security/g' /etc/apt/sources.list && \
@@ -50,10 +59,14 @@ RUN sed -i '/<policy domain="path" rights="none" pattern="@\*"/d' /etc/ImageMagi
# Copy only the requirements.txt first to leverage Docker cache
COPY requirements.txt ./
-# Install Python dependencies with domestic mirrors first and retry logic
-RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --retries 3 --timeout 60 -r requirements.txt || \
- pip install --no-cache-dir -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/ --trusted-host mirrors.tuna.tsinghua.edu.cn --retries 3 --timeout 60 -r requirements.txt || \
- pip install --no-cache-dir --retries 3 --timeout 60 -r requirements.txt
+# 本地默认优先国内 PyPI 镜像;GHCR 发布使用官方 PyPI,避免海外 runner 因跨境镜像访问变慢。
+RUN if [ "$PIP_USE_OFFICIAL" = "1" ]; then \
+ pip install --no-cache-dir --retries 3 --timeout 60 -r requirements.txt; \
+ else \
+ pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --retries 3 --timeout 60 -r requirements.txt || \
+ pip install --no-cache-dir -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/ --trusted-host mirrors.tuna.tsinghua.edu.cn --retries 3 --timeout 60 -r requirements.txt || \
+ pip install --no-cache-dir --retries 3 --timeout 60 -r requirements.txt; \
+ fi
# Now copy the rest of the codebase into the image
COPY . .
diff --git a/README-en.md b/README-en.md
index 6a65f547..3c25cd0b 100644
--- a/README-en.md
+++ b/README-en.md
@@ -194,10 +194,12 @@ If you are using a Windows system, please refer to Microsoft's documentation:
```shell
cd MoneyPrinterTurbo
-docker-compose up
+docker compose -f docker-compose.release.yml up
```
-> Note:The latest version of docker will automatically install docker compose in the form of a plug-in, and the start command is adjusted to `docker compose up `
+> The recommended default is `docker-compose.release.yml`, which pulls the prebuilt image from GitHub Container Registry: `ghcr.io/harry0703/moneyprinterturbo:latest`.
+> If you need to build the image locally, you can still run `docker compose up`.
+> Before the first start, make sure `config.toml` exists in the project root. You can copy it from `config.example.toml`.
#### ② Access the Web Interface
diff --git a/README.md b/README.md
index 0680c44d..fa75d42d 100644
--- a/README.md
+++ b/README.md
@@ -193,10 +193,12 @@ git clone https://github.com/harry0703/MoneyPrinterTurbo.git
```shell
cd MoneyPrinterTurbo
-docker-compose up
+docker compose -f docker-compose.release.yml up
```
-> 注意:最新版的docker安装时会自动以插件的形式安装docker compose,启动命令调整为docker compose up
+> 默认推荐使用 `docker-compose.release.yml`,它会直接拉取 GitHub Container Registry 上的预构建镜像:`ghcr.io/harry0703/moneyprinterturbo:latest`。
+> 如果你需要本地重新构建镜像,可以继续使用 `docker compose up`。
+> 注意:首次启动前请确保项目根目录下存在 `config.toml`,可以从 `config.example.toml` 复制一份。
#### ② 访问Web界面
diff --git a/docker-compose.release.yml b/docker-compose.release.yml
new file mode 100644
index 00000000..ffcc48a7
--- /dev/null
+++ b/docker-compose.release.yml
@@ -0,0 +1,21 @@
+x-common-volumes: &common-volumes
+ - ./config.toml:/MoneyPrinterTurbo/config.toml
+ - ./storage:/MoneyPrinterTurbo/storage
+
+services:
+ webui:
+ image: ghcr.io/harry0703/moneyprinterturbo:latest
+ container_name: "moneyprinterturbo-webui"
+ ports:
+ - "127.0.0.1:8501:8501"
+ command: [ "streamlit", "run", "./webui/Main.py", "--server.address=0.0.0.0", "--server.port=8501", "--browser.serverAddress=127.0.0.1", "--server.enableCORS=True", "--browser.gatherUsageStats=False", "--server.showEmailPrompt=False" ]
+ volumes: *common-volumes
+ restart: always
+ api:
+ image: ghcr.io/harry0703/moneyprinterturbo:latest
+ container_name: "moneyprinterturbo-api"
+ ports:
+ - "127.0.0.1:8080:8080"
+ command: [ "python3", "main.py" ]
+ volumes: *common-volumes
+ restart: always