32个版本 (5个破坏性更新)
新 0.8.13 | 2024年8月20日 |
---|---|
0.8.11 | 2024年6月3日 |
0.8.3 | 2024年3月27日 |
0.3.8 | 2023年12月30日 |
#100 在 构建工具 中
每月254次下载
280KB
6.5K SLoC
BlueBuild
BlueBuild的命令行程序,根据您的recipe.yml构建Containerfile和自定义镜像。
要求
bluebuild
工具利用了最新的构建功能。具体来说,在 RUN
指令上使用了绑定、缓存和tmpfs挂载。我们支持以下工具及其版本:
- Docker - v23及以上
- Podman - v4及以上
- Buildah - v1.24及以上
安装
Cargo
这是安装的最佳方式,因为它为您提供了为特定环境构建的机会。
cargo install --locked blue-build
Podman/Docker
这将将在您的系统中的 /usr/local/bin
上安装二进制文件。这是一个仅适用于 linux-gnu
的版本。
podman run --pull always --rm ghcr.io/blue-build/cli:latest-installer | bash
docker run --pull always --rm ghcr.io/blue-build/cli:latest-installer | bash
GitHub安装脚本
bash <(curl -s https://raw.githubusercontent.com/blue-build/cli/main/install.sh)
Distrobox
我们打包了包含运行 bluebuild
所需所有工具的 fedora-toolbox
和 alpine
镜像。您可以使用 distrobox
运行应用程序,而无需在您的机器上安装它。
# fedora-toolbox
distrobox create blue-build --image ghcr.io/blue-build/cli
# alpine
distrobox create blue-build --image ghcr.io/blue-build/cli:latest-alpine
默认情况下,bluebuild命令在distrobox外部不可见。您需要 进入 distrobox,然后从distrobox内部运行命令,或者 导出 distrobox命令以在distrobox外部使用。
有关更多信息,请参阅 distrobox文档。
在distrobox内部运行命令
[user@host]$ bluebuild help
ERROR
[user@host]$ distrobox enter blue-build
[user@blue-build]$ bluebuild help
A CLI tool built for creating Containerfile templates based on the Ublue Community Project
...
导出命令以在distrobox外部运行
[user@blue-build]$ distrobox-export --bin $(which bluebuild)
[user@blue-build]$ exit
[user@host]$ bluebuild help
A CLI tool built for creating Containerfile templates based on the Ublue Community Project
...
Nix Flake
您可以通过Flakehub上的Nix flake安装此CLI,请访问Flakehub
非NixOS
您可以在非NixOS系统上通过运行以下命令将BlueBuild安装到全局包环境中:
# you can replace "*" with a specific tag
nix profile install https://flakehub.com/f/bluebuild/cli/*.tar.gz#bluebuild
NixOS
如果您正在使用专用的flake来管理依赖项,您可以通过fh CLI(可以通过nixpkgs安装)将BlueBuild添加为flake输入,并将bluebuild
添加到其中。
{pkgs,inputs,...}: {
...
environment.SystemPackages = [
inputs.bluebuild.packages.${pkgs.system}.bluebuild # change bluebuild with the fh added input name
];
...
}
如果您没有使用专门的Nix flake,您可以将BlueBuild flake作为变量添加到您的/etc/nixos/*.nix
配置中,尽管这需要您使用带有--impure
变量的nixos-rebuild
运行,但这样做并不建议。
{pkgs,...}:
let
bluebuild = builtins.fetchTarball "https://flakehub.com/f/bluebuild/cli/*.tar.gz";
in {
...
environment.SystemPackages = [
bluebuild.packages.${pkgs.system}.bluebuild
];
...
}
您还可以在这个repo目录中使用nix develop .#
来运行一个带有开发依赖项和构建BlueBuild的一些有用工具的nix shell!
如何使用
生成Containerfile
一旦安装了CLI工具,您就可以运行以下命令来拉取您的配方文件以生成Containerfile
。
bluebuild generate -o <CONTAINERFILE> <RECIPE_FILE>
然后您可以使用podman
或buildah
构建并发布您的镜像。更多选项可以通过运行bluebuild template --help
查看。
构建
如果您不关心模板的细节,可以运行build
命令。
bluebuild build ./recipes/recipe.yaml
这将使用buildah
或podman
来构建文件。
补全
bluebuild completions
命令生成shell补全,打印到标准输出。这些补全可以存储以供在您的shell环境中集成。例如,在一个安装了bash-completion的系统上
# user completions
$ bluebuild completions bash > ~/.local/share/bash-completion/completions/bluebuild
# system-wide completions
$ bluebuild completions bash | sudo tee /usr/share/bash-completion/completions/bluebuild
随后的bluebuild
调用将响应<Tab>
自动补全
$ bluebuild # press <Tab>
-v -V --help template bug-report
-q --verbose --version upgrade completions
-h --quiet build rebase help
目前,bluebuild补全适用于bash
、zsh
、fish
、powershell
和elvish
shell环境。
本地构建
重基
如果您想测试您的更改,可以使用rebase
命令。这将创建一个作为.tar.gz
文件的镜像,将其存储在/etc/bluebuild
中,并在新构建的文件上运行rpm-ostree rebase
。
sudo bluebuild rebase recipes/recipe.yml
您可以通过添加--reboot/-r
选项来启动即时重启。
升级
当您基于本地镜像存档重基后,可以通过运行以下命令来更新您的配方镜像:
sudo bluebuild upgrade recipes/recipe.yml
您也可以将--reboot
参数与该命令一起使用。
切换
注意:这是一个不稳定的特性,并且只能在从
main
镜像安装或编译时使用switch
功能标志的情况下使用。
使用switch命令,您可以使用oci-archive
tarball本地构建和启动镜像。switch命令可以以普通用户身份运行,并且只有在将存档移动到/etc/bluebuild
时才会请求sudo
权限。
bluebuild switch recipes/recipe.yml
您可以通过添加--reboot/-r
选项来启动即时重启。
CI构建
GitHub
您可以通过以下.github/workflows/build.yaml
使用我们的GitHub Action。
name: bluebuild
on:
schedule:
- cron: "00 17 * * *" # build at 17:00 UTC every day
# (20 minutes after last ublue images start building)
push:
paths-ignore: # don't rebuild if only documentation has changed
- "**.md"
pull_request:
workflow_dispatch: # allow manually triggering builds
jobs:
bluebuild:
name: Build Custom Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false # stop GH from cancelling all matrix builds if one fails
matrix:
recipe:
# !! Add your recipes here
- recipe.yml
steps:
# the build is fully handled by the reusable github action
- name: Build Custom Image
uses: blue-build/[email protected]
with:
recipe: ${{ matrix.recipe }}
cosign_private_key: ${{ secrets.SIGNING_SECRET }}
registry_token: ${{ github.token }}
pr_event_number: ${{ github.event.number }}
Gitlab
我们还支持GitLab CI!有趣的是,这个项目最初是为了在GitLab中构建这些镜像而开始的。您将想要利用GitLab的安全文件功能来使用您的cosign私钥进行签名。以下是一个示例:.gitlab-ci.yml
workflow:
rules:
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: "$CI_COMMIT_TAG"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS"
when: never
- if: "$CI_COMMIT_BRANCH"
stages:
- build
build-image:
stage: build
image:
name: ghcr.io/blue-build/cli:main
entrypoint: [""]
services:
- docker:dind
parallel:
matrix:
- RECIPE:
# Add your recipe files here
- recipe.yml
variables:
# Setup a secure connection with docker-in-docker service
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: /certs
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: $DOCKER_TLS_CERTDIR/client
before_script:
# Pulls secure files into the build
- curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | bash
- export COSIGN_PRIVATE_KEY=$(cat .secure_files/cosign.key)
script:
- sleep 5 # Wait a bit for the docker-in-docker service to start
- bluebuild build --push ./recipes/$RECIPE
未来功能
- 并行构建阶段(用于编译镜像中的程序很有用)
- 自动下载和管理镜像密钥,以便无缝进行签名的镜像变基
- 模块命令,用于轻松管理第三方插件
- 创建一个初始化命令,以创建一个用于开始的项目仓库
- 设置项目,以便可以使用
cargo-binstall
进行安装
依赖项
~57–79MB
~1.5M SLoC