Implement push flag for buildah
KollaBuilder is able to bypass container push we implement the same thing here with the container_push flag in the constructor. Related-Bug: #1822752 Change-Id: I588154ad450bab13d3b20b77126d55ded5acd433
This commit is contained in:
parent
3db41939a3
commit
635b89d2b1
@ -33,7 +33,7 @@ class BuildahBuilder(base.BaseBuilder):
|
||||
|
||||
def __init__(self, work_dir, deps, base='fedora', img_type='binary',
|
||||
tag='latest', namespace='master',
|
||||
registry_address='127.0.0.1:8787'):
|
||||
registry_address='127.0.0.1:8787', push_containers=True):
|
||||
"""Setup the parameters to build with Buildah.
|
||||
|
||||
:params work_dir: Directory where the Dockerfiles
|
||||
@ -50,6 +50,7 @@ class BuildahBuilder(base.BaseBuilder):
|
||||
Default to master.
|
||||
:params registry_address: IP + port of the registry where we push
|
||||
the images. Default is 127.0.0.1:8787.
|
||||
:params push: Flag to bypass registry push if False. Default is True
|
||||
"""
|
||||
|
||||
super(BuildahBuilder, self).__init__()
|
||||
@ -61,6 +62,7 @@ class BuildahBuilder(base.BaseBuilder):
|
||||
self.tag = tag
|
||||
self.namespace = namespace
|
||||
self.registry_address = registry_address
|
||||
self.push_containers = push_containers
|
||||
# Each container image has a Dockerfile. Buildah needs to know
|
||||
# the base directory later.
|
||||
self.cont_map = {os.path.basename(root): root for root, dirs,
|
||||
@ -88,6 +90,7 @@ class BuildahBuilder(base.BaseBuilder):
|
||||
"""
|
||||
|
||||
self.build(container_name, self._find_container_dir(container_name))
|
||||
if self.push_containers:
|
||||
destination = "{}/{}/{}-{}-{}:{}".format(
|
||||
self.registry_address,
|
||||
self.namespace,
|
||||
|
@ -54,3 +54,23 @@ class TestBuildahBuilder(base.TestCase):
|
||||
mock_process.assert_called_once_with(
|
||||
*args, run_as_root=False, use_standard_locale=True
|
||||
)
|
||||
|
||||
@mock.patch.object(bb, 'build', autospec=True)
|
||||
@mock.patch.object(bb, 'push', autospec=True)
|
||||
def test_generate_container_with_push(self, mock_push, mock_build):
|
||||
container_name = "fedora-base"
|
||||
destination = "127.0.0.1:8787/master/fedora-binary-{}:latest"
|
||||
builder = bb(WORK_DIR, DEPS, push_containers=True)
|
||||
builder._generate_container(container_name)
|
||||
mock_build.assert_called_once_with(builder, container_name, "")
|
||||
mock_push.assert_called_once_with(builder,
|
||||
destination.format(container_name))
|
||||
|
||||
@mock.patch.object(bb, 'build', autospec=True)
|
||||
@mock.patch.object(bb, 'push', autospec=True)
|
||||
def test_generate_container_without_push(self, mock_push, mock_build):
|
||||
container_name = "fedora-base"
|
||||
builder = bb(WORK_DIR, DEPS, push_containers=False)
|
||||
builder._generate_container(container_name)
|
||||
mock_build.assert_called_once_with(builder, container_name, "")
|
||||
assert not mock_push.called
|
||||
|
Loading…
Reference in New Issue
Block a user