Skip to content

Commit b08bb47

Browse files
FXFX
authored andcommitted
Add GitHub Actions workflow to build and push Docker image
Build multi-arch (amd64/arm64) images to ghcr.io on main, tags, and manual runs.
1 parent 866739e commit b08bb47

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ["v*"]
7+
pull_request:
8+
branches: [main]
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
concurrency:
16+
group: docker-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
name: Build and push
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v3
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Docker meta
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ghcr.io/${{ github.repository }}
38+
tags: |
39+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
40+
type=semver,pattern={{version}}
41+
type=semver,pattern={{major}}.{{minor}}
42+
type=sha,prefix=sha-
43+
type=ref,event=branch
44+
45+
- name: Login to GHCR
46+
if: github.event_name != 'pull_request'
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ghcr.io
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v6
55+
with:
56+
context: .
57+
file: ./Dockerfile
58+
platforms: linux/amd64,linux/arm64
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ docker compose up -d --build
3636
docker compose down
3737
```
3838

39+
## GitHub Actions 镜像
40+
41+
推送到 `main` 或打 `v*` 标签后,会自动构建并推送多架构镜像到 GHCR:
42+
43+
- `ghcr.io/fatelightx/appupdate:latest`(main)
44+
- `ghcr.io/fatelightx/appupdate:sha-<短提交>`
45+
- `ghcr.io/fatelightx/appupdate:1.0.0`(标签 `v1.0.0`
46+
47+
### 使用预构建镜像
48+
49+
```bash
50+
# 私有仓库镜像需先登录(用有 read:packages 的 Token)
51+
echo YOUR_GITHUB_TOKEN | docker login ghcr.io -u FateLightX --password-stdin
52+
53+
docker pull ghcr.io/fatelightx/appupdate:latest
54+
55+
docker run -d --name appupdate \
56+
-p 8000:8000 \
57+
-v "$PWD/data:/data" \
58+
--restart unless-stopped \
59+
ghcr.io/fatelightx/appupdate:latest
60+
```
61+
62+
或在 `docker-compose.yml` 中注释 `build`,启用:
63+
64+
```yaml
65+
image: ghcr.io/fatelightx/appupdate:latest
66+
```
67+
68+
工作流文件:`.github/workflows/docker.yml`
69+
也可在 GitHub → Actions → **Docker Image** → **Run workflow** 手动触发。
70+
71+
若镜像拉不下来:到仓库 **Packages** 将 `appupdate` 包设为 Public,或保持 Private 并用 Token 登录。
72+
73+
3974
## 可选环境变量
4075

4176
| 变量 | 说明 |

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
services:
22
appupdate:
3+
# 本地构建:
34
build: .
5+
# 或使用 GitHub Actions 推送的镜像(二选一,使用镜像时注释掉 build):
6+
# image: ghcr.io/fatelightx/appupdate:latest
47
container_name: appupdate
58
ports:
69
- "8000:8000"

0 commit comments

Comments
 (0)