def test_hostdocker_build(caplog, source_params):
    if MOCK:
        mock_docker()

    image_name = ImageName(repo="atomic-reactor-test-ssh-image")
    remote_image = image_name.copy()
    remote_image.registry = LOCALHOST_REGISTRY
    m = DockerhostBuildManager("buildroot-dh-fedora", {
        "source": source_params,
        "image": remote_image.to_str(),
        "parent_registry": LOCALHOST_REGISTRY,  # faster
        "target_registries_insecure": True,
        "parent_registry_insecure": True,
    })
    results = m.build()
    dt = DockerTasker()
    dt.pull_image(remote_image, insecure=True)

    if source_params['provider'] == 'path':
        assert_source_from_path_mounted_ok(caplog, m.temp_dir)

    assert len(results.build_logs) > 0
    #assert re.search(r'build json mounted in container .+"uri": %s' %
    #        os.path.join(dconstants.CONTAINER_SHARE_PATH, 'source'))
    # assert isinstance(results.built_img_inspect, dict)
    # assert len(results.built_img_inspect.items()) > 0
    # assert isinstance(results.built_img_info, dict)
    # assert len(results.built_img_info.items()) > 0
    # assert isinstance(results.base_img_info, dict)
    # assert len(results.base_img_info.items()) > 0
    # assert len(results.base_plugins_output) > 0
    # assert len(results.built_img_plugins_output) > 0
    dt.remove_container(results.container_id)
    dt.remove_image(remote_image)
def test_hostdocker_error_build(source_params):
    if MOCK:
        mock_docker(wait_should_fail=True)

    image_name = TEST_IMAGE
    m = DockerhostBuildManager(
        "buildroot-dh-fedora",
        {
            "source": {
                "provider": "git",
                "uri": DOCKERFILE_GIT,
                "provider_params": {
                    "git_commit": "error-build"
                }
            },
            "image": image_name,
            "parent_registry": LOCALHOST_REGISTRY,  # faster
            "target_registries_insecure": True,
            "parent_registry_insecure": True,
        })
    results = m.build()
    dt = DockerTasker()
    assert len(results.build_logs) > 0
    assert results.return_code != 0
    dt.remove_container(results.container_id)
Beispiel #3
0
def build_image_using_hosts_docker(build_image,
                                   source,
                                   image,
                                   target_registries=None,
                                   push_buildroot_to=None,
                                   target_registries_insecure=False,
                                   dont_pull_base_image=False,
                                   **kwargs):
    """
    build image from provided dockerfile (specified by `source`) in privileged container
    using docker from host

    :param build_image: str, image where target image should be built
    :param source: dict, where/how to get source code to put in image
    :param image: str, tag for built image ([registry/]image_name[:tag])
    :param target_registries: list of str, list of registries to push image to (might change in
                              future)
    :param push_buildroot_to: str, repository where buildroot should be pushed
    :param target_registries_insecure: bool, allow connecting to target registries over plain http
    :param dont_pull_base_image: bool, don't pull or update base image specified in dockerfile

    :return: BuildResults
    """
    build_json = _prepare_build_json(image, source, target_registries,
                                     target_registries_insecure,
                                     dont_pull_base_image, **kwargs)
    m = DockerhostBuildManager(build_image, build_json)
    build_response = m.build()
    if push_buildroot_to:
        m.commit_buildroot()
        m.push_buildroot(push_buildroot_to)
    return build_response
def test_hostdocker_error_build(source_params):
    if MOCK:
        mock_docker(wait_should_fail=True)

    image_name = TEST_IMAGE
    m = DockerhostBuildManager(
        "buildroot-dh-fedora",
        {
            "source": {"provider": "git", "uri": DOCKERFILE_GIT, "provider_params": {"git_commit": "error-build"}},
            "image": image_name,
            "parent_registry": LOCALHOST_REGISTRY,  # faster
            "target_registries_insecure": True,
            "parent_registry_insecure": True,
        },
    )
    results = m.build()
    dt = DockerTasker()
    assert len(results.build_logs) > 0
    assert results.return_code != 0
    dt.remove_container(results.container_id)
