![](/img/trans.png)
[英]Configure container image labels using CNB Paketo Image-Labels-Buildpack and the lifecycle creator
[英]Heroku Buildpacks with the CNB lifecycle creator - how to specifiy custom image labels?
我们在 GitLab CI/CD 管道中使用 Heroku Buildpacks,方法是触发运行 heroku 构建器映像的作业,然后直接调用 /cnbLI/生命周期。 这是因为不能在我们的容器编排器上使用 docker 中的 docker。
这一切都很好,很漂亮,但我们面临的问题是无法指定将添加到生成的图像中的任何自定义标签。 默认情况下,会添加这些标签:
但我们还想添加以下标签:
不幸的是,似乎没有办法指定这一点。 据我所知,创建者没有提供任何配置参数来执行此操作,pack CLI 也没有。 在使用 Paketo buildpacks 时,确实有一个指定的 buildpack 可以解决这个问题: https://github.com/paketo-buildpacks/image-labels
使用 Heroku buildpacks 时有什么方法可以做类似的事情吗?
您可以将Paketo 图像标签构建包与 Heroku 构建包一起使用。 以下是从pack
CLI 执行此操作的示例:
$ pack build --builder heroku/buildpacks:20 --buildpack paketo-buildpacks/image-labels my-app
使用 CLI,您可以根据需要添加更多--buildpack
选项。
如果您想对此进行编码,您可以创建一个project.toml
并使用io.buildpacks.post.group
始终在最后运行 image-labels buildpack。
如果您使用的是creator
二进制文件,您可以为其提供group.toml
https://github.com/buildpacks/spec/blob/main/platform.md#inputs-3
这是有关如何实现此目的的更详细的答案:
下面是一个用于构建自定义构建器映像的示例 Dockerfile:
# paketo
FROM paketobuildpacks/builder:base as paketo
# heroku
FROM heroku/builder-classic:22
USER root
COPY --from=paketo /cnb/buildpacks/paketo-buildpacks_image-labels /cnb/buildpacks/paketo-buildpacks_image-labels
COPY group.toml /opt/group.toml
SHELL ["/bin/bash", "-c"]
USER 1000
这是/opt/group.toml
下的文件的样子:
[[group]]
description = "A Cloud Native Buildpack that enables configuration of labels on the created image"
homepage = "https://github.com/paketo-buildpacks/image-labels"
id = "paketo-buildpacks/image-labels"
keywords = ["image-labels", "labels"]
name = "Paketo Image Labels Buildpack"
version = "4.2.0"
sbom-formats = ["application/vnd.cyclonedx+json", "application/vnd.syft+json"]
api = "0.7"
然后您可以按如下方式运行生命周期:
export CNB_LAYERS_DIR=${BP_LAYERS_PATH}
export CNB_GROUP_PATH=${BP_LAYERS_PATH}/group.toml
/cnb/lifecycle/detector -layers=${BP_LAYERS_PATH} -platform=${BP_PLATFORM_PATH} -app=.
# add additional logic for image-label-buildpack
[ -f /opt/group.toml ] && echo "$(cat /opt/group.toml)" >> ${CNB_GROUP_PATH}
export BP_LAST_VERSION=${BP_IMAGE_VERSION}
/cnb/lifecycle/analyzer -uid=$(id -u) -gid=0 -cache-dir=${BP_CACHE_PATH} -layers=${BP_LAYERS_PATH} -analyzed=${BP_LAYERS_PATH}/analyzed.toml ${BP_REGISTRY}/${BP_IMAGE_NAME}:${BP_LAST_VERSION}
/cnb/lifecycle/restorer -uid=$(id -u) -gid=0 -cache-dir=${BP_CACHE_PATH} -layers=${BP_LAYERS_PATH} -group=${BP_LAYERS_PATH}/group.toml
/cnb/lifecycle/builder -layers=${BP_LAYERS_PATH} -platform=${BP_PLATFORM_PATH} -app=. -group=${BP_LAYERS_PATH}/group.toml
/cnb/lifecycle/exporter -uid=$(id -u) -gid=0 -cache-dir=${BP_CACHE_PATH} -layers=${BP_LAYERS_PATH} -app=. -analyzed=${BP_LAYERS_PATH}/analyzed.toml -run-image=${BP_RUN_IMAGE} ${BP_REGISTRY}/${BP_IMAGE_NAME}:${BP_IMAGE_VERSION}
确保使用平台规范定义的合理值填充 env 变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.