Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inventory as a directory by using project_dir from Obsah #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion obal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ def inventory_path():
"""
Return the inventory path
"""
return os.environ.get('OBAL_INVENTORY', os.path.join(os.getcwd(), 'package_manifest.yaml'))
inventory = os.path.join(os.getcwd(), 'package_manifest.yaml')

if os.path.isdir('package_manifests'):
inventory = os.path.join(os.getcwd(), 'package_manifests')

return os.environ.get('OBAL_INVENTORY', inventory)
Comment on lines +63 to +68
Copy link
Member

@ekohl ekohl Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be clearer?

Suggested change
inventory = os.path.join(os.getcwd(), 'package_manifest.yaml')
if os.path.isdir('package_manifests'):
inventory = os.path.join(os.getcwd(), 'package_manifests')
return os.environ.get('OBAL_INVENTORY', inventory)
try:
return os.environ['OBAL_INVENTORY']
except KeyError:
if os.path.isdir('package_manifests'):
return os.path.join(os.getcwd(), 'package_manifests')
else:
return os.path.join(os.getcwd(), 'package_manifest.yaml')

Edit: what always bugged me was package_manifest and packages with tab completion. Should we follow Ansible and use inventory/ or inventory.yaml



def main(cliargs=None, application_config=ApplicationConfig): # pylint: disable=R0914
Expand Down
12 changes: 6 additions & 6 deletions obal/data/playbooks/add/add.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- name: 'Make package directory'
file:
state: 'directory'
path: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
path: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
register: package_directory_result

- block:
Expand All @@ -28,28 +28,28 @@
with_items: "{{ annex }}"
when: annex is defined
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"

- name: 'Git add new package'
command: "git add ./{{ package_base_dir }}/{{ inventory_hostname }}/*"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"

- name: 'Check if changes in package'
command: 'git status -s ./{{ package_base_dir }}/{{ inventory_hostname }}'
register: git_status
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"

- name: 'Git commit new package'
command: "git commit ./{{ package_base_dir }}/{{ inventory_hostname }} -m 'Add {{ inventory_hostname }}'"
when: git_status.stdout | length > 0
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"

- name: 'Git add new package'
command: "git add ./{{ package_base_dir }}/{{ inventory_hostname }}/*"
when: git_status.stdout | length > 0
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
when: package_directory_result is changed
6 changes: 3 additions & 3 deletions obal/data/playbooks/lint/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
tasks:
- name: 'Set default rpmlint RC file'
set_fact:
rpmlint_rc_file: "{{ inventory_dir }}/{{ package_base_dir }}{{ inventory_hostname }}/.rpmlintrc"
rpmlint_rc_file: "{{ project_dir }}/{{ package_base_dir }}{{ inventory_hostname }}/.rpmlintrc"
when: rpmlint_rc_file is not defined

- name: "RPM lint spec file"
command: "rpmlint --file {{ rpmlint_rc_file }} {{ inventory_dir }}/{{ package_base_dir }}{{ inventory_hostname }}"
command: "rpmlint --file {{ rpmlint_rc_file }} {{ project_dir }}/{{ package_base_dir }}{{ inventory_hostname }}"
register: output

- name: "Check for a new changelog entry"
rpmspec_changelog_check:
directory: "{{ inventory_dir }}/{{ package_base_dir }}{{ inventory_hostname }}"
directory: "{{ project_dir }}/{{ package_base_dir }}{{ inventory_hostname }}"

- name: 'Print rpmlint output'
debug:
Expand Down
2 changes: 1 addition & 1 deletion obal/data/playbooks/nightly/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
block:
- name: 'set package_dir'
set_fact:
package_dir: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
package_dir: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"

