Making your build faster with go 1.10 on CircleCI 2.0

Did you update to go 1.10? DId you update to CircleCI 2.0 ?
A month ago, go 1.10 released. It includes awesome feature, build cache.

On the other hand, CircleCI 1.0 EOL announced on August 31, 2018.

You should migrate 1.0 to 2.0.
On my production code, build time faster 4x by updating go 1.10 and CircleCI 2.0.

TL; DR:

  • use CircleCI build cache
  • use dep
  • use test cache

use CircleCI build cache

In CircleCI 2.0, you can save and restore cache any path in your repositories at your any timing.

use dep

dep is dependency management tool for Go. Currently dep may defact standard. dep download dependency libraries to vendor directory. So, with CircleCI build cache you can skip download step efficiently.

here is example circle.yml:

download-libraries phase only executed first push per branch, or Gopkg.lock changed.

use test cache

To enable go 1.10 test cache needs just technique. CircleCI build cache write only once.

The cache for a specific key is immutable and cannot be changed once written. NOTE: If the cache for the given key already exists it won’t be modified, and job execution will proceed to the next step.

On restore cache, use CIRCLE_PREVIOUS_BUILD_NUM environment variable. it restore previous build cache. And save_cache phase, you use CIRCLE_BUILD_NUM environment variable.

Conclusion

On CircleCI 1.0 and go 1.9

8min10sec

On CircleCI 2.0 and go 1.10 (no test cache)

2min2sec

On CircleCI 2.0 and go 1.10 (with test cache via rebuild)

1min14sec

Thanks, reading!

`https://gist.github.com/azihsoyn/7f307e39e4a493c24235367e711e3725`