Tobias Henkel e0e3f3b81c
Optimize repos for size when preparing for nodecache
We currently run 'git gc' on repos before creating the tarball for the
node cache. On busy repos this is not enough to cut down the size of
the repo. With more aggressive pruning and packing one of our repos in
the cache got down from 6GB to 1.8GB.

Change-Id: I7ef428c25fde713efabd966d59b5bd97ec248d7e
2020-03-02 09:54:56 +01:00

43 lines
1.3 KiB
YAML

- name: Create git parent dirs
file:
path: "{{ git_cache_root }}/{{ item.canonical_name | dirname }}"
state: directory
with_items: "{{ zuul.projects.values() | list }}"
- name: Copy git repos to {{ git_cache_root }}
command: cp -r "{{ ansible_user_dir }}/{{ item.src_dir }}/.git"
"{{ git_cache_root }}/{{ item.canonical_name }}"
with_items: "{{ zuul.projects.values() | list }}"
- name: Mark repos as bare
command: git config --bool core.bare true
args:
chdir: "{{ git_cache_root }}/{{ item.canonical_name }}"
with_items: "{{ zuul.projects.values() | list }}"
# We don't want git module foo, just set a config value.
tags:
- skip_ansible_lint
- name: Run git garbage collection
command: git gc --prune=now --aggressive
args:
chdir: "{{ git_cache_root }}/{{ item.canonical_name }}"
with_items: "{{ zuul.projects.values() | list }}"
# The ansible git module doesn't support garbage collection.
tags:
- skip_ansible_lint
- name: Set git_cache_file variable
set_fact:
git_cache_file: "{{ git_cache_root }}/repos.tar.gz"
- name: Create repos tarball
shell: |
tar -czf "{{ git_cache_file }}" *
args:
chdir: "{{ git_cache_root }}"
# Ansible lint wants we should use the unarchive module but we want the other
# way round.
tags:
- skip_ansible_lint