From f96d1709326b6b5eebc1033d5e7ce70a0c77c110 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Fri, 9 Nov 2018 15:09:26 +0100 Subject: [PATCH] Add role git-prepare-nodecache The git-prepare-nodecache is a companion role that can be used to create a git cache suitable to be used by the prepare-workspace-git role. Change-Id: I623eb8abc64d956069b4f18d7a1d61383a705ac9 --- roles/git-prepare-nodecache/README.rst | 15 +++++++ .../git-prepare-nodecache/defaults/main.yaml | 1 + roles/git-prepare-nodecache/tasks/main.yaml | 42 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 roles/git-prepare-nodecache/README.rst create mode 100644 roles/git-prepare-nodecache/defaults/main.yaml create mode 100644 roles/git-prepare-nodecache/tasks/main.yaml diff --git a/roles/git-prepare-nodecache/README.rst b/roles/git-prepare-nodecache/README.rst new file mode 100644 index 000000000..28d69e34e --- /dev/null +++ b/roles/git-prepare-nodecache/README.rst @@ -0,0 +1,15 @@ +Prepare an archive containing all repositories that are part of the job. This +can be used to prepare the repos archive suitable for caching in the node +image to be used by `prepare-workspace-git`. + +The path to the resulting archive file will be stored in the `git_cache_file` +variable. That variable can be used to push the archive to a place where +it will be picked up to be baked into the node image. + +**Role variables** + +.. zuul:rolevar:: git_cache_root + :default: {{ansible_user_dir }}/git-cache" + + Directory where the git cache should be prepared. Usually this should not + be changed. diff --git a/roles/git-prepare-nodecache/defaults/main.yaml b/roles/git-prepare-nodecache/defaults/main.yaml new file mode 100644 index 000000000..96072c918 --- /dev/null +++ b/roles/git-prepare-nodecache/defaults/main.yaml @@ -0,0 +1 @@ +git_cache_root: "{{ansible_user_dir }}/git-cache" diff --git a/roles/git-prepare-nodecache/tasks/main.yaml b/roles/git-prepare-nodecache/tasks/main.yaml new file mode 100644 index 000000000..38d0aa7df --- /dev/null +++ b/roles/git-prepare-nodecache/tasks/main.yaml @@ -0,0 +1,42 @@ +- 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 + 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