Can't remove cache in travis related to Docker container

I cached a docker img on travis, The docker image is created from a dockerfile. Now my dockerfile changed, and I need to remove caches and rebuild the docker image. How will I remove the caches on travis-ci now it seems impossible to do this, any reason why? any help appreciated

My current .travis.yml looks like this:

language: C
services:
- docker
cache:
  directories:
  - docker_cache
before_script:
- |
  echo 18f.gov...
  filename=docker_cache/saved_images.tar
  if [[ -f "$filename" ]]; then
    echo "Got one from cache."
    docker load < "$filename"
  else
    echo "Got one from scratch";
    docker build -t $IMAGE .
    docker save -o "$filename" $IMAGE 
  fi
script:
- docker run -it ${IMAGE} /bin/bash -c "pwd"
env:
- IMAGE=test04

Hey @SolarUltima ,

There’s only really three methods to do this, and I see you are removing cache that involves 18f.gov, which is a US Government entity that deals with the GSA.

That said, Docker images are one example explicitly called out as a thing we really to not cache. I’ll quote the snippet of what the documentation says below:

Large files that are quick to install but slow to download do not benefit from caching, as they take as long to download from the cache as from the original source.

There are however three ways you can clear cache in Travis, these are the following:

  • Using the UI: “More options” → “Caches” on the repo’s page
  • Using the CLI: travis cache --delete
  • Using the API: DELETE /repos/{repository.id}/caches

With the .travis.yml you provided - it’s not really clear what’s involved in the build pipeline beyond that Dockerfile, and even then it looks like it’s wrong as it should be Dockerfile . in this case. If the file itself hasn’t changed, any of the things that go into it (base image, manifest, digest, source code, etc.) might have. Caching the image means you may get false positives, builds that pass even though docker build would have failed.

So theoretically it could be a lose-lose situation, and you might be better off starting over with the Dockerfile. My advice to you is to make a bash script, and clean this .travis.yml up a bit and you should be on your way. If you have issues creating the bash file, I’ll create one for you.

Happy building.
Montana Mendy

2 Likes
Imprint