docs(content): add Mac alternatives, K8s transition guide, CI/CD registry push example

- Add OrbStack/Colima comparison table to Mac install chapter (3.7.4)
- Add Docker→K8s concept mapping paragraph to Ch13 intro
- Add KubeKey/RKE2 deployment tool notes to Ch14
- Add production image checklist to Dockerfile chapter summary
- Add build-and-push-to-registry workflow example to GitHub Actions section
- Expand Ch18 security summary with dimension table
This commit is contained in:
yeasy
2026-05-21 21:33:58 -07:00
parent dae0af9ae7
commit 8b9e4518c8
6 changed files with 100 additions and 3 deletions
+49 -1
View File
@@ -34,11 +34,59 @@ jobs:
```
该示例会在 GitHub Actions 中构建当前仓库的 Docker 镜像不推送到 registry
### 21.2.2 最佳实践
### 21.2.2 构建并推送到 Registry
实际项目中通常需要在 CI 中构建镜像并推送到容器 Registry以下示例展示了多阶段构建 + 登录 + 推送的完整流程
```yaml
name: Build and Push
on:
push:
branches: [main]
permissions:
contents: read
packages: write
jobs:
build-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@v4
- uses: docker/build-push-action@v7
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.sha }}
ghcr.io/${{ github.repository }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
```
关键说明
* `docker/login-action` 负责认证支持 Docker HubGHCRECR 等主流 Registry
* `cache-from` / `cache-to` 使用 GitHub Actions 原生缓存`type=gha`无需额外配置即可加速增量构建
* 标签同时使用 commit hash `latest`兼顾版本追溯与部署便利
### 21.2.3 最佳实践
* 固定 action 的主版本例如 `@v4` / `@v6`避免使用 `@master` 这类浮动引用
* 设置最小权限例如 `contents: read`需要写入权限时再打开
* 需要依赖缓存时优先使用官方支持的缓存方案例如针对语言包管理器的 cache BuildKit cache
* 敏感凭据Registry 密码Deploy Key 一律通过 `secrets` 注入禁止硬编码
* 多平台构建可在 `build-push-action` 中添加 `platforms: linux/amd64,linux/arm64`
如果你需要在某个步骤里直接运行容器镜像而不是构建镜像可以使用 `docker://` 语法