drone-docker: Docs don't mention caching at all
They used to - noticed some commits and previous issues - but the current docs page doesn’t mention them at all: http://plugins.drone.io/drone-plugins/drone-docker/
What is the recommended way to handle this? Even if the docs just covered the basic case of “I don’t want to re-download my FROM image every single time”, that would be a great step forward.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 18
- Comments: 21 (2 by maintainers)
I would like to share with my steps which allowed me to use the docker image caching in Drone CI without the need of using trusted nor privileged git repository options.
To enable docker image caching all you need is:
DRONE_VOLUME=/tmp/drone-cache:/cachedrone-server variable;storage_path: /drone/dockeranduse_cache: trueparameters forplugins/dockerjob;drillster/drone-volume-cacheof course 😉docker-compose.yml
.drone.yml
After this is set, Drone will keep the docker image cache under:
/tmp/drone-cache/<username>/<gitrepo>/1/drone/docker/When the
restore_cachejob is running, you can spot it is running rsync from/cache/<username>/<gitrepo>/1//drone/docker/to/drone/dockerinside the drone pipeline. And the/cacheis mounted fromhost:/tmp/drone-cacheacross the whole pipeline asDRONE_VOLUMEdrone-server variable was leveraged.Snap:
References
Missing documentation
storage_pathvariable documented for some reason. Edit PR to update itDRONE_VOLUMEis not reflected in the documentation for some reason… I have found information about it only here and in the code Edit PR to update the docFYI: @bradrydzewski
For security reasons. If we used the host machine cache, someone could send a malicious pull request that overwrites commonly used images (e.g. golang, or node) and replace with malicious versions of images. These could be used to capture secrets, source code and more.
Also to prevent race condition where two builds are running at the same time on the same machine, and both trying to create an image with the same tag name (e.g.
:latest), which would be problematic.Mounting the layer cache into the plugin is not recommended I think.
Instead, you can use cache-from that is portable even to drone cloud.
More on this here: https://laszlo.cloud/how-using-cache-from-can-speed-up-your-docker-builds-in-droneci
I would argue that the absolute worst feature of the official (or whatever you’d like to call them) drone plugins is that the don’t warn when being supplied with invalid argument names. This issue comes up so often…
Preferably all plugins should also have a PLUGIN_PLUGIN_DEBUG option to turn on verbose logging because that’s the second thing that I find usually goes wrong, plugins can have fairly complicated inner workings and just a simple error message might not always be enough when figuring out whats going wrong.
I don’t think that I can count the times that I personally have had to add logging to a plugin to understand why it fails to do what it’s supposed to on two hands.
While these two issues range for mildly to very annoying for me personally I would just have to guess how annoying it is for people who don’t know how to modify the plugins to inspect what it is doing and it’s probably a lot more problematic and frustrating experience than for me…
Just confirming that
cache_fromis already a list [1] [1] https://github.com/drone-plugins/drone-docker/blob/master/docker.go#L50I believe that docker build support multiple
--cache_fromentries so that option should maybe be turned into a list if it already isn’t. The big issue for me is though that all layers in a typical larger docker build are in intermediate steps and we cannot push those easily to a repository now given howdrone-dockerworks.In the example below the most important steps to be able to cache are the
npm ciandpip wheelbut they are not really made available withdrone-dockerright now.I want the Dockerfile to be self contained so I don’t want separate drone steps to do stuff required to build the full image because I want it to build anywhere only using
docker build. I do the drone stuff with volume mounted caces for npm/pip/… as well for the linting steps of the build but for image publishing I want it to build from one easy to understand source.