Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#128 from openstack-k8s-ope…
Browse files Browse the repository at this point in the history
…rators/build_openstack_packages

Add build_openstack_packages role
  • Loading branch information
openshift-merge-robot authored Apr 19, 2023
2 parents e5bde82 + 67d2c97 commit 2fee4d6
Show file tree
Hide file tree
Showing 13 changed files with 699 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ci_framework/roles/build_openstack_packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Role: build_openstack_packages
An Ansible role for generating custom RPMSs of OpenStack Projects using DLRN

### Parameters

* `cifmw_bop_dlrn_deps`: A list of DLRN project system dependencies.
* `cifmw_bop_build_repo_dir`: The directory where the DLRN repo is built. The variable defaults to the home directory of the user.
* `cifmw_bop_dlrn_repo_url`: The URL of the DLRN repository
* `cifmw_bop_dlrn_from_source`: Install DLRN from git. The default value is false
* `cifmw_bop_rdoinfo_repo_url`: The URL of the rdoinfo repository that contains the project definitions for DLRN
* `cifmw_bop_rdoinfo_repo_name`: Name of the rdoinfo repository
* `cifmw_bop_initial_dlrn_config`: Name of the initial DLRN config. The default value is centos
* `cifmw_bop_dlrn_target`: Name of the DLRN target. The default value is centos9-local.
* `cifmw_bop_use_components`: Build the openstack rpm packages under component. The default value is 1. Set 0 to avoid using it.
* `cifmw_bop_yum_repos_dir`: The path to repos generated by repo-setup tool.
* `cifmw_bop_openstack_release`: The default release of OpenStack project. Default value is master.
* `cifmw_bop_openstack_project_path`: The full path of openstack clonned project to be built
* `cifmw_bop_gating_repo`: The path of directory to store the generated rpms.
* `cifmw_bop_dlrn_cleanup`: Clean up the DLRN aftifacts. The default is set to False.

### TODO
- Allow building multiple openstack projects
- Build RDO dist-git changes
- Parse gerrit review and clone the respective project and build it
- Build rpm from Zuul Depends On

### Sample Playbook

```
- hosts: localhost
vars:
cifmw_bop_dlrn_target: centos9-stream
cifmw_bop_initial_dlrn_config: centos9-local
cifmw_bop_dlrn_baseurl: https://trunk.rdoproject.org/centos9-master
cifmw_bop_yum_repos_dir: /tmp/repos
pre_tasks:
- name: Clone neutron-tempest-plugin
ansible.builtin.git:
accept_hostkey: true
dest: "/tmp/neutron-tempest-plugin"
repo: "https://github.com/openstack/neutron-tempest-plugin"
- name: Set cifmw_bop_openstack_project_path
ansible.builtin.set_fact:
cifmw_bop_openstack_project_path: "/tmp/neutron-tempest-plugin"
roles:
- role: "build_openstack_packages"
```
67 changes: 67 additions & 0 deletions ci_framework/roles/build_openstack_packages/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


# All variables intended for modification should be placed in this file.
# All variables within this role should have a prefix of "cifmw_bop"
cifmw_bop_dlrn_deps:
- createrepo
- gcc
- git
- libffi-devel
- mock
- openssl-devel
- redhat-rpm-config
- rsync
- rpm-build
- rpmdevtools
- sqlite
- python3-libselinux

cifmw_bop_build_repo_dir: "{{ ansible_user_dir }}"
cifmw_bop_dlrn_repo_url: "https://github.com/openstack-packages/DLRN.git"
cifmw_bop_dlrn_from_source: false

cifmw_bop_rdoinfo_repo_url: https://github.com/redhat-openstack/rdoinfo
cifmw_bop_rdoinfo_repo_name: rdoinfo

cifmw_bop_initial_dlrn_config: >-
{%- if ansible_distribution == "RedHat" -%}
redhat
{%- elif ansible_distribution == "CentOS" -%}
centos{{ ansible_distribution_major_version }}
{%- endif -%}
cifmw_bop_dlrn_target: >-
{%- if ansible_distribution == "RedHat" -%}
redhat-local
{%- elif ansible_distribution == "CentOS" -%}
centos{{ ansible_distribution_major_version }}-local
{%- endif -%}
cifmw_bop_dlrn_baseurl: https://trunk.rdoproject.org/{{ ansible_distribution }}{{ ansible_distribution_major_version }}/
cifmw_bop_use_components: 1

