anthony-spruyt/container-images

GitHub: anthony-spruyt/container-images

一个基于 GitHub Actions 的容器镜像构建框架,提供自动化安全扫描、SLSA 来源证明和自定义 MegaLinter flavor 生成能力。

Stars: 1 | Forks: 0

# 容器镜像 [![License](https://img.shields.io/github/license/anthony-spruyt/container-images)](https://github.com/anthony-spruyt/container-images/blob/main/LICENSE) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/14e67a6bff114200.svg)](https://github.com/anthony-spruyt/container-images/actions/workflows/ci.yaml) [![Trivy Scan](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/e9381415dc114202.svg)](https://github.com/anthony-spruyt/container-images/actions/workflows/trivy-scan.yaml) [![Stars](https://img.shields.io/github/stars/anthony-spruyt/container-images)](https://github.com/anthony-spruyt/container-images/stargazers) [![Forks](https://img.shields.io/github/forks/anthony-spruyt/container-images)](https://github.com/anthony-spruyt/container-images/forks) [![Contributors](https://img.shields.io/github/contributors/anthony-spruyt/container-images)](https://github.com/anthony-spruyt/container-images/graphs/contributors) [![Issues](https://img.shields.io/github/issues/anthony-spruyt/container-images)](https://github.com/anthony-spruyt/container-images/issues) 基于上游源或自定义 Dockerfiles 构建的容器镜像,发布到 GitHub Container Registry,并附带自动安全扫描和 SLSA 来源证明。 ## 开发 关于开发环境的设置,请参阅 [DEVELOPMENT.md](DEVELOPMENT.md)。 ## 用法 拉取镜像: ``` docker pull ghcr.io/anthony-spruyt/firemerge:latest ``` ## 添加新镜像 ### 选项 1:从上游源构建 当从外部仓库(例如 GitHub 项目)构建时使用此方法: 1. 创建一个以镜像名称命名的目录 2. 添加 `metadata.yaml`: upstream: owner/repo version: "1.0.0" 3. 可选择添加自定义 `Dockerfile` 以覆盖上游的配置 4. 推送到 main 分支 - 镜像将自动构建并发布 ### 选项 2:从本地 Dockerfile 构建 适用于没有上游源的自定义镜像: 1. 创建一个以镜像名称命名的目录 2. 添加你的 `Dockerfile` 和任何所需文件 3. 添加 `metadata.yaml`: version: "1.0.0" 4. 推送到 main 分支 - 镜像将自动构建并发布 ### 自动配置 - **上游验证** - 使用每个镜像自己的 `metadata.yaml` 作为事实来源 - **Renovate 跟踪** - 在 `metadata.yaml` 中添加 `# renovate:` 注解以实现自动版本更新 ## 添加自定义 MegaLinter Flavor 自定义 MegaLinter flavor 是在官方 flavor 基础上扩展了额外 linter 的版本。`megalinter-factory/` 目录包含了通过简单配置生成 flavor 文件的工具。 ### 使用 Claude Code(推荐) `/create-megalinter-flavor` 命令可以自动化 flavor 的创建,并自动选择基础 flavor: ``` # 使用特定 linter /create-megalinter-flavor my-ci ACTION_ACTIONLINT,MARKDOWN_MARKDOWNLINT,BASH_SHELLCHECK # 交互模式(提示选择 linter) /create-megalinter-flavor my-ci ``` 该命令将: 1. 验证 flavor 名称并检查是否存在冲突 2. 从目录中查找 linter 配置 3. 自动选择最优的基础 flavor(最小化自定义安装) 4. 生成带有 Renovate 注解的 `megalinter-/flavor.yaml` ### 手动设置 1. 为你的 flavor 创建目录: mkdir megalinter-/ 2. 使用你的配置创建 `flavor.yaml`: name: my-flavor description: "MegaLinter for my use case" # renovate: datasource=docker depName=oxsecurity/megalinter-ci_light upstream_image: "oxsecurity/megalinter-ci_light:v9.3.0@sha256:..." custom_linters: - ACTION_ACTIONLINT - MARKDOWN_MARKDOWNLINT - PYTHON_BANDIT 3. 提交 `flavor.yaml` - CI 会生成 Dockerfile、test.sh 和 metadata.yaml,然后自动构建 ### 可用的 Linter Linter 信息是在构建时直接从 MegaLinter 的描述符中提取的。生成器会自动从 获取最新版本。 ### 版本更新 Linter 版本是在构建时从 MegaLinter 自动提取的 - 无需手动跟踪。每周的定时重建工作流会获取任何新的 linter 版本。 对于基础镜像,Renovate 会跟踪上游 MegaLinter 的版本: ``` # renovate: datasource=docker depName=oxsecurity/megalinter-ci_light upstream_image: "oxsecurity/megalinter-ci_light:v9.3.0@sha256:..." ``` 当 Renovate 创建 PR 更新 `flavor.yaml` 时,CI 会重新生成 Dockerfile 并进行构建。 ### 本地开发 要在本地测试,首先生成文件: ``` pip install pyyaml jinja2 python megalinter-factory/generate.py megalinter-/ ``` 生成的文件(`Dockerfile`、`test.sh`)会在构建时由 CI 重新生成。 ## 构建触发器 ### 自动触发 当 `metadata.yaml`、`Dockerfile` 或 `flavor.yaml` 在 main 分支上发生更改时,会使用 metadata 中的版本触发构建。 ### 手动 / n8n 集成 通过 GitHub API (workflow_dispatch) 触发: ``` # Dry run(默认)- 构建并扫描,但不 push 或 release curl -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Accept: application/vnd.github.v3+json" \ https://api.github.com/repos/anthony-spruyt/container-images/actions/workflows/ci.yaml/dispatches \ -d '{"ref":"main","inputs":{"image":"firemerge","version":"0.5.3"}}' # 生产构建 - push 到 GHCR 并创建 release curl -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Accept: application/vnd.github.v3+json" \ https://api.github.com/repos/anthony-spruyt/container-images/actions/workflows/ci.yaml/dispatches \ -d '{"ref":"main","inputs":{"image":"firemerge","version":"0.5.3","dry_run":"false"}}' ``` 参数: - **image**(必填):镜像目录名称(例如 `firemerge`、`chrony`) - **version**(可选):要构建的 Semver 标签(例如 `0.5.3`)- 会从上游检出此标签 - **dry_run**(可选,默认:`true`):当为 `true` 时,构建并扫描镜像,但跳过推送到 GHCR 和创建发布。对于生产构建,请设置为 `false`。 ## 自动版本更新 ### Renovate(推荐) 在 `metadata.yaml` 中添加 Renovate 注解以进行自动版本跟踪: ``` upstream: owner/repo # renovate: datasource=github-tags depName=owner/repo version: "1.0.0" ``` 支持的数据源: - `github-tags` - GitHub 仓库标签 - `github-releases` - GitHub 发布 - `docker` - Docker Hub 或容器镜像仓库 当 Renovate 检测到新版本时,它会创建一个 PR。合并后会自动触发构建。 ### n8n 工作流(特殊情况) 对于 Renovate 无法监控的上游源(例如 Alpine 软件包),请使用 n8n 工作流。有关监视 Alpine 软件包版本并通过 workflow_dispatch 触发构建的示例,请参见 `chrony/n8n-release-watcher.json`。 ## 安全 有关安全策略和控制,请参阅 [SECURITY.md](SECURITY.md)。 创建仓库后,应用 GitHub rulesets: ``` ./.github/apply-rulesets.sh ```
标签:DevSecOps, Docker, Dockerfile, GHCR, GitHub Actions, GitHub Container Registry, SLSA, 上游代理, 制品管理, 安全扫描, 安全防御评估, 容器镜像, 开源, 时序注入, 网络调试, 自动化, 自动笔记, 请求拦截, 逆向工具, 镜像构建