docker 不使用缓存
At Unleashed Technologies we use Gitlab CI with Docker runners for our continuous integration testing. We’ve put significant effort into speeding up the build execution speeds. One of the optimizations we made was to share a cache volume across all the CI jobs, allowing them to share files like package download caches.
在Unleashed Technologies,我们将Gitlab CI与Docker运行程序一起使用来进行持续集成测试。 我们已经付出了巨大的努力来加快构建执行速度。 我们进行的一项优化是在所有CI作业之间共享缓存卷,从而使它们可以共享文件包下载缓存等文件。
Configuring the Docker runner was really simple — we simply dropped volumes = ["/srv/cache:/cache:rw"]
into our config.toml
file:
配置Docker运行程序非常简单-我们只需将volumes = ["/srv/cache:/cache:rw"]
放入我们的config.toml
文件中:
concurrent = 6
check_interval = 0
[[runners]]
name = "ut-ci01"
url = "https://gitlab.example.com/"
token = "xxxxxxxxxxxxx"
executor = "docker"
[runners.docker]
tls_verify = false
image = "unleashed/php:7.1"
privileged = false
disable_cache = false
volumes = ["/srv/cache:/cache:rw"]
[runners.cache]
As a result, all CI jobs will have a /cache
directory available (which is mapped to /srv/cache
on the Docker host).
结果,所有CI作业都将有一个/cache
目录可用(已映射到Docker主机上的/srv/cache
)。
The next step was making the package managers utilize this cache directory whenever jobs run commands like composer install
or yarn install
. Luckily, these package managers allow us to configure their cache directories using environment variables:
下一步是使每当作业运行诸如composer install
或yarn install
类的命令时,程序包管理器就使用此缓存目录。 幸运的是,这些软件包管理器使我们可以使用环境变量来配置其缓存目录:
Composer:
COMPOSER_CACHE_DIR
作曲者:
COMPOSER_CACHE_DIR
Yarn:
YARN_CACHE_FOLDER
纱线:
YARN_CACHE_FOLDER
npm:
NPM_CONFIG_CACHE
npm:
NPM_CONFIG_CACHE
bower:
bower_storage__packages
bower:
bower_storage__packages
RubyGems:
GEM_SPEC_CACHE
RubyGems:
GEM_SPEC_CACHE
pip:
PIP_DOWNLOAD_CACHE
点:
PIP_DOWNLOAD_CACHE
So we simply added these ENV
directives in the Dockerfile
s for our base images:
因此,我们只是在Dockerfile
为基本映像添加了这些ENV
指令:
ENV COMPOSER_CACHE_DIR /cache/composer
ENV YARN_CACHE_FOLDER /cache/yarn
ENV NPM_CONFIG_CACHE /cache/npm
ENV bower_storage__packages /cache/bower
ENV GEM_SPEC_CACHE /cache/gem
ENV PIP_DOWNLOAD_CACHE /cache/pip
Now, whenever a job needs a package installed, it’ll pull from our local cache instead of downloading from a remote server! This provides a noticeable speed improvement for our builds.
现在,每当作业需要安装软件包时,它将从我们的本地缓存中提取,而不是从远程服务器下载! 这为我们的构建提供了明显的速度改进。
This quick tip was originally published on Colin’s blog, and republished here with the author’s permission.
该快速提示最初发布在Colin的博客上 ,并在获得作者许可的情况下在此处重新发布。
翻译自: https://www.sitepoint.com/optimizing-docker-based-ci-runners-shared-package-caches/
docker 不使用缓存