Producing up-to-date container images

Even though Docker Hub supports automated builds — triggering builds when you push to a git repository, you still need to actually push to your git repository in order to get the image build. That is pretty tedious, to just update versions and run tests to verify it works. It would be much simpler to let it update itself automatically and just resolve issues.

And that’s actually pretty easy to do. All you need is GitHub repository, Docker Hub repository and one script running as a Cron Job in Travis CI. And that’s it.

So let’s take a closer look how I set this up for Rust.

  1. Travis CI initiates a build every day using its Cron Jobs feature.

  2. This build script is executed. It’s as simple as:

mkdir -p ~/.docker && echo "${DOCKER_AUTH}" >~/.docker/config.json
docker build --tag=$USER/rust .
make test
TESTS_PASSED=$?
if [[ $TESTS_PASSED == 0 ]] ; then
    VERSION=$(docker run $USER/rust rustc --version)
    docker tag $USER/rust tomastomecek/rust:$VERSION
    docker push tomastomecek/rust:$VERSION
fi
  1. So the image gets built, tested, tagged with correct version and then it’s pushed to Docker Hub.

  2. Tests verify that

  • Rust compiler is able to compile Rust code.
  • Cargo is able to create a new project.
  • This cargo project can be built.

And that’s pretty much it. With such a simple pipeline you get Docker images which are:

  • up to date
  • functional
  • correctly tagged

For implementation details, such as Dockerfile, Makefile, .travis.yml, tests or the precise cron job script, please check my TomasTomecek/rust-container GitHub repository.

comments powered by Disqus