Browse Source

Add prepare-workspace-git role

Currently the incremental push of the git repos to the nodes is split
into a part in project-config and a part in zuul-jobs and only works
within the OpenStack context. The prepare-workspace-git role is an
attempt to make this generically available in zuul-jobs.

It first checks for each needed project if it's cached. If yes it's
cloned to the destination, if not it's just initialized as an empty
git repo. After that we can generically use git operations to sync the
correct state of the repos to the destination.

Change-Id: I87938a02d51e561b25ca2cb20f53d62f3cd3ae73
changes/36/613036/4
Tobias Henkel 7 months ago
parent
commit
7cee7156bc
No account linked to committer's email address

+ 17
- 0
roles/prepare-workspace-git/README.rst View File

@@ -0,0 +1,17 @@
1
+Mirror the local git repos to remote nodes
2
+
3
+This role uses git operations (unlike :zuul:role:`prepare-workspace`
4
+which uses rsync) to mirror the locally prepared git repos to the remote
5
+nodes while taking advantage of cached repos on the node if they exist.
6
+This role works generically regardless of the existence of a cached
7
+repo on the node.
8
+
9
+The 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.

+ 1
- 0
roles/prepare-workspace-git/defaults/main.yaml View File

@@ -0,0 +1 @@
1
+cached_repos_root: /opt/git

+ 56
- 0
roles/prepare-workspace-git/tasks/main.yaml View File

@@ -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

Loading…
Cancel
Save