Files
BiliNote/.github/workflows/docker-build.yml
huangjianwu f6a3438079 feat(build): 全面优化打包流程,Docker 镜像自动发布到 GHCR
Docker 优化:
- Dockerfile 层缓存(requirements/lockfile 先复制再安装)
- ARG 可配置镜像源,国际用户可覆盖为默认源
- 前端 Dockerfile 改用 corepack + frozen-lockfile
- 精简 .dockerignore,排除 .git 和 Tauri 构建产物

CI/CD 优化:
- docker-build 自动推送到 GHCR,支持 amd64/arm64 双架构
- 桌面端 CI 增加 pip/pnpm/cargo 缓存,升级 actions 版本
- Python 版本对齐为 3.11,增加 Linux 构建矩阵
- build.sh 加 -y 覆盖标志

文档更新:
- README Docker 部署简化为 docker pull + docker run

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 17:48:34 +08:00

74 lines
2.1 KiB
YAML

name: Build and Publish Docker Image
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.complete
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Generate Usage Instructions
run: |
echo "=========================================="
echo "Docker Image Published!"
echo "=========================================="
echo ""
echo "Pull the image:"
echo " docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
echo ""
echo "Run the container:"
echo " docker run -d -p 80:80 \\"
echo " -v bilinote-data:/app/backend/data \\"
echo " --name bilinote \\"
echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
echo ""
echo "Access the application at: http://localhost"
echo "=========================================="