tripleo-quickstart-extras/roles/build-test-packages/tasks/main.yml

312 lines
10 KiB
YAML

---
# needed to avoid potential failure when role is used without gather
- name: gather facts used by role
setup:
gather_subset:
- '!min'
- user_dir
- python
- processor
- pkg_mgr
- distribution
- name: Ensure DLRN package dependencies
become: true
package:
state: present
name:
- createrepo
- gcc
- git
- libffi-devel
- mock
- openssl-devel
- redhat-rpm-config
- rsync
- rpm-build
- rpmdevtools
- sqlite
- python3-libselinux
register: package_ensure_dlrndeps
until: package_ensure_dlrndeps is success
retries: 3
delay: 5
- name: Create mock group
become: true
group:
name: mock
state: present
- name: Add user to mock group
become: true
user:
name: '{{ ansible_user_id }}'
groups: mock
append: true
- name: Fetch DLRN from source
git:
repo: '{{ artg_dlrn_repo_url }}'
dest: '{{ build_repo_dir }}/DLRN'
version: 'master'
register: _git_clone
until: _git_clone is success
retries: 3
delay: 5
when: dlrn_pre_installed|bool
- name: Ensure DLRN dir is present
file:
path: '{{ build_repo_dir }}/DLRN/'
state: directory
- name: Remove data files from previous runs
shell:
rm -rf '{{ build_repo_dir }}/DLRN/*'
args:
warn: false
register: result
changed_when: result.stdout or result.stderr
- name: drop in the templated version of projects.ini
template:
src: projects.ini.j2
dest: '{{ build_repo_dir }}/DLRN/projects.ini'
- name: Pip installs
vars:
ansible_python_interpreter: "/usr/bin/{{ python_cmd }}"
block:
- name: Install and update pip
# noqa 403
pip:
name: pip
virtualenv: "{{ build_repo_dir }}/dlrn-venv"
virtualenv_command: "/usr/bin/{{ python_cmd }} -m venv"
state: latest
extra_args: --upgrade
- name: Pip install rdopkg
# noqa 403
pip:
name: rdopkg
virtualenv: "{{ build_repo_dir }}/dlrn-venv"
virtualenv_command: "/usr/bin/{{ python_cmd }} -m venv"
state: latest
when: not dlrn_pre_installed|bool
- name: Pip install DLRN
# noqa 403
pip:
name: dlrn
virtualenv: "{{ build_repo_dir }}/dlrn-venv"
virtualenv_command: "/usr/bin/{{ python_cmd }} -m venv"
state: latest
when: not dlrn_pre_installed|bool
- name: Pip install pre-installed DLRN
shell: >
source {{ build_repo_dir }}/dlrn-venv/bin/activate;
pip install -r requirements.txt;
{{ python_cmd }} setup.py install;
args:
chdir: '{{ build_repo_dir }}/DLRN'
when: dlrn_pre_installed|bool
- name: copy the DLRN scripts in the virtualenv to the scripts dir
synchronize:
src: "{{ build_repo_dir }}/dlrn-venv/share/dlrn/scripts"
dest: "{{ build_repo_dir }}/DLRN"
delegate_to: "{{ inventory_hostname }}"
- name: Fetch local rdoinfo copy
git:
repo: '{{ artg_rdoinfo_repo_url }}'
dest: '{{ build_repo_dir }}/DLRN/{{ rdoinfo_repo_name }}'
version: 'master'
register: _git_clone
until: _git_clone is success
retries: 3
delay: 5
- name: Remove ssh reference from dist-git url
shell: >
sed -i -e "s|osp-distgit: git+ssh|osp-distgit: git|g" packages.yml
args:
chdir: "{{ build_repo_dir }}/DLRN/{{ rdoinfo_repo_name }}"
when: ansible_distribution in ['RedHat']
- name: Use local {{ ansible_distribution }} mirror if available ( centos 7 and RHEL )
shell: >
set -o pipefail ;
gawk '{ print $0 }; /^# repos$/ { exit }' {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}.cfg
> {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}-local.cfg;
cat /etc/yum.repos.d/quickstart-{{ ansible_distribution | lower }}-*.repo >> {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}-local.cfg;
find /etc/yum.repos.d -name "delorean*repo" ! -name "delorean*build-deps.repo" -exec cat {} \; -exec echo "" \;
>> {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}-local.cfg;
find /etc/yum.repos.d -name "delorean*build-deps.repo" -exec sed 's/enabled=.*/enabled=1/g' {} \;
>> {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}-local.cfg;
{% if ansible_distribution in ["RedHat"] and osp_release is defined %}
find /etc/yum.repos.d -name "osptrunk-deps.repo" -exec sed 's/enabled=.*/enabled=1/g' {} \;
>> {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}-local.cfg;
{% endif %}
echo '"""' >> {{ build_repo_dir }}/DLRN/scripts/{{ initial_dlrn_config }}-local.cfg;
mkdir -p /tmp/fake-dlrn-repos/current;
touch /tmp/fake-dlrn-repos/delorean-deps.repo;
touch /tmp/fake-dlrn-repos/current/delorean.repo;
when:
- dlrn_use_local_mirrors|bool
- name: get env variables for changes and default change list
set_fact:
gerrit_host: "{{ lookup('env', 'GERRIT_HOST') }}"
zuul_changes: "{{ lookup('env', 'ZUUL_CHANGES') }}"
artg_change_list: "{{ artg_change_list|default([]) }}"
cacheable: true
- name: Parse Jenkins changes
jenkins_deps:
host: "{{ lookup('env', 'GERRIT_HOST') }}"
change_id: "{{ lookup('env', 'GERRIT_CHANGE_ID') }}"
branch: "{{ lookup('env', 'GERRIT_BRANCH') }}"
patchset_rev: "{{ lookup('env', 'GERRIT_PATCHSET_REVISION') }}"
when: gerrit_host != "" # noqa 602
- name: Add Jenkins changes to the change list
set_fact:
artg_change_list: "{{ artg_change_list|union(jenkins_change_list|default([])) }}"
cacheable: true
# Below is the list of cases needs to handle while constructing zuul change lists to process
# 1. Gerrit change branch is not equal to project branch
# 2. project name should be present in zuul processed change list
- name: construct zuul deps list
set_fact:
artg_change_list: "{{ artg_change_list|default([]) + [{'host': item.change_url.rpartition('/')[0],
'project': item.project.name,
'branch': item.branch,
'refspec': '/'.join(['refs', 'changes',
item.change[-2:],
item.change,
item.patchset]) }] }}"
cacheable: true
with_items: "{{ zuul['items'] }}"
when:
- zuul is defined
- "'change_url' in item"
- item.project.name not in artg_change_list|default([]) | map(attribute='project') |list
- (item.branch == zuul.override_checkout | default(zuul.branch)) or (osp_release is defined and osp_release in item.branch)
- name: Detect github PRs from commit message
include: detect_github_pr.yml
- name: Print out the change list
debug:
var: artg_change_list
- name: Check loop devices stat
stat:
path: "/dev/loop{{ item }}"
register: stat_loop_devices
with_sequence: start=0 end=11
- name: Set loop_devices_absent fact
set_fact:
loop_devices_absent: "{{ stat_loop_devices.results|selectattr('stat.exists','equalto',false)|map(attribute='item')|list }}"
- name: Clone and build the specific DLRN projects
include: dlrn-build.yml artg_change={{ item }}
with_items: '{{ artg_change_list|default([]) }}'
when:
- '"-distgit" not in item.project'
- item.project not in artg_skipped_projects
- release in item.branch or (zuul.project.name | default("") == rdoinfo_repo_name) or (osp_release is defined and osp_release in item.branch)
- '"github.com" not in item.host'
- name: Build package using DLRN
when: not artg_build_one|bool
block:
- name: Generate DLRN Script
template:
src: run_dlrn.sh.j2
dest: "{{ build_repo_dir }}/run_dlrn.sh"
mode: 0744
- name: Run DLRN
shell: >
set -o pipefail &&
{{ build_repo_dir }}/run_dlrn.sh 2>&1 {{ timestamper_cmd }} >> {{ build_repo_dir }}/dlrn.log
args:
chdir: '{{ build_repo_dir }}'
register: repo_built_multi
- name: Clone and build the Github PRs
include: github-pr.yml artg_change={{ item }}
with_items: '{{ artg_change_list|default([]) }}'
when:
- '"github.com" in item.host'
- item.project in artg_github_projects
- name: Clean up loop devices created by mock
file:
path: "/dev/loop{{ item }}"
state: absent
become: true
with_items: "{{ loop_devices_absent }}"
- block:
- name: Create a directory to hold the rpms
file:
path: '{{ build_repo_dir }}/gating_repo'
state: directory
- name: Copy the generated rpms
shell: >
set -o pipefail &&
rm -rf {{ build_repo_dir }}/gating_repo/*;
[[ $(find {{ build_repo_dir }}/DLRN/data/repos -type f -name '*.rpm') ]] &&
find {{ build_repo_dir }}/DLRN/data/repos -type f -name '*.rpm' -print0 | xargs -0 cp -t {{ build_repo_dir }}/gating_repo ||
echo "no DLRN builds";
[[ $(find ~/rpmbuild/RPMS/noarch/*collection*.rpm) ]] &&
find ~/rpmbuild/RPMS/noarch -type f -name '*collection*.rpm' -print0 | xargs -0 cp -t {{ build_repo_dir }}/gating_repo ||
echo "no collection builds";
- name: Run createrepo on generated rpms
command: createrepo gating_repo
args:
chdir: '{{ build_repo_dir }}'
- name: Compress the repo
# noqa 303
command: 'tar czf {{ artg_compressed_gating_repo }} gating_repo'
args:
chdir: '{{ build_repo_dir }}'
- name: Trigger repo injection for quickstart
set_fact:
compressed_gating_repo: "{{ artg_compressed_gating_repo }}"
cacheable: true
when:
- >-
artg_rdo_packages|default([])|length > 0 or
ansible_coll_packages|default([])|length > 0
- name: Clean up
file:
path: '{{ item }}'
state: absent
with_items:
- '{{ build_repo_dir }}/dlrn-venv'
- '{{ build_repo_dir }}/gating_repo'
when: dlrn_cleanup|bool
- name: Clean up DLRN if it was cloned by the playbook
file:
path: '{{ build_repo_dir }}/DLRN'
state: absent
when:
- not dlrn_pre_installed|bool
- dlrn_cleanup|bool