惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
N
Netflix TechBlog - Medium
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
IT之家
IT之家
博客园 - Franky
雷峰网
雷峰网
博客园 - 聂微东
腾讯CDC
M
MIT News - Artificial intelligence
B
Blog RSS Feed
博客园_首页
罗磊的独立博客
S
SegmentFault 最新的问题
I
InfoQ
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
D
Docker
宝玉的分享
宝玉的分享
B
Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

Backups done right! on restic

restic · Restic 0.19.1 Released restic · Restic 0.19.0 Released restic · Restic 0.18.1 Released restic · REST-server 0.14.0 released restic · Restic 0.18.0 Released restic · Restic 0.17.3 Released restic · Restic 0.17.2 Released restic · Restic 0.17.1 Released restic · Restic 0.17.0 Released restic · REST-server 0.13.0 released restic · Restic 0.16.5 Released restic · Restic 0.16.4 Released restic · Restic 0.16.3 Released restic · Restic 0.16.2 Released restic · Restic 0.16.1 Released restic · Restic 0.16.0 Released restic · REST-server 0.12.1 released restic · REST-server 0.12.0 released restic · Restic 0.15.2 released restic · Restic 0.15.1 Released restic · Restic 0.15.0 Released restic · Restic 0.14.0 Released restic · Restic 0.13.1 Released restic · Restic 0.13.0 Released restic · Rest Server 0.11.0 released restic · Restic 0.12.1 released restic · Restic 0.12.0 released restic · Restic 0.11.0 released restic · restic 0.10.0 released restic · Rest Server 0.10.0 Released
restic · Enabling the Go Build Cache on Travis/AppVeyor
2018-09-02 · via Backups done right! on restic

02 Sep 2018

The restic project runs the unit and integration tests for each pushed commit and each pull request. We’re using Travis CI for Linux and OS X, and AppVeyor for Windows. We’re very grateful that they provide their services free of charge for Open Source projects!

Our project not only runs the tests on Travis, but also compiles restic for each supported architecture, operating system, and version of Go. Go is known for its fast compilation times, but still, compilation takes its time. Roughly, for each version of Go, running all the tests takes between 13 and 25 minutes:

Build Times on Travis CI Before Caching Build Cache

With the release of Go 1.10, a build cache was introduced, which saves compiled artifacts in a cache directory. On Linux, that’s usually located in ~/.cache/go-build. So when the same package (with the same build tags and architecture and so on) is to be compiled again, the Go compiler can just use the cached version.

Travis executes the tests in a fresh container each time they are run, but we can tell it to keep the build cache directory and extract it before the tests are run next time. The entry in the configuration file .travis.yml looks like this:

cache:
  directories:
    - $HOME/.cache/go-build
    - $HOME/gopath/pkg/mod

This also caches another directory in the GOPATH called pkg/mod, which contains information about released modules. This is a feature introduced with Go 1.11.

The directories listed above work for Linux, but the Go build cache directory is somewhere else on OS X, so we need to add the cache entries to our build matrix:

matrix:
  include:
    - os: linux
      go: "1.9.x"
      cache:
        directories:
          - $HOME/.cache/go-build
          - $HOME/gopath/pkg/mod

    - os: linux
      go: "1.10.x"
      cache:
        directories:
          - $HOME/.cache/go-build
          - $HOME/gopath/pkg/mod

    - os: linux
      go: "1.11.x"
      sudo: true
      cache:
        directories:
          - $HOME/.cache/go-build
          - $HOME/gopath/pkg/mod

    - os: osx
      go: "1.11.x"
      cache:
        directories:
          - $HOME/Library/Caches/go-build
          - $HOME/gopath/pkg/mod

After a successful build, Travis will then archive both directories, and extract them again for the next test run. Indeed, this speeds up running the tests a great deal (depending on how much code has changed):

Build Times on Travis CI With Caching Build Cache

You can see in the screenshot above that the build time for Go 1.9 wasn’t reduced at all since it does not have the build cache feature.

AppVeyor also has a build cache feature, it can be enabled by specifying the list of directories to cache in the appveyor.yml like this:

cache:
  - '%LocalAppData%\go-build'

For restic, the build cache is not so relevant on AppVeyor, since we’re only using it to run our integration tests on Windows and don’t run any cross-compilation.

We hope that the build cache does not become too large, its size is limited for both Travis and AppVeyor. The Go compiler will delete files which haven’t been used recently, so we hope this is enough to keep the cache size small. We’ll keep you posted when we discover any problems with this approach.

Let us know what you think in the comments (which are hosted in our forum)!