- name: 'set global_nightly_macro'
set_fact:
Expand Down
2 changes: 1 addition & 1 deletion obal/data/playbooks/srpm/metadata.obal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ variables:
help: SCL to set when building a SRPM
build_srpm_output_dir:
parameter: --dir
help: Absolute path to output dir for SRPM. Defaults to <inventory_dir>/SRPMs
help: Absolute path to output dir for SRPM. Defaults to <project_dir>/SRPMs
18 changes: 9 additions & 9 deletions obal/data/playbooks/update/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
- name: Determine source file from spec
shell: "spectool --list-files --all {{ spec_file_path }} | awk '{print $2}'"
args:
chdir: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
chdir: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
register: old_source_urls
when: old_source_urls is not defined
changed_when: False

- name: "Remove old sources"
command: "git rm --ignore-unmatch {{ item | basename }}"
args:
chdir: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
chdir: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
with_items: "{{ old_source_urls.stdout_lines | list }}"
when:
- "'://' in item"
Expand All @@ -30,47 +30,47 @@
- name: Determine new source file from spec
shell: "spectool --list-files --all {{ spec_file_path }} | awk '{print $2}'"
args:
chdir: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
chdir: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
register: new_source_urls
when: new_source_urls is not defined
changed_when: False

- name: 'Git annex add new sources'
command: "git annex add ./{{ package_base_dir }}/{{ inventory_hostname }}/{{ item | basename }}"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
with_items: "{{ new_source_urls.stdout_lines | list }}"
when:
- "'://' in item"

- name: 'Git add new sources'
command: "git -c annex.largefiles=nothing add ./{{ package_base_dir }}/{{ inventory_hostname }}/{{ item | basename }}"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
with_items: "{{ new_source_urls.stdout_lines | list }}"
when:
- "'://' not in item"

- name: 'Get updated version from spec'
command: "rpmspec --query --queryformat=%{version} --srpm {{ spec_file_path }}"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
changed_when: False
register: updated_version

- name: 'Get current git branch'
command: "git rev-parse --abbrev-ref HEAD"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
changed_when: False
register: git_branch

- name: 'Create git branch'
command: "git checkout -b {{ git_branch.stdout }}-update-{{ inventory_hostname }}-{{ updated_version.stdout }}"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"

- name: 'Create git commit'
command: "git commit -a -m 'Update {{ inventory_hostname }} to {{ updated_version.stdout }}'"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
4 changes: 2 additions & 2 deletions obal/data/roles/build_package/tasks/copr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- block:
- name: 'Release to copr'
tito_release:
directory: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
directory: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
arguments: "{{ build_package_tito_args }}"
test: "{{ build_package_test }}"
scratch: "{{ build_package_scratch }}"
Expand Down Expand Up @@ -33,7 +33,7 @@

- name: 'Build SRPM'
tito_build:
directory: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
directory: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
srpm: true
scl: "{{ scl }}"
register: srpm_build
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/build_package/tasks/download_logs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: "Download {{ build_package_koji_command }} task(s) logs"
command: "{{ build_package_koji_command }} download-logs -r {{ build_package_tito_release.tasks | join(' ') }}"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
when: build_package_build_system == 'koji' and build_package_download_logs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- block:
- set_fact:
download_dir: "{{ inventory_dir }}/downloaded_rpms/{{ item['Request Parameters']['Build Target'].split('-')[-1] }}"
download_dir: "{{ project_dir }}/downloaded_rpms/{{ item['Request Parameters']['Build Target'].split('-')[-1] }}"

- name: 'Create RPM downloads directory'
file:
Expand Down
4 changes: 2 additions & 2 deletions obal/data/roles/build_package/tasks/koji.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: "Confirm package is whitelisted"
package_whitelist_check:
releasers_conf: "{{ inventory_dir }}/rel-eng/releasers.conf"
releasers_conf: "{{ project_dir }}/rel-eng/releasers.conf"
spec_file_path: "{{ spec_file_path }}"
releasers: "{{ releasers }}"
build_command: "{{ build_package_koji_command }}"
Expand All @@ -19,7 +19,7 @@

