Beispiel #1
0
 def test_module_discovery(self, mod, _):
     module.discover_modules('repo')
     mod.assert_called_with('dir/module.yaml')
Beispiel #2
0
    def run(self):
        parser = MyParser(description='Dockerfile generator tool',
                          formatter_class=argparse.RawDescriptionHelpFormatter)

        parser.add_argument('-v',
                            '--verbose',
                            action='store_true',
                            help='verbose output')

        parser.add_argument('--version',
                            action='version',
                            help='show version and exit',
                            version=version)

        build_group = parser.add_argument_group(
            'build', "Arguments valid for the 'build' target")

        build_group.add_argument('--build-engine',
                                 default='docker',
                                 choices=['docker', 'osbs'],
                                 help='an engine used to build the image.')

        build_group.add_argument(
            '--build-tag',
            dest='build_tags',
            action='append',
            help='tag to assign to the built image, can be used multiple times'
        )

        build_group.add_argument('--build-osbs-release',
                                 dest='build_osbs_release',
                                 action='store_true',
                                 help='execute OSBS release build')

        build_group.add_argument('--build-tech-preview',
                                 action='store_true',
                                 help='perform tech preview build')

        parser.add_argument('--overrides',
                            help='path to a file containing overrides')

        parser.add_argument(
            '--target',
            default="target",
            help="path to directory where to generate sources, \
                                default: 'target' directory in current working directory"
        )

        parser.add_argument(
            '--descriptor',
            default="image.yaml",
            help="path to image descriptor file, default: image.yaml")

        parser.add_argument('commands',
                            nargs='+',
                            choices=['generate', 'build'],
                            help="commands that should be executed, \
                                you can specify multiple commands")

        self.args = parser.parse_args()

        if self.args.verbose:
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)

        logger.debug("Running version %s", version)

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

            # We need to construct Generator first, because we need overrides
            # merged in
            generator = Generator(self.args.descriptor, self.args.target,
                                  self.args.overrides)

            # Now we can fetch repositories of modules (we have all overrides)
            get_dependencies(generator.descriptor,
                             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'))

            # First we need to prepare a builder environment (it can change default target)
            if 'build' in self.args.commands:
                # we need to create the builder before generate, because it needs
                # to prepare env
                builder = Builder(self.args.build_engine, self.args.target)
                # build contains implicit generate
                self.args.commands.append('generate')

            if 'generate' in self.args.commands:
                generator.prepare_modules()
                generator.prepare_repositories()
                generator.prepare_artifacts()
                if self.args.build_tech_preview:
                    generator.generate_tech_preview()
                generator.render_dockerfile()

            if 'build' in self.args.commands:
                builder.prepare(generator.descriptor)
                if not self.args.build_tags:
                    self.args.build_tags = generator.get_tags()
                builder.build(self.args)

            logger.info("Finished!")
        except KeyboardInterrupt as e:
            pass
        except ConcreateError as e:
            if self.args.verbose:
                logger.exception(e)
            else:
                logger.error(str(e))
            sys.exit(1)
Beispiel #3
0
 def test_module_is_added_to_modules(self, mod, _):
     module.modules = []
     module.discover_modules('repo')
     self.assertEqual(len(module.modules), 1)
     module.modules = []
Beispiel #4
0
    def run(self):
        if self.args.verbose:
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)

        logger.debug("Running version %s", version)

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

            # We need to construct Generator first, because we need overrides
            # merged in
            generator = Generator(self.args.descriptor, self.args.target,
                                  self.args.overrides)

            # 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
                }
                builder = Builder(self.args.build_engine, self.args.target,
                                  params)
                builder.prepare(generator.image)
                builder.build(self.args)

            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)

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