Repository navigation
114 lines (95 loc) · 3.1 KB
/
Copy pathdocker-ghcr.yml
File metadata and controls
114 lines (95 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Publish Docker image
on:
push:
branches:
- main
tags:
- "v*"
paths-ignore:
- "README*.md"
- "docs/**"
workflow_dispatch:
# 默认只授予源码读取权限,只有实际发布镜像的 job 才临时获得 packages: write。
permissions:
contents: read
concurrency:
group: docker-ghcr-${{ github.ref }}
cancel-in-progress: true
env:
# GHCR 镜像路径必须使用小写名称,不能直接使用包含 AudioNotes 大写字母的 github.repository。
IMAGE_NAME: ghcr.io/harry0703/audio-notes
jobs:
validate:
name: Validate source
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements-dev.txt
- name: Install validation tools
run: python -m pip install --disable-pip-version-check -r requirements-dev.txt
- name: Run static checks
run: ruff check .
- name: Run unit tests
run: python -m unittest discover -s tests -v
- name: Check Python syntax
run: python -m compileall -q main.py app tests
- name: Validate container configuration
run: |
docker compose config --quiet
# 发布前同时验证可选 NVIDIA 配置能与默认编排正确合并。
docker compose -f docker-compose.yml -f docker-compose.gpu.yml config --quiet
docker build --check .
publish:
name: Build and publish
needs: validate
runs-on: ubuntu-latest
timeout-minutes: 90
# GHCR 支持使用仓库自带的 GITHUB_TOKEN 发布关联软件包,无需维护 DockerHub 密钥。
permissions:
contents: read
packages: write
steps:
- name: Check out repository
uses: actions/checkout@v6
- 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=sha,prefix=sha-,format=long
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
build-args: |
PYTORCH_INDEX_URL=https://download.pytorch.org/whl/cpu
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max