docker 不使用缓存_如何使用共享程序包缓存优化基于Docker的CI运行器

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 installyarn 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 Dockerfiles 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 不使用缓存

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值