增加 GitHub Docker 镜像发布流程
通过 GitHub Actions 构建并发布 linux/amd64 镜像到 GHCR,补充镜像标签策略和服务器拉取部署说明。
This commit is contained in:
1 parent
6a9a684e5e
commit
a5a8aa9b8b
3 files changed
+77
-3
No files matched your search
+1
-1
@@ -10,7 +10,7 @@ POSTGRES_PASSWORD=请替换为高强度数据库密码
|
||||
DATABASE_URL=postgres://xianyu:请替换为URL编码后的数据库密码@postgres:5432/xianyu?sslmode=disable
|
||||
|
||||
# 应用
|
||||
XIANYU_IMAGE=xianyu-go:debian13-amd64
|
||||
XIANYU_IMAGE=ghcr.io/christ9038/xinayu-go:dev
|
||||
XIANYU_DATA_KEY=请替换为稳定且足够长的随机密钥
|
||||
XIANYU_BIND_ADDRESS=0.0.0.0
|
||||
XIANYU_HTTP_PORT=8080
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
name: 构建并发布 Docker 镜像
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
- main
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
concurrency:
|
||||
group: docker-publish-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: 发布 linux/amd64 镜像
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 配置 Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: 登录 GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: 生成小写镜像名称
|
||||
id: image
|
||||
shell: bash
|
||||
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: 生成镜像标签
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ steps.image.outputs.name }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=sha,format=long
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||
|
||||
- name: 构建并推送镜像
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.debian13
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
provenance: mode=max
|
||||
sbom: true
|
||||
@@ -165,10 +165,17 @@ Debian 13 应用镜像和 PostgreSQL 17。Compose 明确锁定 `linux/amd64`,
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# 编辑 .env,至少替换 PostgreSQL 密码、DATABASE_URL 和 XIANYU_DATA_KEY
|
||||
docker compose -f docker-compose.debian13-postgres17.yml build app
|
||||
docker compose -f docker-compose.debian13-postgres17.yml up -d postgres app
|
||||
docker login ghcr.io -u Christ9038
|
||||
docker compose -f docker-compose.debian13-postgres17.yml pull app postgres
|
||||
docker compose -f docker-compose.debian13-postgres17.yml up -d --no-build postgres app
|
||||
```
|
||||
|
||||
`dev` 分支会由 GitHub Actions 自动发布
|
||||
`ghcr.io/christ9038/xinayu-go:dev`;`main` 分支同时发布 `main` 和 `latest` 标签,
|
||||
版本标签(例如 `v1.2.3`)会发布对应语义化版本标签。仓库和镜像为私有时,服务器
|
||||
登录 GHCR 所用的 Personal Access Token 需要 `read:packages` 权限。本地修改镜像后
|
||||
也可以运行 `docker compose -f docker-compose.debian13-postgres17.yml build app` 自行构建。
|
||||
|
||||
数据库只在 Compose 内部网络开放,不映射宿主机端口;应用端口由
|
||||
`XIANYU_BIND_ADDRESS` 和 `XIANYU_HTTP_PORT` 控制。PostgreSQL 数据、应用数据和
|
||||
Chromium 持久化配置分别保存在命名卷 `postgres_data`、`app_data` 和
|
||||
|
||||
Reference in new issue
Block a user