Пример #1
0
def test_figure_out_build_file(tmpdir, repository, expected_path):
    tmpdir_path = str(tmpdir.realpath())
    clone_git_repo(repository, tmpdir_path)
    path, dir = figure_out_build_file(tmpdir_path)
    assert path == os.path.join(tmpdir_path, expected_path)
    assert os.path.isfile(path)
    assert os.path.isdir(dir)
Пример #2
0
def test_figure_out_build_file(tmpdir, contents, local_path, expected_path, expected_exception):
    tmpdir_path = str(tmpdir.realpath())
    for path, path_contents in contents.items():
        fullpath = os.path.join(tmpdir_path, path)
        d = os.path.dirname(fullpath)
        if not os.path.exists(d):
            os.makedirs(d)
        with open(fullpath, "w") as f:
            f.write(path_contents)

    if expected_exception is None:
        path, dir = figure_out_build_file(tmpdir_path, local_path=local_path)
        assert path == os.path.join(tmpdir_path, expected_path)
        assert os.path.isfile(path)
        assert os.path.isdir(dir)
    else:
        with pytest.raises(Exception) as e:
            figure_out_build_file(tmpdir_path, local_path=local_path)
        print(e)
        assert expected_exception in str(e)
Пример #3
0
    def build_image_from_git(self,
                             url,
                             image,
                             git_path=None,
                             git_commit=None,
                             copy_dockerfile_to=None,
                             use_cache=False,
                             buildargs=None):
        """
        build image from provided url and tag it

        this operation is asynchronous and you should consume returned generator in order to wait
        for build to finish

        :param url: str
        :param image: ImageName, name of the resulting image
        :param git_path: str, path to dockerfile within gitrepo
        :param copy_dockerfile_to: str, copy dockerfile to provided path
        :param use_cache: bool, True if you want to use cache
        :param buildargs: dict, build-time variables --build-arg
        :return: generator
        """
        logger.info(
            "building image '%s' from git repo '%s' specified as URL '%s'",
            image, git_path, url)
        logger.info("will copy Dockerfile to '%s'", copy_dockerfile_to)
        temp_dir = tempfile.mkdtemp()
        response = None
        try:
            clone_git_repo(url, temp_dir, git_commit)
            build_file_path, build_file_dir = figure_out_build_file(
                temp_dir, git_path)
            if copy_dockerfile_to:  # TODO: pre build plugin
                shutil.copyfile(build_file_path, copy_dockerfile_to)
            response = self.build_image_from_path(build_file_dir,
                                                  image,
                                                  use_cache=use_cache,
                                                  buildargs=buildargs)
        finally:
            try:
                shutil.rmtree(temp_dir)
            except (IOError, OSError) as ex:
                # no idea why this is happening
                logger.warning("Failed to remove dir '%s': %s", temp_dir, ex)
        logger.info("build finished")
        return response
Пример #4
0
 def get_build_file_path(self):
     # TODO: will we need figure_out_build_file as a separate method?
     return util.figure_out_build_file(self.path, self.dockerfile_path)
Пример #5
0
 def get_build_file_path(self):
     return util.figure_out_build_file(self.path, self.dockerfile_path)