How to use the cekit.builders.docker_builder.DockerBuilder function in cekit

To help you get started, we’ve selected a few cekit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cekit / cekit / tests / test_builder.py View on Github external
def test_docker_squashing_parameters(mocker):
    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))

    # None is fine here, default values for params are tested in different place
    assert builder.params.no_squash == None

    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
    squash_class = mocker.patch('cekit.builders.docker_builder.Squash')
    squash = squash_class.return_value
    docker_client = docker_client_class.return_value
    mocker.patch.object(builder, '_build_with_docker', return_value="1654234sdf56")

    builder.generator = Map({'image': {'from': 'FROM'}})

    builder.run()

    squash_class.assert_called_once_with(
        cleanup=True, docker=docker_client, from_layer="FROM", image="1654234sdf56", log=logging.getLogger('cekit'))
github cekit / cekit / tests / test_builder.py View on Github external
def create_builder_object(mocker, builder, params, common_params={'target': 'something'}):
    if 'docker' == builder:
        from cekit.builders.docker_builder import DockerBuilder as BuilderImpl
    elif 'osbs' == builder:
        from cekit.builders.osbs import OSBSBuilder as BuilderImpl
    elif 'podman' == builder:
        from cekit.builders.podman import PodmanBuilder as BuilderImpl
    elif 'buildah' == builder:
        from cekit.builders.buildah import BuildahBuilder as BuilderImpl
    else:
        raise Exception("Builder engine %s is not supported" % builder)

    mocker.patch('cekit.tools.decision')

    builder = BuilderImpl(Map(merge_two_dicts(common_params, params)))
    builder.dist_git_dir = '/tmp'
    builder.dist_git = DistGitMock()
    builder.artifacts = []
    return builder
github cekit / cekit / tests / test_builder.py View on Github external
def test_docker_squashing_enabled(mocker):
    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))

    # None is fine here, default values for params are tested in different place
    assert builder.params.no_squash == None
    assert builder.params.tags == ['foo', 'bar']

    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
    docker_client = docker_client_class.return_value
    mocker.patch.object(builder, '_build_with_docker')
    mocker.patch.object(builder, '_squash')
    builder._build_with_docker.return_value = "1654234sdf56"

    builder.run()

    builder._build_with_docker.assert_called_once_with(docker_client)
    builder._squash.assert_called_once_with(docker_client, "1654234sdf56")
github cekit / cekit / tests / test_unit_builder_docker.py View on Github external
def test_docker_client_build(mocker, caplog):
    caplog.set_level(logging.DEBUG, logger="cekit")

    squash_class = mocker.patch('cekit.builders.docker_builder.Squash')
    squash = squash_class.return_value
    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
    docker_client = docker_client_class.return_value
    docker_client_build = mocker.patch.object(
        docker_client, 'build', return_value=docker_success_output)

    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))
    builder.generator = Map({'image': {'from': 'FROM'}})
    builder.run()

    squash_class.assert_called_once_with(
        cleanup=True, docker=docker_client, from_layer="FROM", image="985573b8bb7b", log=logging.getLogger('cekit'))
    squash.run.assert_called_once_with()
    docker_client_build.assert_called_once_with(
        decode=True, path='something/image', pull=None, rm=True)
    assert "Docker: This system is not receiving updates. You can use subscription-manager on the host to register and assign subscriptions." in caplog.text
    assert "Image built and available under following tags: foo, bar" in caplog.text
github cekit / cekit / tests / test_builder.py View on Github external
def test_docker_squashing_disabled(mocker):
    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {
                            'no_squash': True, 'tags': ['foo', 'bar']})))

    assert builder.params.no_squash == True

    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
    docker_client = docker_client_class.return_value
    mocker.patch.object(builder, '_build_with_docker')
    mocker.patch.object(builder, '_squash')

    builder._build_with_docker.return_value = "1654234sdf56"

    builder.run()

    builder._build_with_docker.assert_called_once_with(docker_client)
    builder._squash.assert_not_called()
github cekit / cekit / tests / test_builder.py View on Github external
def test_docker_builder_defaults():
    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))

    assert builder.params.tags == ['foo', 'bar']
github cekit / cekit / tests / test_builder.py View on Github external
def test_docker_build_default_tags(mocker):
    builder = DockerBuilder(Map({'target': 'something'}))

    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
    docker_client = docker_client_class.return_value
    mock_generator = mocker.patch.object(builder, 'generator')
    mock_generator.get_tags.return_value = ["image/test:1.0", "image/test:latest"]
    mocker.patch.object(builder, '_build_with_docker')
    mocker.patch.object(builder, '_squash', return_value="112321312imageID")

    builder._build_with_docker.return_value = "1654234sdf56"

    builder.run()

    builder._build_with_docker.assert_called_once_with(docker_client)

    tag_calls = [mocker.call('112321312imageID', 'image/test', tag='1.0'),
                 mocker.call('112321312imageID', 'image/test', tag='latest')]
github cekit / cekit / tests / test_unit_builder_docker.py View on Github external
def test_docker_tag(mocker):
    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))

    docker_client_mock = mocker.Mock()

    builder._tag(docker_client_mock, "image_id", ["image:latest", "host:5000/repo/image:tag"])

    assert len(docker_client_mock.tag.mock_calls) == 2

    docker_client_mock.tag.assert_has_calls([
        mocker.call("image_id", "image", tag="latest"),
        mocker.call("image_id", "host:5000/repo/image", tag="tag")
    ])
github cekit / cekit / cekit / builders / docker_builder.py View on Github external
def __init__(self, common_params, params):
        super(DockerBuilder, self).__init__('docker', common_params, params)