我们想以最简单的方式使用Paketo.io / CloudNativeBuildpacks (CNB) GitLab CI 。我们的 GitLab 设置使用 AWS EKS 集群,该集群具有利用Kubernetes executor 的非特权 GitLab CI Runners 。我们也不想通过在我们的构建中使用 Docker 来引入安全风险。所以我们没有/var/run/docker.sock
暴露我们的主机也不想使用docker:dind
.
我们找到了一些关于如何将 Paketo 与 GitLab CI 一起使用的指南,例如https://tanzu.vmware.com/developer/guides/gitlab-ci-cd-cnb/。但正如标题下方所述Use Cloud Native Buildpacks with GitLab in GitLab Build Job WITHOUT Using the GitLab Build Template
,该方法依赖于 Docker 和 pack CLI。我们试图在我们.gitlab-ci.yml
的看起来像这样:
image: docker:20.10.9
stages:
- build
before_script:
- |
echo "install pack CLI (see https://buildpacks.io/docs/tools/pack/)"
apk add --no-cache curl
(curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.21.1/pack-v0.21.1-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack)
build-image:
stage: build
script:
- pack --version
- >
pack build $REGISTRY_GROUP_PROJECT/$CI_PROJECT_NAME:latest
--builder paketobuildpacks/builder:base
--path .
但正如概述的那样,我们的设置不支持 docker,我们最终在日志中出现以下错误:
...
$ echo "install pack CLI (see https://buildpacks.io/docs/tools/pack/)" # collapsed multi-line command
install pack CLI (see https://buildpacks.io/docs/tools/pack/)
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/4) Installing brotli-libs (1.0.9-r5)
(2/4) Installing nghttp2-libs (1.43.0-r0)
(3/4) Installing libcurl (7.79.1-r0)
(4/4) Installing curl (7.79.1-r0)
Executing busybox-1.33.1-r3.trigger
OK: 12 MiB in 26 packages
pack
$ pack --version
0.21.1+git-e09e397.build-2823
$ pack build $REGISTRY_GROUP_PROJECT/$CI_PROJECT_NAME:latest --builder paketobuildpacks/builder:base --path .
ERROR: failed to build: failed to fetch builder image 'index.docker.io/paketobuildpacks/builder:base': Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: command terminated with exit code 1
关于如何在 GitLab CI 中使用 Paketo Buildpacks 而不在我们的 GitLab Kubernetes 运行器中存在 Docker 的任何想法(这似乎是一种最佳实践)?我们也不希望我们的设置变得复杂——例如通过添加kpack。