コード例 #1
0
ファイル: build.py プロジェクト: zedge/docker-rpmbuild
def main():
    args = docopt(__doc__, version='Docker Packager 0.0.1')
    config, path_to_config = get_parsed_config(args)
    context = get_context(args, config, path_to_config)

    try:
        with Packager(context,  get_docker_config(args, config)) as p:
            for line in p.build_image():
                parsed = json.loads(line.decode('utf-8'))
                if 'stream' not in parsed:
                    log(parsed)
                    if 'error' in parsed:
                        if 'errorDetail' in parsed:
                            raise PackagerException(
                                "{0} : {1}".format(
                                    parsed['error'],
                                    parsed['errorDetail']))
                        raise PackagerException(parsed['error'])
                else:
                    log(parsed['stream'].strip())

            container, logs = p.build_package()

            for line in logs:
                log(line.decode('utf-8').strip())

            for path in p.export_package(args['--output']):
                log('Wrote: %s' % path)

    except PackagerException:
        log('Container build failed!', file=sys.stderr)
        sys.exit(1)
コード例 #2
0
    def test_get_docker_config_gets_doctopt_timeout_when_provided_and_no_config_given(self):
        docopt_with_timeout_and_no_config = {
            '--config': None,
            '--define': [],
            '--docker-base_url': None,
            '--docker-timeout': 44,
            '--docker-version': None,
            '--output': '.',
            '--retrieve': True,
            '--source': [],
            '--sources-dir': 'SOURCES',
            '--spec': 'SPECS/foo.spec',
            '--srpm': None,
            '<image>': 'docker.example.net:5000/centos:7',
            'build': True,
            'rebuild': False
        }

        with mock.patch('rpmbuild.config.read_config') as read_config_mock:
            read_config_mock.return_value = defaultdict(None, {
                'version': '0.11'
            })

            config = get_docker_config(docopt_with_timeout_and_no_config)
            self.assertEqual(config.get('timeout'), 44)
コード例 #3
0
    def test_get_docker_config_insert_internal_default_if_no_timeout_is_given_either_as_docopt_argument_or_config(self):
        with mock.patch('rpmbuild.config.read_config') as read_config_mock:
            read_config_mock.return_value = defaultdict(None, {
                'version': '0.11'
            })

            config = get_docker_config(self.docopt_with_only_config_file_without_timeout)
            self.assertEqual(config.get('timeout'), int(DEFAULT_TIMEOUT))
コード例 #4
0
ファイル: config_test.py プロジェクト: norrs/docker-rpmbuild
    def test_get_docker_config_is_type_defaultdict(self):
        with mock.patch("rpmbuild.config.read_config") as read_config_mock:
            read_config_mock.return_value = defaultdict(None, {"timeout": 42, "version": "0.11"})

            with mock.patch("os.path.exists") as exists:
                exists.return_value = True
                config = get_docker_config(self.docopt_with_only_config_file_without_timeout)

            self.assertIsInstance(config, defaultdict, "{0} file returns non defaultdict!".format(config))
            read_config_mock.assert_called_with(self.config_file)
コード例 #5
0
    def test_get_docker_config_is_type_defaultdict(self):
        with mock.patch('rpmbuild.config.read_config') as read_config_mock:
            read_config_mock.return_value = defaultdict(None, {
                'timeout': 42,
                'version': '0.11'
            })

            with mock.patch('os.path.exists') as exists:
                exists.return_value = True
                config = get_docker_config(self.docopt_with_only_config_file_without_timeout)

            self.assert_(isinstance(config, defaultdict),
                '{0} file returns non defaultdict!'.format(config))
            read_config_mock.assert_called_with(self.config_file)
コード例 #6
0
ファイル: build.py プロジェクト: shawnsi/docker-rpmbuild
def main():
    args = docopt(__doc__, version='Docker Packager 0.0.1')

    if args['build']:
        context = PackagerContext(
            args['<image>'],
            defines=args['--define'],
            sources=args['--source'],
            sources_dir=args['--sources-dir'],
            spec=args['--spec'],
            macrofiles=args['--macrofile'],
            retrieve=args['--retrieve'],
        )

    if args['rebuild']:
        context = PackagerContext(
            args['<image>'],
            srpm=args['--srpm']
        )

    try:
        with Packager(context,  get_docker_config(args)) as p:
            for line in p.build_image():
                if is_py26:
                    parsed = json.loads(line.decode('UTF-8'))
                else:
                    parsed = json.loads(line.decode(encoding='UTF-8'))
                if 'stream' not in parsed:
                    print(parsed)
                else:
                    print(parsed['stream'].strip())

            container, logs = p.build_package()

            for line in logs:
                if is_py26:
                    print(line.decode('UTF-8').strip())
                else:
                    print(line.decode(encoding='UTF-8').strip())

            for path in p.export_package(args['--output']):
                print('Wrote: %s' % path)

    except PackagerException:
        print('Container build failed!', file=sys.stderr)
        sys.exit(1)
コード例 #7
0
def main():
    args = docopt(__doc__, version='Docker Packager 0.0.1')

    if args['build']:
        context = PackagerContext(
            args['<image>'],
            defines=args['--define'],
            sources=args['--source'],
            sources_dir=args['--sources-dir'],
            spec=args['--spec'],
            macrofiles=args['--macrofile'],
            retrieve=args['--retrieve'],
        )

    if args['rebuild']:
        context = PackagerContext(args['<image>'], srpm=args['--srpm'])

    try:
        with Packager(context, get_docker_config(args)) as p:
            for line in p.build_image():
                if is_py26:
                    parsed = json.loads(line.decode('UTF-8'))
                else:
                    parsed = json.loads(line.decode(encoding='UTF-8'))
                if 'stream' not in parsed:
                    print(parsed)
                else:
                    print(parsed['stream'].strip())

            container, logs = p.build_package()

            for line in logs:
                if is_py26:
                    print(line.decode('UTF-8').strip())
                else:
                    print(line.decode(encoding='UTF-8').strip())

            for path in p.export_package(args['--output']):
                print('Wrote: %s' % path)

    except PackagerException:
        print('Container build failed!', file=sys.stderr)
        sys.exit(1)
コード例 #8
0
ファイル: config_test.py プロジェクト: norrs/docker-rpmbuild
    def test_get_docker_config_gets_overriden_timeout_provided_in_docopts_over_config_files_timeout(self):
        docopt_with_timeout_and_with_config = {
            "--config": "/tmp/foo",
            "--define": [],
            "--docker-base_url": None,
            "--docker-timeout": 48,
            "--docker-version": None,
            "--output": ".",
            "--retrieve": True,
            "--source": [],
            "--sources-dir": "SOURCES",
            "--spec": "SPECS/foo.spec",
            "--srpm": None,
            "<image>": "docker.example.net:5000/centos:7",
            "build": True,
            "rebuild": False,
        }
        with mock.patch("rpmbuild.config.read_config") as read_config_mock:
            read_config_mock.return_value = defaultdict(None, {"timeout": 41, "version": "0.11"})

            config = get_docker_config(docopt_with_timeout_and_with_config)
            self.assertEqual(config.get("timeout"), 48)