def get_container_publisher(configp): """ Look up the registry host and token from a ConfigParser object. """ host = config.lookup(configp, 'publish', 'registry_host', fatal=False) if not host: return None token = config.lookup(configp, 'publish', 'registry_token', fatal=True) return ContainerPublisher(host, token)
def build_container(repo_urls, branch, parent_image, scratch, configp): """ Build a container with Koji. """ kconf = dict(configp.items('koji', vars={'branch': branch})) koji = KojiBuilder(profile=kconf['profile']) parent = None if parent_image: registry_url = config.lookup(configp, 'registry', 'url') registry = Registry(registry_url) parent = registry.build(parent_image) # bucko.build.Build log.info('Building container at %s' % koji.session.baseurl) task_id = koji.build_container(scm=kconf['scm'], target=kconf['target'], branch=branch, repos=repo_urls, scratch=scratch, koji_parent_build=parent) # Show information to the console. koji.watch_task(task_id) # Untag the build from the -candidate tag: # There's no "skip_tag" parameter for buildContainer, so we must # immediately untag it ourselves. if not scratch: koji.untag_task_result(task_id) # Return information about this build. result = {'koji_task': task_id} repositories = koji.get_repositories(task_id, kconf['target']) # "repository" (first in the list) is the OSBS unique tag. result['repository'] = repositories[0] result['repositories'] = repositories return result
def get_publisher(configp): """ Look up the push url and http url from a ConfigParser object. """ push_url = config.lookup(configp, 'publish', 'push') http_url = config.lookup(configp, 'publish', 'http') return Publisher(push_url, http_url)
def main(): """ Scratch-build a container for an HTTP-accessible compose. """ args = parse_args() if args.compose is None: err = 'Please set the CI_MESSAGE env var or use --compose arg' raise SystemExit(err) compose_url = args.compose # Load config file configp = config.load() # Load compose c = get_compose(compose_url, configp) # Generate .repo file log.info('Generating .repo file for %s compose' % c.info.release.short) filename = c.write_yum_repo_file() # Publish the .repo file p = get_publisher(configp) log.info('Publishing .repo file to %s' % p.push_url) repo_url = p.publish(filename) log.info('Published %s' % repo_url) # Determine scm and brew target branch name branch = get_branch(c) # Determine other settings for this branch section = '%s-base' % branch # eg "ceph-4.0-rhel-8-base" parent_image = config.lookup(configp, section, 'parent_image', fatal=False) if parent_image: log.info('parent_image configured: %s' % parent_image) repo_urls = config.get_repo_urls(configp, section) for url in repo_urls: log.info('Additional .repo configured: %s' % url) repo_urls.add(repo_url) # Do a Koji build metadata = build_container(repo_urls, branch, parent_image, args.scratch, configp) # Publish this Koji build to our registry container_pub = get_container_publisher(configp) if container_pub and 'repository' in metadata: source_image = metadata['repository'] dest_namespace, _ = branch.split('-', 1) # eg "ceph" _, unique_tag = source_image.split(':', 1) # OSBS unique build tag for tag in ('latest', unique_tag): dest_repo = container_pub.publish(source_image, dest_namespace, branch, tag) if dest_repo: # Add the new location to metadata['repositories'] so that we # record it in the -osbs.json file below. metadata['repositories'].append(dest_repo) # Store and publish our information about this build metadata['compose_url'] = compose_url metadata['compose_id'] = c.info.compose.id json_file = write_metadata_file(c.info.compose.id + '-osbs.json', **metadata) json_url = p.publish(json_file) log.info('OSBS JSON data at %s' % json_url) write_props_file(**metadata)
def test_lookup_nonfatal(simple_configp): result = config.lookup(simple_configp, 'testsection', 'baz', fatal=False) assert result is None
def test_lookup_fatal(simple_configp): with pytest.raises(SystemExit) as e: config.lookup(simple_configp, 'testsection', 'baz') assert 'bucko.conf' in str(e)
def test_lookup_present(simple_configp): result = config.lookup(simple_configp, 'testsection', 'foo') assert result == 'bar'