Merge "Use zuul_workspace_root for prepare/mirror workspace roles"

This commit is contained in:
Zuul 2023-06-29 16:24:26 +00:00 committed by Gerrit Code Review
commit d490441a61
6 changed files with 20 additions and 8 deletions

View File

@ -12,3 +12,8 @@ some or all of the git repos.
If `true` git operations will be silenced and won't print every
changed reference.
.. zuul:rolevar:: zuul_workspace_root
:default: "{{ ansible_user_dir }}"
The root of the workspace.

View File

@ -1 +1,2 @@
mirror_workspace_quiet: false
zuul_workspace_root: "{{ ansible_user_dir }}"

View File

@ -3,7 +3,7 @@
name: receive.denyCurrentBranch
value: ignore
scope: local
repo: "{{ ansible_user_dir }}/{{ zj_project.value.src_dir }}"
repo: "{{ zuul_workspace_root }}/{{ zj_project.value.src_dir }}"
with_dict: "{{ zuul.projects }}"
loop_control:
loop_var: zj_project
@ -11,9 +11,9 @@
- name: Synchronize src repos to workspace directory
command: |-
{% if ansible_connection == "kubectl" %}
git push {% if mirror_workspace_quiet %}--quiet{% endif %} --mirror "ext::kubectl --context {{ zuul.resources[inventory_hostname].context }} -n {{ zuul.resources[inventory_hostname].namespace }} exec -i {{ zuul.resources[inventory_hostname].pod }} -- %S {{ ansible_user_dir }}/{{ zj_project.value.src_dir }}"
git push {% if mirror_workspace_quiet %}--quiet{% endif %} --mirror "ext::kubectl --context {{ zuul.resources[inventory_hostname].context }} -n {{ zuul.resources[inventory_hostname].namespace }} exec -i {{ zuul.resources[inventory_hostname].pod }} -- %S {{ zuul_workspace_root }}/{{ zj_project.value.src_dir }}"
{% else %}
git push {% if mirror_workspace_quiet %}--quiet{% endif %} --mirror git+ssh://{{ ansible_user }}@{{ ansible_host | ipwrap }}:{{ ansible_port }}/{{ ansible_user_dir }}/{{ zj_project.value.src_dir }}
git push {% if mirror_workspace_quiet %}--quiet{% endif %} --mirror git+ssh://{{ ansible_user }}@{{ ansible_host | ipwrap }}:{{ ansible_port }}/{{ zuul_workspace_root }}/{{ zj_project.value.src_dir }}
{% endif %}
args:
chdir: "{{ zuul.executor.work_root }}/{{ zj_project.value.src_dir }}"
@ -52,7 +52,7 @@
echo "{{ zj_project.value.canonical_name }} checked out to:"
git log --pretty=oneline -1
args:
chdir: "{{ ansible_user_dir }}/{{ zj_project.value.src_dir }}"
chdir: "{{ zuul_workspace_root }}/{{ zj_project.value.src_dir }}"
with_dict: "{{ zuul.projects }}"
loop_control:
loop_var: zj_project

View File

@ -15,3 +15,8 @@ The cached repos need to be placed using the canonical name under the
:default: /opt/git
The root of the cached repos.
.. zuul:rolevar:: zuul_workspace_root
:default: "{{ ansible_user_dir }}"
The root of the workspace in which the repos are mirrored.

View File

@ -1 +1,2 @@
cached_repos_root: /opt/git
zuul_workspace_root: "{{ ansible_user_dir }}"

View File

@ -7,16 +7,16 @@
if [ -d "{{ cached_repos_root }}/{{ zj_project.canonical_name }}" ] ; then
# We do a bare clone here first so that we skip creating a working
# copy that will be overwritten later anyway.
git clone --bare {{ cached_repos_root }}/{{ zj_project.canonical_name }} {{ ansible_user_dir }}/{{ zj_project.src_dir }}/.git
git clone --bare {{ cached_repos_root }}/{{ zj_project.canonical_name }} {{ zuul_workspace_root }}/{{ zj_project.src_dir }}/.git
else
git init {{ ansible_user_dir }}/{{ zj_project.src_dir }}
git init {{ zuul_workspace_root }}/{{ zj_project.src_dir }}
fi
cd {{ ansible_user_dir }}/{{ zj_project.src_dir }}
cd {{ zuul_workspace_root }}/{{ zj_project.src_dir }}
git config --local --bool core.bare false
git remote -v | grep origin && git remote rm origin || true
git remote add origin file:///dev/null
args:
creates: "{{ ansible_user_dir }}/{{ zj_project.src_dir }}"
creates: "{{ zuul_workspace_root }}/{{ zj_project.src_dir }}"
with_items: "{{ zuul.projects.values() | list }}"
loop_control:
loop_var: zj_project