cifmw_bop_yum_repos_dir: "/etc/yum.repos.d"

cifmw_bop_openstack_release: master
cifmw_bop_openstack_project_path: ''

cifmw_bop_gating_repo: "{{ cifmw_bop_build_repo_dir }}/gating_repo"
cifmw_bop_dlrn_cleanup: false

cifmw_bop_timestamper_cmd: >-
| awk '{ print strftime("%Y-%m-%d %H:%M:%S |"), $0; fflush(); }'
41 changes: 41 additions & 0 deletions ci_framework/roles/build_openstack_packages/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


galaxy_info:
author: CI Framework
description: CI Framework Role -- build_openstack_packages
company: Red Hat
license: Apache-2.0
min_ansible_version: 2.14
namespace: edpm
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: CentOS
versions:
- 9

galaxy_tags:
- edpm

# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


- name: Converge
hosts: all
vars:
ansible_user_dir: "{{ lookup('env', 'HOME') }}"
cifmw_basedir: "{{ ansible_user_dir }}/src/github.com/openstack-k8s-operators/ci-framework"
cifmw_bop_dlrn_target: centos9-stream
cifmw_bop_initial_dlrn_config: centos9-local
cifmw_bop_dlrn_baseurl: https://trunk.rdoproject.org/centos9-master
cifmw_bop_yum_repos_dir: "{{ cifmw_basedir }}/artifacts/repositories/"
pre_tasks:
- name: Clone neutron-tempest-plugin
ansible.builtin.git:
accept_hostkey: true
dest: "/tmp/neutron-tempest-plugin"
repo: "https://github.com/openstack/neutron-tempest-plugin"

- name: Set cifmw_bop_openstack_project_path
ansible.builtin.set_fact:
cifmw_bop_openstack_project_path: "/tmp/neutron-tempest-plugin"

roles:
- role: "build_openstack_packages"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Mainly used to override the defaults set in .config/molecule/
# By default, it uses the "config_podman.yml" - in CI, it will use
# "config_local.yml".
log: true

provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


- name: Prepare
hosts: all
vars:
ansible_user_dir: "{{ lookup('env', 'HOME') }}"
cifmw_basedir: "{{ ansible_user_dir }}/src/github.com/openstack-k8s-operators/ci-framework"
roles:
- role: test_deps
- role: repo_setup
32 changes: 32 additions & 0 deletions ci_framework/roles/build_openstack_packages/tasks/cleanup_dlrn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Clean up
ansible.builtin.file:
path: '{{ item }}'
state: absent
with_items:
- '{{ cifmw_bop_build_repo_dir }}/dlrn-venv'
- '{{ cifmw_bop_build_repo_dir }}/gating_repo'
when: cifmw_bop_dlrn_cleanup|bool

- name: Clean up DLRN if it was cloned by the playbook
ansible.builtin.file:
path: '{{ cifmw_bop_build_repo_dir }}/DLRN'
state: absent
when:
- not cifmw_bop_dlrn_from_source|bool
- cifmw_bop_dlrn_cleanup|bool
38 changes: 38 additions & 0 deletions ci_framework/roles/build_openstack_packages/tasks/create_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Create a directory to hold the rpms
file:
path: '{{ cifmw_bop_gating_repo }}'
state: directory

- name: Copy the generated rpms
shell: >
set -o pipefail &&
rm -rf {{ cifmw_bop_gating_repo }}/*;
[[ $(find {{ cifmw_bop_build_repo_dir }}/DLRN/data/repos -type f -name '*.rpm') ]] &&
find {{ cifmw_bop_build_repo_dir }}/DLRN/data/repos -type f -name '*.rpm' -print0 | xargs -0 cp -t {{ cifmw_bop_gating_repo }} ||
echo "no DLRN builds";
- name: Run createrepo on generated rpms
command: createrepo gating_repo
args:
chdir: '{{ cifmw_bop_build_repo_dir }}'

- name: Compress the repo
command: 'tar czf {{ cifmw_bop_gating_repo }}.tar.gz gating_repo'
args:
chdir: '{{ cifmw_bop_build_repo_dir }}'
Loading

0 comments on commit 2fee4d6

Please sign in to comment.