node.js – 如何在使用docker时加快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
07002 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 07003 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 07004 (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 07005 for how to plug it all together.

点赞