GCS Cacher
GCS Cacher is a small CLI and Docker container that saves and restores caches on
Google Cloud Storage. It is intended to be used in CI/CD systems like
Cloud Build, but may have applications elsewhere.
Usage
-
Create a cache:
gcs-cacher -bucket "my-bucket" -cache "go-mod" -dir "$GOPATH/pkg/mod"
This will compress and upload the contents at pkg/mod
to Google Cloud
Storage at the key "go-mod".
-
Restore a cache:
gcs-cacher -bucket "my-bucket" -restore "go-mod" -dir "$GOPATH/pkg/mod"
This will download the Google Cloud Storage object named "go-mod" and
decompress it to pkg/mod
.
Installation
Choose from one of the following:
-
Download the latest version from the releases.
-
Use a pre-built Docker container:
us-docker.pkg.dev/vargolabs/gcs-cacher/gcs-cacher
docker.pkg.github.com/sethvargo/gcs-cacher/gcs-cacher
Implementation
When saving the cache, the provided directory is made into a tarball, then
gzipped, then uploaded to Google Cloud Storage. When restoring the cache, the
reverse happens.
It's strongly recommend that you use a cache key based on your dependency file,
and restore up the chain. For example:
gcs-cacher \
-bucket "my-bucket" \
-cache "ruby-$(gcs-cacher -hash Gemfile.lock)"
gcs-cacher \
-bucket "my-bucket" \
-restore "ruby-$(gcs-cacher -hash Gemfile.lock)"
-restore "ruby-"
This will maximize cache hits.