Skip to content

Commit

Permalink
Add support for composing containers.
Browse files Browse the repository at this point in the history
fixes fedora-infra#2028

Signed-off-by: Randy Barlow <[email protected]>
  • Loading branch information
bowlofeggs committed Mar 13, 2018
1 parent fc85ce7 commit b8c0fc2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 13 deletions.
14 changes: 14 additions & 0 deletions bodhi/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ class BodhiConfig(dict):
'captcha.ttl': {
'value': 300,
'validator': int},
'container.destination_registry': {
'value': 'registry.fedoraproject.org',
'validator': six.text_type},
'container.source_registry': {
'value': 'candidate-registry.fedoraproject.org',
'validator': six.text_type},
'cors_connect_src': {
'value': 'https://*.fedoraproject.org/ wss://hub.fedoraproject.org:9939/',
'validator': six.text_type},
Expand Down Expand Up @@ -547,6 +553,14 @@ class BodhiConfig(dict):
'site_requirements': {
'value': 'dist.rpmdeplint dist.upgradepath',
'validator': six.text_type},
'skopeo.cmd': {
'value': '/usr/bin/skopeo',
'validator': six.text_type,
},
'skopeo.extra_copy_flags': {
'value': '',
'validator': six.text_type,
},
'smtp_server': {
'value': None,
'validator': _validate_none_or(six.text_type)},
Expand Down
43 changes: 41 additions & 2 deletions bodhi/server/consumers/masher.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
from bodhi.server.metadata import UpdateInfoMetadata
from bodhi.server.models import (Compose, ComposeState, Update, UpdateRequest, UpdateType, Release,
UpdateStatus, ReleaseState, ContentType)
from bodhi.server.util import sorted_updates, sanity_check_repodata, transactional_session_maker
from bodhi.server.util import (cmd, sorted_updates, sanity_check_repodata,
transactional_session_maker)


def checkpoint(method):
Expand Down Expand Up @@ -304,7 +305,7 @@ def get_masher(content_type):
ComposerThread or None: Either a ContainerComposerThread, RPMComposerThread, or a
ModuleComposerThread, as appropriate, or None if no masher is found.
"""
mashers = [RPMComposerThread, ModuleComposerThread]
mashers = [ContainerComposerThread, RPMComposerThread, ModuleComposerThread]
for possible in mashers:
if possible.ctype is content_type:
return possible
Expand Down Expand Up @@ -859,6 +860,44 @@ def sort_by_days_in_testing(self, updates):
return updates


class ContainerComposerThread(ComposerThread):
"""Use skopeo to copy and tag container images."""

ctype = ContentType.container

def _compose_updates(self):
"""Use skopeo to copy images to the correct repos and tags."""
source_registry = config['container.source_registry']
destination_registry = config['container.destination_registry']

for update in self.compose.updates:

if update.request is UpdateRequest.stable:
destination_tag = 'latest'
else:
destination_tag = 'testing'

for build in update.builds:
image_name = '{}/{}'.format(build.release.branch, build.package.name)
name, version, release = build.nvr.rsplit('-', 2)
version_release = '{}-{}'.format(version, release)
for dtag in [version_release, version, destination_tag]:
source_url = 'docker://{}/{}:{}'.format(source_registry, image_name,
version_release)
destination_url = 'docker://{}/{}:{}'.format(destination_registry, image_name,
dtag)
skopeo_cmd = [
config.get('skopeo.cmd'), 'copy', config.get('skopeo.extra_copy_flags'),
source_url, destination_url]
log.info(skopeo_cmd)
skopeo_process = subprocess.Popen(
skopeo_cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = skopeo_process.communicate()

if skopeo_process.returncode:
raise RuntimeError(out + err)


class PungiComposerThread(ComposerThread):
"""Compose update with Pungi."""

Expand Down
32 changes: 21 additions & 11 deletions bodhi/server/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,27 @@ def push(username, cert_prefix, **kwargs):
click.echo('\nSending masher.start fedmsg')
# Because we're a script, we want to send to the fedmsg-relay,
# that's why we say active=True
bodhi.server.notifications.init(active=True, cert_prefix=cert_prefix)
bodhi.server.notifications.publish(
topic='masher.start',
msg=dict(
api_version=2,
composes=composes,
resume=resume,
agent=username,
),
force=True,
)
import mock
from bodhi.server.consumers import masher
from pyramid.paster import setup_logging
setup_logging('/home/vagrant/bodhi/development.ini')
with mock.patch('bodhi.server.consumers.masher.fedmsg.consumers.FedmsgConsumer.__init__'):
m = masher.Masher(mock.MagicMock())
import logging
m.log = logging.getLogger('bowlofeggs')
m.work({'body': {'msg': dict(api_version=2, composes=composes, resume=resume,
agent=username)}})
#bodhi.server.notifications.init(active=True, cert_prefix=cert_prefix)
#bodhi.server.notifications.publish(
# topic='masher.start',
# msg=dict(
# api_version=2,
# composes=composes,
# resume=resume,
# agent=username,
# ),
# force=True,
#)


def _filter_releases(session, query, releases=None):
Expand Down
14 changes: 14 additions & 0 deletions production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ use = egg:bodhi-server
# What to pass to Pungi's --label flag, which is metadata included in its composeinfo.json.
# pungi.labeltype = Update

# The skopeo executable to use to copy container images.
# You can put credentials for skopeo to use in $HOME/.docker/config.json
# https://github.com/projectatomic/skopeo#private-registries-with-authentication
# skopeo.cmd = /usr/bin/skopeo

# Extra flags to pass to the skopeo copy command.
# During development, it can be handy to set this to --dest-tls-verify=false if you want to push
# into a local registry.
# skopeo.extra_copy_flags =

# Container hostnames. You can specify a port as well, using the traditional syntax (i.e., localhost:5000).
# container.destination_registry = registry.fedoraproject.org
# container.source_registry = candidate-registry.fedoraproject.org


##
## Mirror settings
Expand Down

0 comments on commit b8c0fc2

Please sign in to comment.