Drone provided the standard cache function until v0.4.
Cache function is to use build artifacts which saved in the end of previous build.
It reduce the build time to preserve node_modules for nodejs, bundler gems for ruby.From dron v0.5 disastablished standard cache function, instead provides plugin. Plugin function produces some problems. This article introduces alternative cache function.
Volume Cache Plugin
When you expected to the same behaviour as always, volume-cache plugin is available.
This plugin is able to save the build artifacts on the arbitrary path which is running agent.
Enabling cache is to put the step of cache restore and rebuild between build as follows.
Because this flag is able to set by administrator only, management will be heavy task. Also trusted flag open docker socket to plugins, so the user can mount on any paths on the agent host.
It is the best choice in small scale usage.
S3 Cache Plugin
s3-cache plugin which uses AWS S3 as cache storage is also available.
When your drone is hosted on AWS, this plugin is convenient choice, If not, you can choice S3 compatible storages. Minio is the best for you own hosted drone.
Minio is able to launch on docker immediately, works fine with drone.
In docker-compose, the settings are as follows.
Minio uses 9000 port as default, however the drone v0.8 uses 9000 port for gRPC to communicate with agent.
To resolve port conflict, launch on other node, or listen port 80.
Minio is simple storage for single user. Because of this, the access and secret key is need to share with all users. But this is not going to matter as much for cache storage.
Setting example is as follows, but the url option uses on document for S3 endpoint setting, “endpoint” is required instead of url option.
Default cache path is ///. Basically it generate the cache on each branch, it reduce effectiveness of cache when in workflow creating branch on every feature requests like a Github Flow. If you specify the path option with a fixed value as below, the cache can be used the same artifact every time.
Organization name less then 3 characters
If your drone connected to github and organization name is less than 3 characters, rebuild-cache will fail because the bucket name violates the validation rule of 3 or more characters. (It will deadlock and die on the rebuild step)
In this case, using path option to avoid this problem.
flush is the function to erase old cache.
Since minio can be seen regular files from the host side, if tmpwatch target include the minio mount path, the user do not have to explicitly write flush_cache.
The cache function has been deleted standard features in v0.5 but now users can freely delete rotten caches by the plugin. Try more drone.