Skip to content

Commit

Permalink
.travis.yml: introduce caching (#329)
Browse files Browse the repository at this point in the history
cloud-images.ubuntu.com can sometimes be under heavy load; caching the
images helps avoid that affecting our build times (or causing build
failures entirely).
  • Loading branch information
OddBloke authored Apr 30, 2020
1 parent 7dceb98 commit 25698b1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
language: python
dist: bionic

# We use two different caching strategies. The default is to cache pip
# packages (as most of our jobs use pip packages), which is configured here.
# For the integration tests, we instead want to cache the lxd images. The
# directory in which the images are stored (/var/snap/lxd/common/lxd/images/)
# is not readable/writeable by the default user (which is a requirement for
# caching), so we instead cache the `lxd_images/` directory. We move lxd
# images out of there before we run tests and back in once tests are complete.
# We _move_ the images out and only copy the most recent lxd image back into
# the cache, to avoid our cache growing without bound. (We only need the most
# recent lxd image because the integration tests only use a single image.)
#
# We cache the lxd images because this saves a few seconds in the general
# case, but provides substantial speed-ups when cloud-images.ubuntu.com, the
# source of the images, is under heavy load.
cache: pip

install:
# Required so `git describe` will definitely find a tag; see
# https://github.com/travis-ci/travis-ci/issues/7422
Expand All @@ -18,6 +34,17 @@ matrix:
TOXENV=py3
PYTEST_ADDOPTS=-v # List all tests run by pytest
- if: NOT branch =~ /^ubuntu\//
cache:
- directories:
- lxd_images
before_cache:
- |
# Find the most recent image file
latest_file="$(sudo ls -Art /var/snap/lxd/common/lxd/images/ | tail -n 1)"
# This might be <hash>.rootfs or <hash>, normalise
latest_file="$(basename $latest_file .rootfs)"
# Find all files with that prefix and copy them to our cache dir
sudo find /var/snap/lxd/common/lxd/images/ -name $latest_file* -print -exec cp {} lxd_images/ \;
install:
- git fetch --unshallow
- sudo apt-get build-dep -y cloud-init
Expand All @@ -33,6 +60,8 @@ matrix:
- sudo snap install lxd
- sudo lxd init --auto
- sudo mkdir --mode=1777 -p /var/snap/lxd/common/consoles
# Move any cached lxd images into lxd's image dir
- sudo find lxd_images/ -type f -print -exec mv {} /var/snap/lxd/common/lxd/images/ \;
- sudo usermod -a -G lxd $USER
- sudo sbuild-adduser $USER
- cp /usr/share/doc/sbuild/examples/example.sbuildrc /home/$USER/.sbuildrc
Expand Down

0 comments on commit 25698b1

Please sign in to comment.