Docker-in-Docker 构建信息

gtp*_*dqc 5 git continuous-integration docker

当使用docker:24.0.0-dindwith docker:24.0.0-cli, todocker build而不先安装 Git 时,我们会收到警告:

警告:buildx:系统中未找到 git。构建未捕获当前提交信息

如果在运行之前安装了 Git,会捕获哪些信息docker build

# Git is not installed at this point
# "WARNING: buildx: git was not found in the system. Current commit information was not captured by the build"
docker build -t "$REGISTRY/without-git" .

apk add git
# Git installed. No more buildx warning.
docker build -t "$REGISTRY/with-git" .

docker push "$REGISTRY/without-git"
docker push "$REGISTRY/with-git"

# stdout: null
docker buildx imagetools inspect "$REGISTRY/without-git" --format "{{ json .Provenance.SLSA }}"

# stdout: null
docker buildx imagetools inspect "$REGISTRY/with-git" --format "{{ json .Provenance.SLSA }}"

# Explicit attestation, also stdout: null
docker buildx build -t "$CI_REGISTRY_IMAGE/with-git-attested" --attest type=provenance,mode=max .
docker push "$REGISTRY/with-git-attested"
docker buildx imagetools inspect "$REGISTRY/with-git-attested" --format "{{ json .Provenance.SLSA }}"
Run Code Online (Sandbox Code Playgroud)

Mit*_*tar 3

Docker 23 默认使用 buildx,并且自动捕获来源,例如捕获 git VCS 信息。这只是一个警告而不是错误,因此构建仍然成功完成,只是缺少 git 出处信息。