summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2018-10-24 09:05:14 +0200
committerTobias Henkel <tobias.henkel@bmw.de>2018-10-31 06:11:41 +0100
commit7cee7156bcde8bc396ac4b6581bf2cae02eea0e9 (patch)
treebbd4a7242fc79c7a474c892413c66e188012c139
parent08af5f0110672a14917adb8fd1389fc37f433ab7 (diff)
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
Notes
Notes (review): Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+1: melissaml <ma.lei@99cloud.net> Code-Review+2: Clark Boylan <cboylan@sapwetik.org> Workflow+1: Clark Boylan <cboylan@sapwetik.org> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Nov 2018 19:40:40 +0000 Reviewed-on: https://review.openstack.org/613036 Project: openstack-infra/zuul-jobs Branch: refs/heads/master
-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