summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2018-11-09 15:09:26 +0100
committerTobias Henkel <tobias.henkel@bmw.de>2018-11-09 15:57:03 +0100
commitf96d1709326b6b5eebc1033d5e7ce70a0c77c110 (patch)
tree974f4e3a2fceea0ded56253df2b69e0171261bcd
parent34cfe44ca5c63c354339aa502052d9054a36bf60 (diff)
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
Notes
Notes (review): Code-Review+2: Clark Boylan <cboylan@sapwetik.org> Code-Review+2: Andreas Jaeger <jaegerandi@gmail.com> Workflow+1: Andreas Jaeger <jaegerandi@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Nov 2018 19:57:10 +0000 Reviewed-on: https://review.openstack.org/616946 Project: openstack-infra/zuul-jobs Branch: refs/heads/master
-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