summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-19 19:57:10 +0000
committerGerrit Code Review <review@openstack.org>2018-11-19 19:57:10 +0000
commit6ac6c21e3b1e0ce33adaa5101acba7101bafa397 (patch)
tree2eca9753af3c76c95d0ba16f594260806ebe27ea
parentbd26195f1520faf1256b1308b47d9e0ecc4e9886 (diff)
parentf96d1709326b6b5eebc1033d5e7ce70a0c77c110 (diff)
Merge "Add role git-prepare-nodecache"
-rw-r--r--roles/git-prepare-nodecache/README.rst15
-rw-r--r--roles/git-prepare-nodecache/defaults/main.yaml1
-rw-r--r--roles/git-prepare-nodecache/tasks/main.yaml42
3 files changed, 58 insertions, 0 deletions
diff --git a/roles/git-prepare-nodecache/README.rst b/roles/git-prepare-nodecache/README.rst
new file mode 100644
index 0000000..28d69e3
--- /dev/null
+++ b/roles/git-prepare-nodecache/README.rst
@@ -0,0 +1,15 @@
1Prepare an archive containing all repositories that are part of the job. This
2can be used to prepare the repos archive suitable for caching in the node
3image to be used by `prepare-workspace-git`.
4
5The path to the resulting archive file will be stored in the `git_cache_file`
6variable. That variable can be used to push the archive to a place where
7it will be picked up to be baked into the node image.
8
9**Role variables**
10
11.. zuul:rolevar:: git_cache_root
12 :default: {{ansible_user_dir }}/git-cache"
13
14 Directory where the git cache should be prepared. Usually this should not
15 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 0000000..96072c9
--- /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 0000000..38d0aa7
--- /dev/null
+++ b/roles/git-prepare-nodecache/tasks/main.yaml
@@ -0,0 +1,42 @@
1- name: Create git parent dirs
2 file:
3 path: "{{ git_cache_root }}/{{ item.canonical_name | dirname }}"
4 state: directory
5 with_items: "{{ zuul.projects.values() | list }}"
6
7- name: Copy git repos to {{ git_cache_root }}
8 command: cp -r "{{ ansible_user_dir }}/{{ item.src_dir }}/.git"
9 "{{ git_cache_root }}/{{ item.canonical_name }}"
10 with_items: "{{ zuul.projects.values() | list }}"
11
12- name: Mark repos as bare
13 command: git config --bool core.bare true
14 args:
15 chdir: "{{ git_cache_root }}/{{ item.canonical_name }}"
16 with_items: "{{ zuul.projects.values() | list }}"
17 # We don't want git module foo, just set a config value.
18 tags:
19 - skip_ansible_lint
20
21- name: Run git garbage collection
22 command: git gc
23 args:
24 chdir: "{{ git_cache_root }}/{{ item.canonical_name }}"
25 with_items: "{{ zuul.projects.values() | list }}"
26 # The ansible git module doesn't support garbage collection.
27 tags:
28 - skip_ansible_lint
29
30- name: Set git_cache_file variable
31 set_fact:
32 git_cache_file: "{{ git_cache_root }}/repos.tar.gz"
33
34- name: Create repos tarball
35 shell: |
36 tar -czf "{{ git_cache_file }}" *
37 args:
38 chdir: "{{ git_cache_root }}"
39 # Ansible lint wants we should use the unarchive module but we want the other
40 # way round.
41 tags:
42 - skip_ansible_lint