How to use the cekit.errors.CekitError 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 / cekit / tools.py View on Github external
for directory in path:
            file_path = os.path.join(os.path.normcase(directory), executable)

            if self._is_program(file_path):
                LOGGER.debug("CEKit dependency '{}' provided via the '{}' executable.".format(
                    dependency, file_path))
                return

        msg = "CEKit dependency: '{}' was not found, please provide the '{}' executable.".format(
            dependency, executable)

        if package:
            msg += " To satisfy this requirement you can install the '{}' package.".format(package)

        raise CekitError(msg)
github cekit / cekit / cekit / cli.py View on Github external
if builder == 'docker':
        # import is delayed until here to prevent circular import error
        from cekit.builders.docker_builder import DockerBuilder as builder_impl
        LOGGER.info("Using Docker builder to build the image")
    elif builder == 'osbs':
        # import is delayed until here to prevent circular import error
        from cekit.builders.osbs import OSBSBuilder as builder_impl
        LOGGER.info("Using OSBS builder to build the image")
    elif builder == 'podman':
        from cekit.builders.podman import PodmanBuilder as builder_impl
        LOGGER.info("Using Podman builder to build the image")
    elif builder == 'buildah':
        from cekit.builders.buildah import BuildahBuilder as builder_impl
        LOGGER.info("Using Buildah builder to build the image")
    else:
        raise CekitError("Builder engine {} is not supported".format(builder))

    run_command(ctx, builder_impl)
github cekit / cekit / cekit / builders / docker_builder.py View on Github external
LOGGER.error(
            "Could not connect to the Docker daemon at '{}', please make sure the Docker "
            "daemon is running.".format(client.base_url))

        if client.base_url.startswith('unix'):
            LOGGER.error(
                "Please make sure the Docker socket has correct permissions.")

        if os.environ.get('DOCKER_HOST'):
            LOGGER.error("If Docker daemon is running, please make sure that you specified valid "
                         "parameters in the 'DOCKER_HOST' environment variable, examples: "
                         "'unix:///var/run/docker.sock', 'tcp://192.168.22.33:1234'. You may "
                         "also need to specify 'DOCKER_TLS_VERIFY', and 'DOCKER_CERT_PATH' "
                         "environment variables.")

        raise CekitError("Cannot connect to Docker daemon")
github cekit / cekit / cekit / builders / docker_builder.py View on Github external
else:
                raise CekitError(message, ex)

        except Exception as ex:
            msg = "Image build failed, see logs above."
            if len(docker_layer_ids) >= 2:
                LOGGER.error("You can look inside the failed image by running "
                             "'docker run --rm -ti {} bash'".format(docker_layer_ids[-1]))
            if "To enable Red Hat Subscription Management repositories:" in ' '.join(build_log) and \
                    not os.path.exists(os.path.join(self.target, 'image', 'repos')):
                msg = "Image build failed with a yum error and you don't " \
                    "have any yum repository configured, please check " \
                    "your image/module descriptor for proper repository " \
                    "definitions."

            raise CekitError(msg, ex)

        return docker_layer_ids[-1]
github cekit / cekit / cekit / builders / docker_builder.py View on Github external
docker_args['path'] = os.path.join(self.target, 'image')
        docker_args['pull'] = self.params.pull
        docker_args['rm'] = True
        docker_args['decode'] = True

        build_log = []
        docker_layer_ids = []

        try:
            stream = docker_client.build(**docker_args)

            for part in stream:
                # In case an error is returned, log the message and fail the build
                if 'errorDetail' in part:
                    error_message = part.get('errorDetail', {}).get('message', '')
                    raise CekitError("Image build failed: '{}'".format(error_message))
                elif 'stream' in part:
                    messages = part['stream']
                else:
                    # We actually expect only 'stream' here.
                    # If there is something different, we ignore it.
                    # It's safe to do so because if it would be an error, we would catch it
                    # earlier. Ignored logs are related to fetching/pulling/extracing
                    # of container images.
                    continue

                # This prevents polluting CEKit log with dowloading/extracting messages
                messages = ANSI_ESCAPE.sub('', messages).strip()

                # Python 2 compatibility
                if sys.version_info[0] == 2:
                    messages = messages.encode("utf-8", errors="ignore")
github cekit / cekit / cekit / descriptor / resource.py View on Github external
def guarded_copy(self, target):
        try:
            self._copy_impl(target)
        except Exception as ex:
            logger.warning("Cekit is not able to fetch resource '{}' automatically. "
                           "Please use cekit-cache command to add this artifact manually.".format(self.name))

            if self.description:
                logger.info(self.description)

            # exception is fatal we be logged before Cekit dies
            raise CekitError("Error copying resource: '%s'. See logs for more info."
                             % self.name, ex)

        if set(SUPPORTED_HASH_ALGORITHMS).intersection(self) and \
                not self.__verify(target):
            raise CekitError('Artifact checksum verification failed!')

        return target
github cekit / cekit / cekit / descriptor / base.py View on Github external
In a case of simple type values are appended.

    Args:
      list1, list2 - list to merge

    Returns merged list
    """
    for v2 in reversed(list2):
        if isinstance(v2, Descriptor):
            if v2 in list1:
                v1 = list1.pop(list1.index(v2))
                list1.insert(0, v1.merge(v2))
            else:
                list1.insert(0, v2)
        elif isinstance(v2, list):
            raise CekitError("Cannot merge list of lists")
        else:
            if v2 not in list1:
                list1.insert(0, v2)

    return list1
github cekit / cekit / cekit / builders / podman.py View on Github external
for tag in tags:
            cmd.extend(["-t", tag])

        LOGGER.info("Building container image...")

        cmd.append(os.path.join(self.target, 'image'))

        LOGGER.debug("Running Podman build: '{}'".format(" ".join(cmd)))

        try:
            subprocess.check_call(cmd)

            LOGGER.info("Image built and available under following tags: {}".format(", ".join(tags)))
        except:
            raise CekitError("Image build failed, see logs above.")
github cekit / cekit / cekit / builders / buildah.py View on Github external
for tag in tags:
            cmd.extend(["-t", tag])

        LOGGER.info("Building container image...")

        cmd.append(os.path.join(self.target, 'image'))

        LOGGER.debug("Running Buildah build: '{}'".format(" ".join(cmd)))

        try:
            subprocess.check_call(cmd)

            LOGGER.info("Image built and available under following tags: {}".format(", ".join(tags)))
        except:
            raise CekitError("Image build failed, see logs above.")
github cekit / cekit / cekit / descriptor / resource.py View on Github external
try:
            self._copy_impl(target)
        except Exception as ex:
            logger.warning("Cekit is not able to fetch resource '{}' automatically. "
                           "Please use cekit-cache command to add this artifact manually.".format(self.name))

            if self.description:
                logger.info(self.description)

            # exception is fatal we be logged before Cekit dies
            raise CekitError("Error copying resource: '%s'. See logs for more info."
                             % self.name, ex)

        if set(SUPPORTED_HASH_ALGORITHMS).intersection(self) and \
                not self.__verify(target):
            raise CekitError('Artifact checksum verification failed!')

        return target