I have a CI/CD with multiple projects (some are (really) big (Go)) and want to reduce bandwith consumption / CPU usage on the server and so I need a cache for git objects on my runner.
But because I using gitlab-runner
on kubernetes there is no cache on job side by default.
So, our idea is this:
- regularly create a PV with something like this:
git mirror https://my_project_url.git /cache/<project_id>/
or if the directory exist
git fetch --all
- add the PV (in read-only) mounted in all our gitlab jobs (aka k8s pods) in
/cache/
- And we add an env var on every job that is:
GIT_ALTERNATE_OBJECT_DIRECTORIES="/cache-projects/${CI_PROJECT_ID}/objects
This work great I, but it kind of do not work when using submodules because the submodule is in other folder.
So my idea was to change and do something like this:
git init /cache/full_repo
git remote add <project_id> https://my_project_url.git
git fetch --all
In this configuration all objects of all projects are stored in the same object directory.
And now I would only define GIT_ALTERNATE_OBJECT_DIRECTORIES=/cache/full_repo/objects
So should work for submodule.
But before doing that… is there any drawback to do that ?
How pack of objects are affected ?
BTW: we have also LFS objects and do some git lfs fetch --all
5