GitLab Docker Runner 重用已安装的软件层
GitLab Docker Runner to reuse installed software layers
GitLab CI 的一个非常典型的场景是安装您的工作所需的一些包(linters、代码覆盖工具、特定于部署的助手等),然后 运行您实际 stages/steps 构建、测试和部署您的软件。
Docker运行ner 是一个非常干净利落的解决方案,但总是运行安装基本软件的步骤似乎很浪费。通常,Docker 能够缓存这些层,但是 GitLab Docker 运行ner 的工作方式不会发生这种情况。
我们是否意识到设置另一个项目来生成预配置的 Docker 图像是一种解决方案,但还有更好的解决方案吗?基本上,我们想说的是:“如果 before
部分没有改变,你可以重复使用上次的图像,不需要重新安装 wget
或其他 ".
有这样的解决方案吗?
你可以使用你的gitlab项目的registry。
例如
images:
stage: build
image: docker
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY # login
# pull the current image or in case the image does not exit, do not stop the script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
# build with the pulled image as cache:
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest -t "$CI_REGISTRY_IMAGE:latest" .
# push the final image:
- docker push "$CI_REGISTRY_IMAGE:latest"
这样 docker 构建将从作业的最后一个 运行 完成的工作中获益。见 docs. Maybe you want to avoid unnecessary runs by some rules.
GitLab CI 的一个非常典型的场景是安装您的工作所需的一些包(linters、代码覆盖工具、特定于部署的助手等),然后 运行您实际 stages/steps 构建、测试和部署您的软件。
Docker运行ner 是一个非常干净利落的解决方案,但总是运行安装基本软件的步骤似乎很浪费。通常,Docker 能够缓存这些层,但是 GitLab Docker 运行ner 的工作方式不会发生这种情况。
我们是否意识到设置另一个项目来生成预配置的 Docker 图像是一种解决方案,但还有更好的解决方案吗?基本上,我们想说的是:“如果 before
部分没有改变,你可以重复使用上次的图像,不需要重新安装 wget
或其他 ".
有这样的解决方案吗?
你可以使用你的gitlab项目的registry。
例如
images:
stage: build
image: docker
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY # login
# pull the current image or in case the image does not exit, do not stop the script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
# build with the pulled image as cache:
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest -t "$CI_REGISTRY_IMAGE:latest" .
# push the final image:
- docker push "$CI_REGISTRY_IMAGE:latest"
这样 docker 构建将从作业的最后一个 运行 完成的工作中获益。见 docs. Maybe you want to avoid unnecessary runs by some rules.