node.js - 使用 docker 时如何加快 CI 构建时间?

标签 node.js jenkins docker continuous-integration travis-ci

我目前使用 docker + travis CI 来测试/部署我的应用程序。这在本地非常有效,因为我有 node_modules 等数据量,并且 docker 的层提供缓存加速构建。

但是,当我将代码推送到 travis 时,它必须从头开始重建和安装所有内容,这需要很长时间! Travis 不支持缓存 docker 层 atm。有没有其他方法可以加快我的构建速度,或者是否有其他类似的工具允许 docker 层缓存?

最佳答案

您可能想调查如何 i3wm已经解决了类似的问题。

主要开发人员在 design behind his Travis CI workflow 上写过.引用相关部分:

The basic idea is to build a Docker container based on Debian testing and then run all build/test commands inside that container. Our Dockerfile installs compilers, formatters and other development tools first, then installs all build dependencies for i3 based on the debian/control file, so that we don’t need to duplicate build dependencies for Travis and for Debian.

This solves the immediate issue nicely, but comes at a significant cost: building a Docker container adds quite a bit of wall clock time to a Travis run, and we want to give our contributors quick feedback. The solution to long build times is caching: we can simply upload the Docker container to the Docker Hub and make subsequent builds use the cached version.

We decided to cache the container for a month, or until inputs to the build environment (currently the Dockerfile and debian/control) change. Technically, this is implemented by a little shell script called ha.sh (get it? hash!) which prints the SHA-256 hash of the input files. This hash, appended to the current month, is what we use as tag for the Docker container, e.g. 2016-03-3d453fe1.

See our .travis.yml for how to plug it all together.

关于node.js - 使用 docker 时如何加快 CI 构建时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37335910/

相关文章:

node.js - NodeJs 的 Pubsubhubbub 库

node.js - Node.js 流与异步

networking - 如何在两个不同主机上运行的两个Docker容器之间进行通信?

mysql - 使用 Marathon 在 Mesos 上部署 Mysql

docker - 如何为同一项目中的不同构建指定不同的 .dockerignore 文件?

javascript - Node 流结尾 : Write after end

node.js - Mongoose - 使用 findoneandupdate 和 $push 添加或更新子文档(当 upsert 为 true 时)

jenkins - 与 Jenkins 一起部署Symfony项目:最佳实践

git - Tomcat Jenkins Git repo 错误

xcode - Jenkins 配置文件问题