我们有自己的 gitlab 存储库。我们有自己的运行者。
如何设置运行者和 gitlab 以便能够缓存 docker 层。
下面是 .gitlab-ci.yml 文件的示例:
before_script:
- docker version
test:
stage: test
script:
- docker-compose -f docker-compose.yml build my_job
- docker-compose -f docker-compose.yml down
- docker-compose -f docker-compose.yml up --remove-orphans --force-recreate --abort-on-container-exit
我一直在尝试阅读如何执行此操作,但所有文档都令人困惑。
https://gitlab.com/gitlab-org/gitlab-ce/issues/17861状态:
Using shell executor
This is the best executor as for now to be used when you wan't to cache docker layers. It basically doesn't require any changes, other then adding gitlab-runner to docker group.
Given the git fetch it gives the best possibility of caching docker layers.
如何设置?我只是在文档中的任何地方都找不到这个。
最佳答案
由于您将构建 docker 镜像作为 CI 作业的一部分,这意味着您很可能已经使用了 shell 执行器。为了支持构建 docker 镜像作为 CI 作业的一部分,只有 3 种方法可以配置您的 gitlab 运行器:https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
本文档还解释了如何配置 shell 执行器以及所有 3 种配置方式之间的权衡。
基本上,唯一不允许缓存 docker 层的运行器配置是使用 docker-in-docker 执行器。
使用 shell 和 docker 套接字绑定(bind)始终在托管 gitlab 运行器的 VM 上本地缓存层,因此无需进一步配置即可启用缓存。
关于git - 如何设置 GitLab+runners 来缓存 Docker 层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49007841/