Hey,
for some good time, Travis has been allowing anyone to run Docker in their infrastructure - see Using Docker in Builds - be it on a paid or free plan.
Something that is not outlined there is that it’s very common to not have the latest version of Docker running in your builds. For some people, that’s a problem.
Updating the version
To update the version we must, before using Docker in the build, set a script that will fetch Docker from the official apt
repository and perform the upgrade.
This script can either be inlined in the .travis.yaml
definition or be called via an extra file.
Personally, I prefer an extra file.
sudo: 'required'
language: 'generic'
services:
- 'docker'
before_install:
- './.travis/main.sh'
script:
- 'docker version'
notifications:
email: false
And the script looks like this:
#!/bin/bash
# Performs any provisioning needed for a clean build.
#
# This script is meant to be used either directly
# as a `before_install` step such that the next step
# in the Travis build have the environment properly
# setup.
#
# The script is also handy for debugging - SSH into
# the machine and then call `./.travis/main.sh` to
# have all dependencies set.
set -o errexit
main() {
setup_dependencies
echo "INFO:
Done! Finished setting up Travis-CI machine.
"
}
# Takes care of updating any dependencies that the
# machine needs.
setup_dependencies() {
echo "INFO:
Setting up dependencies.
"
sudo apt update -y
sudo apt install --only-upgrade docker-ce -y
docker info
}
main
Let it run and Docker should be updated.
Looking at build system information
we can see which version Travis used as the Docker version by default:
docker version
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:38 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:41:20 2017
OS/Arch: linux/amd64
Experimental: false
Then, verify that our provisioning step got executed:
$ ./.travis/main.sh
INFO:
Setting up dependencies.
Ign:1 http://us-central1.gce.archive.ubuntu.com/ubuntu trusty InRelease
Hit:2 http://us-central1.gce.archive.ubuntu.com/ubuntu trusty-updates InRelease
....
And see that we end up with the desired version:
$ docker version
Client:
Version: 18.02.0-ce
API version: 1.36
Go version: go1.9.3
Git commit: fc4de44
Built: Wed Feb 7 21:16:47 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.02.0-ce
API version: 1.36 (minimum version 1.12)
Go version: go1.9.3
Git commit: fc4de44
Built: Wed Feb 7 21:15:21 2018
OS/Arch: linux/amd64
Experimental: false
That’s it!
Conclusion
In Travis-CI it’s almost guaranteed that you’ll not have, by default, the latest version of Docker. Nevertheless, it’s very easy to update it: just apt update && apt upgrade <docker>
and you’re good to go.
Just in case you need some guidance, here’s an example repository I set up to make this even clearer: cirocosta/sample-travis-docker-update.
If you’re curious about the execution, check it out: https://travis-ci.org/cirocosta/sample-travis-docker-update.
Having any questions, make sure you ping me on Twitter! I’m @cirowrc there.
Have a good one!
finis