summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-19 19:40:40 +0000
committerGerrit Code Review <review@openstack.org>2018-11-19 19:40:40 +0000
commitdd3f9fe00b625ef905b2ab2de8a68e6342028c11 (patch)
tree1486df2ca02ed449e0ed65dd31a0eec4f77f084b
parent54f1a9f7ebcc097e8a095fb62d46e22f335e71af (diff)
parent7cee7156bcde8bc396ac4b6581bf2cae02eea0e9 (diff)
Merge "Add prepare-workspace-git role"
-rw-r--r--roles/prepare-workspace-git/README.rst17
-rw-r--r--roles/prepare-workspace-git/defaults/main.yaml1
-rw-r--r--roles/prepare-workspace-git/tasks/main.yaml56
3 files changed, 74 insertions, 0 deletions
diff --git a/roles/prepare-workspace-git/README.rst b/roles/prepare-workspace-git/README.rst
new file mode 100644
index 0000000..e1e4711
--- /dev/null
+++ b/roles/prepare-workspace-git/README.rst
@@ -0,0 +1,17 @@
1Mirror the local git repos to remote nodes
2
3This role uses git operations (unlike :zuul:role:`prepare-workspace`
4which uses rsync) to mirror the locally prepared git repos to the remote
5nodes while taking advantage of cached repos on the node if they exist.
6This role works generically regardless of the existence of a cached
7repo on the node.
8
9The cached repos need to be placed using the canonical name under the
10`cached_repos_root` directory.
11
12**Role Variables**
13
14.. zuul:rolevar:: cached_repos_root
15 :default: /opt/git
16
17 The root of the cached repos.
diff --git a/roles/prepare-workspace-git/defaults/main.yaml b/roles/prepare-workspace-git/defaults/main.yaml
new file mode 100644
index 0000000..b0c54a3
--- /dev/null
+++ b/roles/prepare-workspace-git/defaults/main.yaml
@@ -0,0 +1 @@
cached_repos_root: /opt/git
diff --git a/roles/prepare-workspace-git/tasks/main.yaml b/roles/prepare-workspace-git/tasks/main.yaml
new file mode 100644
index 0000000..89922cd
--- /dev/null
+++ b/roles/prepare-workspace-git/tasks/main.yaml
@@ -0,0 +1,56 @@
1- name: Find locally cached git repos
2 stat:
3 path: "{{ cached_repos_root }}/{{ item.canonical_name }}"
4 with_items: "{{ zuul.projects.values() | list }}"
5 register: cached_repos
6
7# We do a bare clone here first so that we skip creating a working copy that
8# will be overwritten later anyway.
9- name: Clone cached repo to workspace
10 shell: |
11 set -e
12 git clone --bare {{ cached_repos_root }}/{{ item.0.canonical_name }} {{ ansible_user_dir }}/{{ item.0.src_dir}}/.git
13 cd {{ ansible_user_dir }}/{{ item.0.src_dir }}
14 git config --local --bool core.bare false
15 args:
16 creates: "{{ ansible_user_dir }}/{{ item.0.src_dir}}"
17 when: item.1.stat.exists
18 with_together:
19 - "{{ zuul.projects.values() | list }}"
20 - "{{ cached_repos.results }}"
21 # ANSIBLE0006: If we use the git module, we get warning
22 # ANSIBLE0004 since we do not give an explicit version
23 tags:
24 - skip_ansible_lint
25
26- name: Initialize non-cached repos
27 command: "git init {{ ansible_user_dir }}/{{ item.0.src_dir}}"
28 args:
29 creates: "{{ ansible_user_dir }}/{{ item.0.src_dir}}"
30 when: not item.1.stat.exists
31 with_together:
32 - "{{ zuul.projects.values() | list }}"
33 - "{{ cached_repos.results }}"
34 # ANSIBLE0006: If we use the git module, we get warning
35 # ANSIBLE0004 since we do not give an explicit version
36 tags:
37 - skip_ansible_lint
38
39- name: Remove origin from local git repos and replace it by the zuul fake origin
40 # To be idempotent, remove origin only if it's found in the local list.
41 shell: |
42 set -e
43 git remote -v | grep origin && git remote rm origin || true
44 git remote add origin file:///dev/null
45 args:
46 chdir: "{{ ansible_user_dir }}/{{ item.src_dir}}"
47 with_items: "{{ zuul.projects.values() | list }}"
48 # ANSIBLE0006: git remote is not supported by ansible module
49 tags:
50 - skip_ansible_lint
51
52# TODO(tobiash): we might want to deprecate the role mirror-workspace-git-repos
53# and move it here.
54- name: Synchronize repos
55 import_role:
56 name: mirror-workspace-git-repos