예제 #1
0
    def build_image_from_git(self, url, image, git_path=None, git_commit=None, copy_dockerfile_to=None,
                             stream=False, use_cache=False):
        """
        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 stream: bool, True returns generator, False returns str
        :param use_cache: bool, True if you want to use cache
        :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)
            df_path, df_dir = figure_out_dockerfile(temp_dir, git_path)
            if copy_dockerfile_to:  # TODO: pre build plugin
                shutil.copyfile(df_path, copy_dockerfile_to)
            response = self.build_image_from_path(df_dir, image, stream=stream, use_cache=use_cache)
        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, repr(ex))
        logger.info("build finished")
        return response
예제 #2
0
파일: core.py 프로젝트: pkgw/atomic-reactor
    def build_image_from_git(self, url, image, git_path=None, git_commit=None, copy_dockerfile_to=None,
                             stream=False, use_cache=False):
        """
        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 stream: bool, True returns generator, False returns str
        :param use_cache: bool, True if you want to use cache
        :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)
            df_path, df_dir = figure_out_dockerfile(temp_dir, git_path)
            if copy_dockerfile_to:  # TODO: pre build plugin
                shutil.copyfile(df_path, copy_dockerfile_to)
            response = self.build_image_from_path(df_dir, image, stream=stream, use_cache=use_cache)
        finally:
            try:
                shutil.rmtree(temp_dir)
            except (IOError, OSError) as ex:
                # no idea why this is happening
                logger.warning("Failed to remove dir '%s': %r", temp_dir, ex)
        logger.info("build finished")
        return response
예제 #3
0
 def get_dockerfile_path(self):
     # TODO: will we need figure_out_dockerfile as a separate method?
     return util.figure_out_dockerfile(self.path, self.dockerfile_path)
예제 #4
0
def test_figure_out_dockerfile(tmpdir):
    tmpdir_path = str(tmpdir.realpath())
    clone_git_repo(DOCKERFILE_GIT, tmpdir_path)
    path, dir = figure_out_dockerfile(tmpdir_path)
    assert os.path.isfile(path)
    assert os.path.isdir(dir)
예제 #5
0
 def get_dockerfile_path(self):
     # TODO: will we need figure_out_dockerfile as a separate method?
     return util.figure_out_dockerfile(self.path, self.dockerfile_path)
예제 #6
0
def test_figure_out_dockerfile(tmpdir):
    tmpdir_path = str(tmpdir.realpath())
    clone_git_repo(DOCKERFILE_GIT, tmpdir_path)
    path, dir = figure_out_dockerfile(tmpdir_path)
    assert os.path.isfile(path)
    assert os.path.isdir(dir)