ci(docker): publish ghcr latest and release tags only
This commit is contained in:
57
.github/workflows/docker-ghcr.yml
vendored
Normal file
57
.github/workflows/docker-ghcr.yml
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
name: Docker Publish (GHCR)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: docker-ghcr-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
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: Login 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: ghcr.io/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=ref,event=tag
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
25
README.md
25
README.md
@@ -406,7 +406,7 @@ npm run format
|
|||||||
|
|
||||||
用于将生成的静态站点发布到 服务器 or CI/CD;本地构建见 [快速开始](#快速开始)。
|
用于将生成的静态站点发布到 服务器 or CI/CD;本地构建见 [快速开始](#快速开始)。
|
||||||
|
|
||||||
### 快速部署到GitHub Pages
|
### 快速部署到GitHub Pages(推荐)
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>点击展开</summary>
|
<summary>点击展开</summary>
|
||||||
@@ -453,14 +453,14 @@ npm run format
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Docker 部署(推荐)
|
### Docker 部署(可选)
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>点击展开</summary>
|
<summary>点击展开</summary>
|
||||||
|
|
||||||
MeNav 构建后是纯静态站点(`dist/`),仓库已内置 Docker 部署文件,可直接构建并运行。
|
MeNav 构建后是纯静态站点(`dist/`),仓库已内置 Docker 部署文件,可直接构建并运行。
|
||||||
|
|
||||||
#### 方式一:Docker Compose(推荐)
|
#### 方式一:Docker Compose(常用)
|
||||||
|
|
||||||
1. 准备配置(首次使用):
|
1. 准备配置(首次使用):
|
||||||
- 按 [设置配置文件](#设置配置文件) 完成 `config/user/` 配置
|
- 按 [设置配置文件](#设置配置文件) 完成 `config/user/` 配置
|
||||||
@@ -497,6 +497,25 @@ docker build -t menav \
|
|||||||
docker run -d --name menav -p 8080:80 --restart unless-stopped menav
|
docker run -d --name menav -p 8080:80 --restart unless-stopped menav
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 使用 GHCR 预构建镜像(免本地构建)
|
||||||
|
|
||||||
|
仓库已提供 `Docker Publish (GHCR)` 工作流(`.github/workflows/docker-ghcr.yml`):
|
||||||
|
|
||||||
|
- 推送到 `main` 时自动发布 `latest`
|
||||||
|
- 推送 `v*` 标签时自动发布版本标签(如 `v1.3.0`)
|
||||||
|
- 对外标签策略:仅 `latest` 与版本标签
|
||||||
|
|
||||||
|
首次启用前请在仓库设置确认:
|
||||||
|
|
||||||
|
1. `Settings -> Actions -> General -> Workflow permissions` 设为 `Read and write permissions`
|
||||||
|
2. 在 `Packages` 中将镜像可见性设为 `Public`(否则匿名用户无法拉取)
|
||||||
|
|
||||||
|
发布后,用户可直接拉取并运行(将 `<owner>/<repo>` 替换为你的仓库路径):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d --name menav -p 8080:80 --restart unless-stopped ghcr.io/<owner>/<repo>:latest
|
||||||
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### 部署到服务器
|
### 部署到服务器
|
||||||
|
|||||||
Reference in New Issue
Block a user