def test_hostdocker_build(caplog, source_params):
    if MOCK:
        mock_docker()

    image_name = ImageName(repo="atomic-reactor-test-ssh-image")
    remote_image = image_name.copy()
    remote_image.registry = LOCALHOST_REGISTRY
    m = DockerhostBuildManager("buildroot-dh-fedora", {
        "source": source_params,
        "image": remote_image.to_str(),
        "parent_registry": LOCALHOST_REGISTRY,  # faster
        "target_registries_insecure": True,
        "parent_registry_insecure": True,
    })
    results = m.build()
    dt = DockerTasker()
    dt.pull_image(remote_image, insecure=True)

    assert len(results.build_logs) > 0
    dt.remove_container(results.container_id)
    dt.remove_image(remote_image)
def test_hostdocker_build(caplog, source_params):
    if MOCK:
        mock_docker()

    image_name = ImageName(repo="atomic-reactor-test-ssh-image")
    remote_image = image_name.copy()
    remote_image.registry = LOCALHOST_REGISTRY
    m = DockerhostBuildManager("buildroot-dh-fedora", {
        "source": source_params,
        "image": remote_image.to_str(),
        "parent_registry": LOCALHOST_REGISTRY,  # faster
        "target_registries_insecure": True,
        "parent_registry_insecure": True,
    })
    results = m.build()
    dt = DockerTasker()
    dt.pull_image(remote_image, insecure=True)

    assert len(results.build_logs) > 0
    dt.remove_container(results.container_id)
    dt.remove_image(remote_image)
Beispiel #7
0
def build_image_using_hosts_docker(build_image, source, image,
        parent_registry=None, target_registries=None, push_buildroot_to=None,
        parent_registry_insecure=False, target_registries_insecure=False,
        dont_pull_base_image=False, **kwargs):
    """
    build image from provided dockerfile (specified by `source`) in privileged container
    using docker from host

    :param build_image: str, image where target image should be built
    :param source: dict, where/how to get source code to put in image
    :param image: str, tag for built image ([registry/]image_name[:tag])
    :param parent_registry: str, registry to pull base image from
    :param target_registries: list of str, list of registries to push image to (might change in future)
    :param push_buildroot_to: str, repository where buildroot should be pushed
    :param parent_registry_insecure: bool, allow connecting to parent registry over plain http
    :param target_registries_insecure: bool, allow connecting to target registries over plain http
    :param dont_pull_base_image: bool, don't pull or update base image specified in dockerfile

    :return: BuildResults
    """
    build_json = _prepare_build_json(image, source, parent_registry, target_registries,
                                     parent_registry_insecure, target_registries_insecure,
                                     dont_pull_base_image, **kwargs)
    m = DockerhostBuildManager(build_image, build_json)
    build_response = m.build()
    if push_buildroot_to:
        m.commit_buildroot()
        m.push_buildroot(push_buildroot_to)
    return build_response
def test_hostdocker_build(caplog, source_params):
    if MOCK:
        mock_docker()

    image_name = ImageName(repo="atomic-reactor-test-ssh-image")
    remote_image = image_name.copy()
    remote_image.registry = LOCALHOST_REGISTRY
    m = DockerhostBuildManager(
        "buildroot-dh-fedora",
        {
            "source": source_params,
            "image": remote_image.to_str(),
            "parent_registry": LOCALHOST_REGISTRY,  # faster
            "target_registries_insecure": True,
            "parent_registry_insecure": True,
        })
    results = m.build()
    dt = DockerTasker()
    dt.pull_image(remote_image, insecure=True)

    if source_params['provider'] == 'path':
        assert_source_from_path_mounted_ok(caplog, m.temp_dir)

    assert len(results.build_logs) > 0
    #assert re.search(r'build json mounted in container .+"uri": %s' %
    #        os.path.join(dconstants.CONTAINER_SHARE_PATH, 'source'))
    # assert isinstance(results.built_img_inspect, dict)
    # assert len(results.built_img_inspect.items()) > 0
    # assert isinstance(results.built_img_info, dict)
    # assert len(results.built_img_info.items()) > 0
    # assert isinstance(results.base_img_info, dict)
    # assert len(results.base_img_info.items()) > 0
    # assert len(results.base_plugins_output) > 0
    # assert len(results.built_img_plugins_output) > 0
    dt.remove_container(results.container_id)
    dt.remove_image(remote_image)