Use zuul_workspace_root for prepare/mirror workspace test roles

Use zuul_workspace_root as the destination folder for preparing and
mirroring the workspace, which points to ansible_user_dir by default.
(As is currently the case).
The override of this variable can be useful when using a static node
with multiple slots to use a separate workspace for each slot.

Change-Id: I2014b9c876907cfc17a0ec7fa2b6d4e67cb2331c
This commit is contained in:
Benedikt Loeffler 2023-06-15 17:09:36 +02:00
parent 29f27ebaaa
commit 258add7bb4
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 If `true` git operations will be silenced and won't print every
changed reference. changed reference.
.. 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 @@
mirror_workspace_quiet: false mirror_workspace_quiet: false
zuul_workspace_root: "{{ ansible_user_dir }}"

View File

@ -3,7 +3,7 @@
name: receive.denyCurrentBranch name: receive.denyCurrentBranch
value: ignore value: ignore
scope: local scope: local
repo: "{{ ansible_user_dir }}/{{ zj_project.value.src_dir }}" repo: "{{ zuul_workspace_root }}/{{ zj_project.value.src_dir }}"
with_dict: "{{ zuul.projects }}" with_dict: "{{ zuul.projects }}"
loop_control: loop_control:
loop_var: zj_project loop_var: zj_project
@ -11,9 +11,9 @@
- name: Synchronize src repos to workspace directory - name: Synchronize src repos to workspace directory
command: |- command: |-
{% if ansible_connection == "kubectl" %} {% 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 %} {% 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 %} {% endif %}
args: args:
chdir: "{{ zuul.executor.work_root }}/{{ zj_project.value.src_dir }}" chdir: "{{ zuul.executor.work_root }}/{{ zj_project.value.src_dir }}"
@ -52,7 +52,7 @@
echo "{{ zj_project.value.canonical_name }} checked out to:" echo "{{ zj_project.value.canonical_name }} checked out to:"
git log --pretty=oneline -1 git log --pretty=oneline -1
args: args:
chdir: "{{ ansible_user_dir }}/{{ zj_project.value.src_dir }}" chdir: "{{ zuul_workspace_root }}/{{ zj_project.value.src_dir }}"
with_dict: "{{ zuul.projects }}" with_dict: "{{ zuul.projects }}"
loop_control: loop_control:
loop_var: zj_project 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 :default: /opt/git
The root of the cached repos. 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 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 if [ -d "{{ cached_repos_root }}/{{ zj_project.canonical_name }}" ] ; then
# We do a bare clone here first so that we skip creating a working # We do a bare clone here first so that we skip creating a working
# copy that will be overwritten later anyway. # 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 else
git init {{ ansible_user_dir }}/{{ zj_project.src_dir }} git init {{ zuul_workspace_root }}/{{ zj_project.src_dir }}
fi 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 config --local --bool core.bare false
git remote -v | grep origin && git remote rm origin || true git remote -v | grep origin && git remote rm origin || true
git remote add origin file:///dev/null git remote add origin file:///dev/null
args: args:
creates: "{{ ansible_user_dir }}/{{ zj_project.src_dir }}" creates: "{{ zuul_workspace_root }}/{{ zj_project.src_dir }}"
with_items: "{{ zuul.projects.values() | list }}" with_items: "{{ zuul.projects.values() | list }}"
loop_control: loop_control:
loop_var: zj_project loop_var: zj_project