Exemplo n.º 1
0
    def configure(self):
        if self.args.verbose:
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)

        logger.debug("Running version %s", version)
        if 'dev' in version or 'rc' in version:
            logger.warning(
                "You are running unreleased development version of Cekit, "
                "use it only at your own risk!")

        config.configure(
            self.args.config, {
                'redhat': self.args.redhat,
                'work_dir': self.args.work_dir,
                'addhelp': self.args.addhelp,
                'package_manager': self.args.package_manager
            })

        cleanup(self.args.target)

        # We need to construct Generator first, because we need overrides
        # merged in
        params = {
            'addhelp': config.get('doc', 'addhelp'),
            'redhat': config.get('common', 'redhat'),
            'help_template': config.get('doc', 'help_template'),
            'package_manager': config.get('common', 'package_manager')
        }

        self.generator = Generator(self.args.descriptor, self.args.target,
                                   self.args.build_engine, self.args.overrides,
                                   params)
Exemplo n.º 2
0
def prepare_generator(target, desc_part, desc_type="image", engine="docker"):
    # create basic descriptor

    desc = basic_config.copy()
    desc.update(desc_part)

    image = Module(desc, '/tmp/', '/tmp')

    generator = Generator.__new__(Generator, image, target, engine, None, {})
    generator.image = image
    generator.target = target
    generator._type = 'docker'
    generator._wipe = False
    generator._params = {}
    generator._fetch_repos = False
    return generator
Exemplo n.º 3
0
    def prepare(self):
        self.generator = Generator(self.params.descriptor, self.params.target,
                                   self.params.overrides)

        # Handle dependencies for selected generator, if any
        LOGGER.debug("Checking CEKit generate dependencies...")
        self.dependency_handler.handle(self.generator, self.params)

        self.generator.init()

        # TODO: investigate if we can improve handling different schema versions
        self.collected = self.test_collector.collect(
            self.generator.image.get('schema_version'), self.params.steps_url)

        if self.collected:
            # Handle test dependencies, if any
            LOGGER.debug("Checking CEKit test collector dependencies...")
            self.dependency_handler.handle(self.test_collector, self.params)
            LOGGER.debug("Checking CEKit test runner dependencies...")
            self.dependency_handler.handle(self.test_runner, self.params)
Exemplo n.º 4
0
def test_issue_322(tmpdir):
    """tests a particular inheritance issue reported as GitHub issue #322"""
    target_dir = str(tmpdir.mkdir('target'))
    artifact_dir = str(tmpdir.mkdir('artifacts'))
    clone_dir = str(tmpdir.mkdir('clone'))

    descriptor = yaml.load(open("tests/issue_322/image.yaml").read())
    image = Module(descriptor=descriptor,
                   path="tests/issue_322",
                   artifact_dir=artifact_dir)
    image.fetch_dependencies(clone_dir)

    generator = Generator.__new__(Generator,
                                  descriptor_path="tests/issue_322",
                                  target=target_dir,
                                  builder="docker",
                                  overrides=None,
                                  params={})
    generator.image = image
    generator.target = target_dir
    generator.prepare_modules()
Exemplo n.º 5
0
    def configure(self):
        if self.args.verbose:
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)

        logger.debug("Running version %s", version)
        if 'dev' in version or 'rc' in version:
            logger.warning(
                "You are running unreleased development version of Cekit, "
                "use it only at your own risk!")

        tools.cfg = tools.get_cfg(self.args.config)
        tools.cleanup(self.args.target)

        if self.args.redhat:
            tools.cfg['common']['redhat'] = True
        if self.args.work_dir:
            tools.cfg['common']['work_dir'] = self.args.work_dir

        addhelp = tools.cfg.get('doc', {}).get('addhelp', False)
        if bool == type(self.args.addhelp):
            addhelp = self.args.addhelp

        # We need to construct Generator first, because we need overrides
        # merged in
        params = {
            'addhelp': addhelp,
            'redhat': tools.cfg['common']['redhat'],
        }

        if 'help_template' in tools.cfg.get('doc', {}):
            params['help_template'] = tools.cfg['doc']['help_template']

        self.generator = Generator(self.args.descriptor, self.args.target,
                                   self.args.build_engine, self.args.overrides,
                                   params)
Exemplo n.º 6
0
Arquivo: cli.py Projeto: crobby/cekit
    def run(self):
        if self.args.verbose:
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)

        logger.debug("Running version %s", version)
        if 'dev' in version:
            logger.warning("You are running unreleased development version of Cekit, "
                           "use it only at your own risk!")

        try:
            tools.cfg = tools.get_cfg(self.args.config)
            tools.cleanup(self.args.target)

            if self.args.redhat:
                tools.cfg['common']['redhat'] = True
            if self.args.work_dir:
                tools.cfg['common']['work_dir'] = self.args.work_dir

            # We need to construct Generator first, because we need overrides
            # merged in
            params = {'redhat': tools.cfg['common']['redhat']}
            generator = Generator(self.args.descriptor,
                                  self.args.target,
                                  self.args.build_engine,
                                  self.args.overrides,
                                  params)

            # Now we can fetch repositories of modules (we have all overrides)
            get_dependencies(generator.image,
                             os.path.join(self.args.target, 'repo'))

            # We have all overrided repo fetch so we can discover modules
            # and process its dependency trees
            discover_modules(os.path.join(self.args.target, 'repo'))

            # we run generate for every possible command
            if self.args.commands:
                generator.prepare_modules()
                generator.prepare_repositories()
                generator.prepare_artifacts()
                if self.args.build_tech_preview:
                    generator.generate_tech_preview()
                generator.image.write(os.path.join(self.args.target, 'image.yaml'))
                generator.render_dockerfile()

                # if tags are not specified on command line we take them from image descriptor
                if not self.args.tags:
                    self.args.tags = generator.get_tags()

            if 'build' in self.args.commands:
                params = {'user': self.args.build_osbs_user,
                          'nowait': self.args.build_osbs_nowait,
                          'stage': self.args.build_osbs_stage,
                          'release': self.args.build_osbs_release,
                          'tags': self.args.tags,
                          'pull': self.args.build_pull,
                          'redhat': tools.cfg['common']['redhat'],
                          'target': self.args.build_osbs_target
                          }

                builder = Builder(self.args.build_engine,
                                  self.args.target,
                                  params)
                builder.prepare(generator.image)
                builder.build()

            if 'test' in self.args.commands:

                test_tags = [generator.get_tags()[0]]
                # if wip is specifed set tags to @wip
                if self.args.test_wip:
                    test_tags = ['@wip']

                # at first we collect tests
                tc = TestCollector(os.path.dirname(self.args.descriptor),
                                   self.args.target)

                # we run the test only if we collect any
                if tc.collect(generator.image.get('schema_version'), self.args.test_steps_url):
                    runner = TestRunner(self.args.target)
                    runner.run(self.args.tags[0], test_tags)
                else:
                    logger.warning("No test collected, test can't be run.")

            logger.info("Finished!")
            sys.exit(0)
        except KeyboardInterrupt as e:
            pass
        except CekitError as e:
            if self.args.verbose:
                logger.exception(e)
            else:
                logger.error(str(e))
            sys.exit(1)