当前位置: 首页>>代码示例>>Python>>正文


Python errors.BuildError方法代码示例

本文整理汇总了Python中docker.errors.BuildError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.BuildError方法的具体用法?Python errors.BuildError怎么用?Python errors.BuildError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docker.errors的用法示例。


在下文中一共展示了errors.BuildError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _build_image

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import BuildError [as 别名]
def _build_image(self, context_dir, env: DockerEnv) -> docker.models.images.Image:
        tag = self.params.uri
        logger.debug('Building docker image %s from %s...', tag, context_dir)
        with env.daemon.client() as client:
            self.params.registry.login(client)

            if not self.force_overwrite:
                if self.params.exists(client):
                    raise ValueError(f'Image {tag} already exists at {self.params.registry}. '
                                     f'Change name or set force_overwrite=True.')

            else:
                self.params.delete(client)  # to avoid spawning dangling images
            try:
                image, logs = client.images.build(path=context_dir, tag=tag, rm=True)
                logger.info('Built docker image %s', tag)
                _print_docker_logs(logs)

                self.params.registry.push(client, tag)

                return image
            except errors.BuildError as e:
                _print_docker_logs(e.build_log, logging.ERROR)
                raise 
开发者ID:zyfra,项目名称:ebonite,代码行数:26,代码来源:build_context.py

示例2: _handle_log_stream

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import BuildError [as 别名]
def _handle_log_stream(self, stream):
        log_lines = []
        status = True
        try:
            for log_line in stream:
                new_log_lines, new_status = self._prepare_log_lines(log_line)
                log_lines += new_log_lines
                if not new_status:
                    status = new_status
                self._handle_logs(log_lines)
                log_lines = []
            if log_lines:
                self._handle_logs(log_lines)
        except (BuildError, APIError) as e:
            self._handle_logs(
                [
                    "{}: Could not build the image, encountered {}".format(
                        LogLevels.ERROR, e
                    )
                ]
            )
            return False

        return status 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:26,代码来源:builder.py

示例3: getImage

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import BuildError [as 别名]
def getImage(path, dockerfile, tag):
    '''Check if an image with a given tag exists. If not, build an image from
    using a given dockerfile in a given path, tagging it with a given tag.
    No extra side effects. Handles and reraises BuildError, TypeError, and
    APIError exceptions.
    '''
    image = getImageByTag(tag)

    if not image:
        # Build an Image using the dockerfile in the path
        try:
            image = client.images.build(
              path=path,
              dockerfile=dockerfile,
              tag=tag
            )
        except BuildError as exc:
            eprint("Failed to build docker image")
            raise exc
        except TypeError as exc:
            eprint("You must give a path to the build environemnt.")
            raise exc
        except APIError as exc:
            eprint("Unhandled error while building image", tag)
            raise exc

    return image 
开发者ID:hyperledger,项目名称:indy-node,代码行数:29,代码来源:indypool.py

示例4: docker_example_base_image

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import BuildError [as 别名]
def docker_example_base_image():
    mlflow_home = os.environ.get("MLFLOW_HOME", None)
    if not mlflow_home:
        raise Exception("MLFLOW_HOME environment variable is not set. Please set the variable to "
                        "point to your mlflow dev root.")
    with TempDir() as tmp:
        cwd = tmp.path()
        mlflow_dir = _copy_project(
            src_path=mlflow_home, dst_path=cwd)
        import shutil
        shutil.copy(os.path.join(TEST_DOCKER_PROJECT_DIR, "Dockerfile"), tmp.path("Dockerfile"))
        with open(tmp.path("Dockerfile"), "a") as f:
            f.write(("COPY {mlflow_dir} /opt/mlflow\n"
                     "RUN pip install -U -e /opt/mlflow\n").format(
                mlflow_dir=mlflow_dir))

        client = docker.from_env()
        try:
            client.images.build(tag='mlflow-docker-example', forcerm=True, nocache=True,
                                dockerfile='Dockerfile', path=cwd)
        except BuildError as build_error:
            for chunk in build_error.build_log:
                print(chunk)
            raise build_error
        except APIError as api_error:
            print(api_error.explanation)
            raise api_error 
开发者ID:mlflow,项目名称:mlflow,代码行数:29,代码来源:utils.py

示例5: stage

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import BuildError [as 别名]
def stage(self, startimage, newimage):
        """ Copies the file from source to target

        Args:
            startimage (str): name of the image to stage these files into
            newimage (str): name of the created image
        """
        client = utils.get_client()
        cprint(
            '  Copying file from "%s:/%s" \n                 to "%s://%s/"'
            % (self.sourceimage, self.sourcepath, startimage, self.destpath),
            "blue",
        )

        # copy build artifacts from the container if necessary
        cachedir = self._setcache(client)
        cacherelpath = os.path.relpath(cachedir, TMPDIR)

        # if cached file doesn't exist (presumably purged by OS), trigger it to be recreated
        if os.path.exists(cachedir) and not os.path.exists(
            os.path.join(cachedir, "content.tar")
        ):
            shutil.rmtree(cachedir)

        if not os.path.exists(cachedir):
            print(" * Creating cache at %s" % cacherelpath)
            container = client.containers.create(self.sourceimage)
            try:
                tarfile_stream, tarfile_stats = container.get_archive(self.sourcepath)
            except docker.errors.NotFound:
                raise errors.MissingFileError(
                    'Cannot copy file "%s" from image "%s" - it does not exist!'
                    % (self.sourcepath, self.sourceimage)
                )

            # write files to disk (would be nice to stream them, haven't gotten it to work)
            tempdir = tempfile.mkdtemp(dir=BUILD_TEMPDIR)
            with open(os.path.join(tempdir, "content.tar"), "wb") as localfile:
                for chunk in tarfile_stream:
                    localfile.write(chunk)
            os.mkdir(cachedir)
            os.rename(tempdir, cachedir)
        else:
            print("  Using cached files from %s" % cacherelpath)

        # write Dockerfile for the new image and then build it
        dockerfile = "FROM %s\nADD content.tar %s" % (startimage, self.destpath)
        with open(os.path.join(cachedir, "Dockerfile"), "w") as df:
            df.write(dockerfile)

        buildargs = dict(path=cachedir, tag=newimage, decode=True)
        utils.set_build_cachefrom(self.cache_from, buildargs, client)

        # Build and show logs
        stream = client.api.build(**buildargs)
        try:
            utils.stream_docker_logs(stream, newimage)
        except ValueError as e:
            raise errors.BuildError(dockerfile, e.args[0], build_args=buildargs) 
开发者ID:avirshup,项目名称:DockerMake,代码行数:61,代码来源:staging.py


注:本文中的docker.errors.BuildError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。