- name: 'Release to {{ build_package_koji_command }}'
tito_release:
directory: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
directory: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
arguments: "{{ build_package_tito_args }}"
scratch: "{{ build_package_scratch and build_package_koji_command != 'brew'}}"
test: "{{ build_package_test }}"
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/build_srpm/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
build_srpm_dist:
build_srpm_scl:
build_srpm_tito_build_args: "{{ build_package_tito_releaser_args | default([]) }}"
build_srpm_output_dir: "{{ inventory_dir }}/SRPMs"
build_srpm_output_dir: "{{ project_dir }}/SRPMs"
build_srpm_tito_args: "{{ build_package_tito_args | default([]) }}"
build_srpm_tito_builder: "{{ build_package_tito_builder | default() }}"
2 changes: 1 addition & 1 deletion obal/data/roles/build_srpm/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: 'Build SRPM'
tito_build:
directory: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
directory: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
build_arguments: "{{ build_srpm_tito_build_args }}"
srpm: true
offline: true
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/ensure_package/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: check for package dir
stat:
path: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
path: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
register: package_dir
failed_when: not package_dir.stat.exists
6 changes: 3 additions & 3 deletions obal/data/roles/fetch_sources/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- name: 'Copy upstream files'
synchronize:
src: "{{ obal_tmp_dir }}/{{ upstream_directory }}/{{ item }}"
dest: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}/"
dest: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}/"
with_items: "{{ upstream_files }}"
when: #block
- upstream is defined
Expand All @@ -26,7 +26,7 @@
- name: 'Remove package directory'
file:
state: 'absent'
path: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
path: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"

- block:
- name: 'Make package download directory'
Expand All @@ -53,7 +53,7 @@
- name: 'Copy upstream files'
synchronize:
src: "{{ obal_tmp_dir }}/{{ inventory_hostname }}/{{ item }}"
dest: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}/"
dest: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}/"
with_items: "{{ upstream_files }}"
when: #block
- upstream is defined
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/git_annex_setup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
command: git annex init
args:
creates: .git/annex/index
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
2 changes: 1 addition & 1 deletion obal/data/roles/mock/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
mock_config: mock/el7.cfg
mock_output_dir: "{{ inventory_dir }}/mock_builds"
mock_output_dir: "{{ project_dir }}/mock_builds"
2 changes: 1 addition & 1 deletion obal/data/roles/mock/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
- name: Build with mock
shell: "mock --recurse --chain -r {{ mock_config }} --localrepo {{ mock_output_dir }} SRPMs/*"
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"
run_once: true
2 changes: 1 addition & 1 deletion obal/data/roles/repoclosure/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

- name: Find all downloaded repositories
find:
paths: "{{ inventory_dir }}/downloaded_rpms"
paths: "{{ project_dir }}/downloaded_rpms"
recurse: no
file_type: directory
register: downloaded_rpms_folders
Expand Down
4 changes: 2 additions & 2 deletions obal/data/roles/repoclosure/tasks/repoclosure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

- name: Copy repoclosure config to temp directory
copy:
src: "{{ inventory_dir }}/{{ repoclosure_config }}"
src: "{{ project_dir }}/{{ repoclosure_config }}"
dest: "{{ temp_directory.path }}/{{ config_filename }}"
remote_src: true

Expand All @@ -40,7 +40,7 @@
warn: false
register: output
args:
chdir: "{{ inventory_dir }}"
chdir: "{{ project_dir }}"

- debug:
msg: "{{ output.stdout_lines | join('\n') }}"
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/setup_sources/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: 'Set package_dir'
set_fact:
package_dir: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
package_dir: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"

- name: 'Setup sources from specfile'
include_tasks: specfile.yml
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/setup_workspace/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: 'Define tmp directory'
set_fact:
obal_tmp_dir: "{{ inventory_dir }}/.tmp"
obal_tmp_dir: "{{ project_dir }}/.tmp"

- name: 'Ensure .tmp directory'
file:
Expand Down
2 changes: 1 addition & 1 deletion obal/data/roles/spec_file/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: get spec file
find:
pattern: "*.spec"
path: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
path: "{{ project_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}"
register: spec_file

- name: "Set spec file path"
Expand Down