-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
222 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
A copr-cli wrapper | ||
""" | ||
from subprocess import check_output, CalledProcessError | ||
|
||
class CoprCliCommandError(Exception): | ||
"""Raised when copr-cli command fails""" | ||
def __init__(self, message, command): | ||
self.message = message | ||
self.command = command | ||
super(CoprCliCommandError, self).__init__(message) #pylint: disable-all | ||
|
||
def copr_cli(command, executable=None): | ||
""" | ||
Run a copr-cli command | ||
""" | ||
if executable is None: | ||
executable = 'copr-cli' | ||
|
||
try: | ||
return check_output([executable] + command, universal_newlines=True) | ||
except CalledProcessError as error: | ||
raise CoprCliCommandError(error.output, error.cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Release a package to Copr | ||
""" | ||
|
||
import re | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr_wrapper import copr_cli, CoprCliCommandError # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Build a package in koji | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
srpm=dict(type='path', required=True), | ||
repo_name=dict(type='str', required=True), | ||
wait=dict(type='bool', required=False, default=True) | ||
) | ||
) | ||
|
||
srpm = module.params['srpm'] | ||
repo_name = module.params['repo_name'] | ||
wait = module.params['wait'] | ||
|
||
command = ['build', repo_name, srpm] | ||
|
||
if not wait: | ||
command.append('--nowait') | ||
|
||
try: | ||
output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr build failed', command=error.command, output=error.message, | ||
repo_name=repo_name, srpm=srpm) | ||
|
||
builds = re.findall(r'^Build was added to.+:\n^\s(.+)', output, re.MULTILINE) | ||
|
||
module.exit_json(changed=True, output=output, builds=builds) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Manage a chroot in a Copr repository | ||
""" | ||
|
||
import re | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr_wrapper import copr_cli, CoprCliCommandError # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Manage a chroot in a Copr repository | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
repo_name=dict(type='str', required=True), | ||
chroot=dict(type='str', required=True), | ||
external_repos=dict(type='list', required=False, default=[]), | ||
buildroot_packages=dict(type='list', required=False, default=[]), | ||
modules=dict(type='list', required=False, default=[]), | ||
) | ||
) | ||
|
||
repo_name = module.params['repo_name'] | ||
chroot = module.params['chroot'] | ||
external_repos = module.params['external_repos'] | ||
buildroot_packages = module.params['buildroot_packages'] | ||
modules = module.params['modules'] | ||
|
||
command = [ | ||
'edit-chroot', | ||
"%s/%s" % (repo_name, chroot) | ||
] | ||
|
||
if external_repos: | ||
command.extend(['--repos', external_repos.join(' ')]) | ||
|
||
if buildroot_packages: | ||
command.extend(['--packages', buildroot_packages.join(' ')]) | ||
|
||
if modules: | ||
command.extend(['--modules', modules.join(',')]) | ||
|
||
try: | ||
output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr chroot edit failed', command=' '.join(error.command), output=error.message) | ||
|
||
module.exit_json(changed=True, output=output) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Create a repository in Copr | ||
""" | ||
|
||
import re | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr_wrapper import copr_cli, CoprCliCommandError # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Create a repository in Copr | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
repo_name=dict(type='str', required=True), | ||
chroots=dict(type='list', required=True), | ||
description=dict(type='str', required=False), | ||
unlisted_on_homepage=dict(type='bool', required=False, default=True), | ||
delete_after_days=dict(type='str', required=False, default=None), | ||
) | ||
) | ||
|
||
repo_name = module.params['repo_name'] | ||
chroots = module.params['chroots'] | ||
description = module.params['description'] | ||
unlisted_on_homepage = module.params['unlisted_on_homepage'] | ||
delete_after_days = module.params['delete_after_days'] | ||
|
||
if not description: | ||
description = repo_name | ||
|
||
command = [ | ||
'create', | ||
repo_name, | ||
'--description', | ||
"'%s'" % description | ||
] | ||
|
||
for chroot in chroots: | ||
command.extend(['--chroot', chroot]) | ||
|
||
if unlisted_on_homepage: | ||
command.extend(['--unlisted-on-hp', 'on']) | ||
|
||
if delete_after_days: | ||
command.extend(['--delete-after-days', delete_after_days]) | ||
|
||
try: | ||
output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr repository creation failed', command=' '.join(error.command), output=error.message) | ||
|
||
module.exit_json(changed=True, output=output) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
--- | ||
- name: 'Create copr scratch build repo' | ||
command: > | ||
copr-cli | ||
create | ||
{{ copr_repo_name }} | ||
--chroot {{ copr_repo_chroot }} | ||
--description '{{ copr_repo_description }}' | ||
--unlisted-on-hp on | ||
--repo '{{ copr_repo_external_repos | join(' ') }}' | ||
changed_when: false | ||
- name: 'Create Copr repo' | ||
copr_repo: | ||
repo_name: "{{ copr_repo_name }}" | ||
chroots: "{{ copr_repo_chroots | map(attribute='name') }}" | ||
description: "{{ copr_repo_description | default(omit) }}" | ||
delete_after_days: "{{ copr_repo_delete_after_days | default(omit) }}" | ||
unlisted_on_homepage: "{{ copr_repo_unlisted_on_homepage | default(omit) }}" | ||
register: create_output | ||
|
||
- name: 'Add build packages to chroot' | ||
command: > | ||
copr-cli | ||
edit-chroot | ||
{{ copr_repo_name }}/{{ copr_repo_chroot }} | ||
--packages '{{ copr_repo_packages | join(' ') }}' | ||
changed_when: false | ||
- name: Configure chroots | ||
copr_chroot: | ||
repo_name: "{{ copr_repo_name }}" | ||
chroot: "{{ chroot.name }}" | ||
external_repos: "{{ chroot.external_repos | default(omit) }}" | ||
buildroot_packages: "{{ chroot.buildroot_packages | default(omit) }}" | ||
modules: "{{ chroot.modules | default(omit) }}" | ||
loop: "{{ copr_repo_chroots }}" | ||
loop_control: | ||
loop_var: chroot |