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


Python dockerfile_parse.DockerfileParser方法代码示例

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


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

示例1: mock_workflow

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def mock_workflow(tmpdir):
    if MOCK:
        mock_docker()

    workflow = DockerBuildWorkflow('test-image', source=SOURCE)
    setattr(workflow, 'builder', X())
    flexmock(DockerfileParser, content='df_content')
    setattr(workflow.builder, 'get_built_image_info', flexmock())
    flexmock(workflow.builder, get_built_image_info={'Id': 'some'})
    setattr(workflow.builder, 'ensure_not_built', flexmock())
    flexmock(workflow.builder, ensure_not_built=None)
    setattr(workflow.builder, 'image_id', 'image-id')
    setattr(workflow.builder, 'source', flexmock(
        dockerfile_path='dockerfile-path',
        path='path',
        config=flexmock(image_build_method=None),
    ))
    setattr(workflow.builder, 'df_path', 'df_path')
    setattr(workflow.builder, 'image', flexmock())
    setattr(workflow.builder.image, 'to_str', lambda: 'image')
    setattr(workflow.builder, 'base_image', flexmock())
    setattr(workflow.builder.base_image, 'to_str', lambda: 'base-image')

    return workflow 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:26,代码来源:test_plugin.py

示例2: test_source_not_removed_for_exit_plugins

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_source_not_removed_for_exit_plugins():
    flexmock(DockerfileParser, content='df_content')
    this_file = inspect.getfile(PreRaises)
    mock_docker()
    fake_builder = MockInsideBuilder()
    flexmock(InsideBuilder).new_instances(fake_builder)
    watch_exit = Watcher()
    watch_buildstep = Watcher()
    workflow = DockerBuildWorkflow('test-image', source=SOURCE,
                                   exit_plugins=[{'name': 'uses_source',
                                                  'args': {
                                                      'watcher': watch_exit,
                                                  }}],
                                   buildstep_plugins=[{'name': 'buildstep_watched',
                                                       'args': {
                                                           'watcher': watch_buildstep,
                                                       }}],
                                   plugin_files=[this_file])

    workflow.build_docker_image()

    # Make sure that the plugin was actually run
    assert watch_exit.was_called() 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:25,代码来源:test_inner.py

示例3: test_failed_build

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_failed_build(workflow):
    cmd_output = "spam spam spam spam spam spam spam baked beans spam spam spam and spam\n"
    cmd_error = "Nobody expects the Spanish Inquisition!\n"
    ib_process = flexmock(
        stdout=StringIO(cmd_output + cmd_error),
        poll=lambda: True,
        returncode=1,
    )
    flexmock(subprocess).should_receive('Popen').and_return(ib_process)

    flexmock(DockerfileParser, content='df_content')
    fake_builder = MockInsideBuilder(image_id='abcde')
    flexmock(InsideBuilder).new_instances(fake_builder)
    with pytest.raises(PluginFailedException):
        workflow.build_docker_image()

    assert isinstance(workflow.build_result, BuildResult)
    assert workflow.build_result.is_failed()
    assert cmd_output in workflow.build_result.logs
    assert cmd_error in workflow.build_result.logs
    assert cmd_error in workflow.build_result.fail_reason
    assert workflow.build_result.skip_layer_squash is False 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:24,代码来源:test_imagebuilder.py

示例4: test_popen_cmd

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_popen_cmd(docker_tasker, workflow, image_id):
    """
    tests buildah build plugin working
    """
    flexmock(DockerfileParser, content='df_content')
    fake_builder = MockInsideBuilder(image_id=image_id)
    fake_builder.tasker = docker_tasker
    mock_docker_tasker(docker_tasker)
    flexmock(InsideBuilder).new_instances(fake_builder)

    cmd_output = "spam spam spam spam spam spam spam baked beans spam spam spam and spam"
    real_popen = subprocess.Popen
    flexmock(subprocess, Popen=lambda *_, **kw: real_popen(['echo', '-n', cmd_output], **kw))
    workflow.build_docker_image()

    assert isinstance(workflow.buildstep_result['buildah_bud'], BuildResult)
    assert workflow.build_result == workflow.buildstep_result['buildah_bud']
    assert not workflow.build_result.is_failed()
    assert workflow.build_result.image_id.startswith('sha256:')
    assert workflow.build_result.image_id.count(':') == 1
    assert workflow.build_result.skip_layer_squash
    assert len(workflow.exported_image_sequence) == 1
    assert cmd_output in workflow.build_result.logs 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:25,代码来源:test_buildah.py

示例5: test_dockerfileparser

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_dockerfileparser(self, dfparser, tmpdir):
        df_content = dedent("""\
            FROM fedora
            LABEL label={0}""".format(NON_ASCII))
        df_lines = ["FROM fedora\n", "LABEL label={0}".format(NON_ASCII)]

        dfparser.content = ""
        dfparser.content = df_content
        assert dfparser.content == df_content
        assert dfparser.lines == df_lines
        assert [isinstance(line, six.text_type) for line in dfparser.lines]

        dfparser.content = ""
        dfparser.lines = df_lines
        assert dfparser.content == df_content
        assert dfparser.lines == df_lines
        assert [isinstance(line, six.text_type) for line in dfparser.lines]

        dockerfile = os.path.join(str(tmpdir), 'Dockerfile')
        with open(dockerfile, 'wb') as fp:
            fp.write(df_content.encode('utf-8'))
        dfparser = DockerfileParser(dockerfile)
        assert dfparser.content == df_content
        assert dfparser.lines == df_lines
        assert [isinstance(line, six.text_type) for line in dfparser.lines] 
开发者ID:containerbuildsystem,项目名称:dockerfile-parse,代码行数:27,代码来源:test_parser.py

示例6: test_get_build_args

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_get_build_args(self, tmpdir):
        tmpdir_path = str(tmpdir.realpath())
        b_args = {"bar": "baz❤"}
        df1 = DockerfileParser(tmpdir_path, env_replace=True, build_args=b_args)
        df1.lines = [
            "ARG foo=\"baz❤\"\n",
            "ARG not=\"used\"\n",
            "FROM parent\n",
            "ARG foo\n",
            "ARG bar\n",
            "LABEL label=\"$foo $bar\"\n"
        ]

        # Even though we inherit an ARG, this .args count should only be for the
        # ARGs defined in *this* Dockerfile as we're parsing the Dockerfile and
        # the build_args is only to satisfy use of this build.
        assert len(df1.args) == 2
        assert df1.args.get('foo') == 'baz❤'
        assert df1.args.get('bar') == 'baz❤'
        assert len(df1.labels) == 1
        assert df1.labels.get('label') == 'baz❤ baz❤' 
开发者ID:containerbuildsystem,项目名称:dockerfile-parse,代码行数:23,代码来源:test_parser.py

示例7: test_get_parent_env

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_get_parent_env(self, tmpdir):
        tmpdir_path = str(tmpdir.realpath())
        p_env = {"bar": "baz❤"}
        df1 = DockerfileParser(tmpdir_path, env_replace=True, parent_env=p_env)
        df1.lines = [
            "FROM parent\n",
            "ENV foo=\"$bar\"\n",
            "LABEL label=\"$foo $bar\"\n"
        ]

        # Even though we inherit an ENV, this .envs count should only be for the
        # ENVs defined in *this* Dockerfile as we're parsing the Dockerfile and
        # the parent_env is only to satisfy use of inherited ENVs.
        assert len(df1.envs) == 1
        assert df1.envs.get('foo') == 'baz❤'
        assert len(df1.labels) == 1
        assert df1.labels.get('label') == 'baz❤ baz❤' 
开发者ID:containerbuildsystem,项目名称:dockerfile-parse,代码行数:19,代码来源:test_parser.py

示例8: test_context_structure_mixed_top_arg

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_context_structure_mixed_top_arg(self, tmpdir):
        dfp = DockerfileParser(
            str(tmpdir.realpath()),
            build_args={"version": "8", "key": "value❤"},
            env_replace=True)
        dfp.content = dedent("""\
            ARG image=centos
            ARG version=latest
            FROM $image:$version
            ARG image
            ARG key
            """)
        c = dfp.context_structure

        assert len(c) == 5
        assert c[0].get_values(context_type='ARG') == {"image": "centos"}
        assert c[1].get_values(context_type='ARG') == {"image": "centos", "version": "8"}
        assert c[2].get_values(context_type='ARG') == {}
        assert c[3].get_values(context_type='ARG') == {"image": "centos"}
        assert c[4].get_values(context_type='ARG') == {"image": "centos", "key": "value❤"} 
开发者ID:containerbuildsystem,项目名称:dockerfile-parse,代码行数:22,代码来源:test_parser.py

示例9: test_workflow_compat

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_workflow_compat(caplog):
    """
    Some of our plugins have changed from being run post-build to
    being run at exit. Let's test what happens when we try running an
    exit plugin as a post-build plugin.
    """
    flexmock(DockerfileParser, content='df_content')
    this_file = inspect.getfile(PreWatched)
    mock_docker()
    fake_builder = MockInsideBuilder()
    flexmock(InsideBuilder).new_instances(fake_builder)
    watch_exit = Watcher()
    watch_buildstep = Watcher()

    caplog.clear()

    workflow = DockerBuildWorkflow('test-image', source=MOCK_SOURCE,
                                   postbuild_plugins=[{'name': 'store_logs_to_file',
                                                       'args': {
                                                           'watcher': watch_exit
                                                       }}],

                                   buildstep_plugins=[{'name': 'buildstep_watched',
                                                       'args': {
                                                           'watcher': watch_buildstep
                                                       }}],
                                   plugin_files=[this_file])

    workflow.build_docker_image()
    assert watch_exit.was_called()
    for record in caplog.records:
        assert record.levelno != logging.ERROR 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:34,代码来源:test_inner.py

示例10: test_plugin_errors

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_plugin_errors(plugins, should_fail, should_log, caplog):
    """
    Try bad plugin configuration.
    """
    flexmock(DockerfileParser, content='df_content')
    flexmock(DockerApiPlugin).should_receive('run').and_return(DUMMY_BUILD_RESULT)
    this_file = inspect.getfile(PreRaises)
    mock_docker()
    fake_builder = MockInsideBuilder()
    flexmock(InsideBuilder).new_instances(fake_builder)

    caplog.clear()
    workflow = DockerBuildWorkflow('test-image', source=MOCK_SOURCE,
                                   plugin_files=[this_file],
                                   **plugins)

    # Find the 'watcher' parameter
    watchers = [conf.get('args', {}).get('watcher')
                for plugin in plugins.values()
                for conf in plugin]
    watcher = [x for x in watchers if x][0]

    if should_fail:
        with pytest.raises(PluginFailedException):
            workflow.build_docker_image()

        assert not watcher.was_called()
        assert workflow.plugins_errors
        assert all([is_string_type(plugin)
                    for plugin in workflow.plugins_errors])
        assert all([is_string_type(reason)
                    for reason in workflow.plugins_errors.values()])
    else:
        workflow.build_docker_image()
        assert watcher.was_called()
        assert not workflow.plugins_errors

    if should_log:
        assert any(record.levelno == logging.ERROR for record in caplog.records)
    else:
        assert all(record.levelno != logging.ERROR for record in caplog.records) 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:43,代码来源:test_inner.py

示例11: test_show_version

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_show_version(has_version, caplog):
    """
    Test atomic-reactor print version of osbs-client used to build the build json
    if available
    """
    VERSION = "1.0"
    flexmock(DockerfileParser, content='df_content')
    this_file = inspect.getfile(PreRaises)

    mock_docker()
    fake_builder = MockInsideBuilder()
    flexmock(InsideBuilder).new_instances(fake_builder)

    watch_buildstep = Watcher()

    caplog.clear()

    params = {
        'prebuild_plugins': [],
        'buildstep_plugins': [{'name': 'buildstep_watched',
                               'args': {'watcher': watch_buildstep}}],
        'prepublish_plugins': [],
        'postbuild_plugins': [],
        'exit_plugins': [],
        'plugin_files': [this_file],
    }
    if has_version:
        params['client_version'] = VERSION

    workflow = DockerBuildWorkflow('test-image', source=MOCK_SOURCE, **params)
    workflow.build_docker_image()
    expected_log_message = "build json was built by osbs-client {}".format(VERSION)
    assert any(
        expected_log_message in record.message
        for record in caplog.records
        if record.levelno == logging.DEBUG
    ) == has_version 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:39,代码来源:test_inner.py

示例12: test_popen_cmd

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_popen_cmd(docker_tasker, workflow, image_id):
    """
    tests imagebuilder build plugin working
    """
    flexmock(DockerfileParser, content='df_content')
    fake_builder = MockInsideBuilder(image_id=image_id)
    fake_builder.tasker = docker_tasker
    mock_docker_tasker(docker_tasker)
    flexmock(InsideBuilder).new_instances(fake_builder)

    real_popen = subprocess.Popen

    process_args = ['imagebuilder', '-t', fake_builder.image.to_str()]
    for argname, argval in fake_builder.buildargs.items():
        process_args.append('--build-arg')
        process_args.append('%s=%s' % (argname, argval))
    process_args.append(fake_builder.df_dir)

    flexmock(subprocess, Popen=lambda *args, **kw: real_popen(['echo', '-n', str(args)], **kw))
    workflow.build_docker_image()

    assert isinstance(workflow.buildstep_result['imagebuilder'], BuildResult)
    assert workflow.build_result == workflow.buildstep_result['imagebuilder']
    assert not workflow.build_result.is_failed()
    assert workflow.build_result.image_id.startswith('sha256:')
    assert workflow.build_result.image_id.count(':') == 1
    assert workflow.build_result.skip_layer_squash
    assert len(workflow.exported_image_sequence) == 1
    assert str((process_args, )) in workflow.build_result.logs 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:31,代码来源:test_imagebuilder.py

示例13: test_build

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def test_build(docker_tasker, workflow, is_failed, image_id):
    """
    tests docker build api plugin working
    """
    flexmock(DockerfileParser, content='df_content')
    mock_docker()
    fake_builder = MockInsideBuilder(image_id=image_id)
    fake_builder.tasker = docker_tasker
    mock_docker_tasker(docker_tasker)
    flexmock(InsideBuilder).new_instances(fake_builder)

    flexmock(CommandResult).should_receive('is_failed').and_return(is_failed)
    error = "error message"
    error_detail = "{u'message': u\"%s\"}" % error
    if is_failed:
        flexmock(CommandResult, error=error, error_detail=error_detail)
        with pytest.raises(PluginFailedException):
            workflow.build_docker_image()
    else:
        workflow.build_docker_image()

    assert isinstance(workflow.buildstep_result['docker_api'], BuildResult)
    assert workflow.build_result == workflow.buildstep_result['docker_api']
    assert workflow.build_result.is_failed() == is_failed

    if is_failed:
        assert workflow.build_result.fail_reason == error
        assert '\\' not in workflow.plugins_errors['docker_api']
        assert error in workflow.plugins_errors['docker_api']
    else:
        assert workflow.build_result.image_id.startswith('sha256:')
        assert workflow.build_result.image_id.count(':') == 1 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:34,代码来源:test_docker_api.py

示例14: __init__

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def __init__(self, target, **_):
        super().__init__()
        self.target_name = target
        logger.debug("Target is a dockerfile.")
        if isinstance(target, io.IOBase):
            logger.debug("Target is a dockerfile loaded from the file-like object.")
            self.instance = DockerfileParser(fileobj=target)
        else:
            self.instance = DockerfileParser(fileobj=open(target)) 
开发者ID:user-cont,项目名称:colin,代码行数:11,代码来源:target.py

示例15: bump_release

# 需要导入模块: import dockerfile_parse [as 别名]
# 或者: from dockerfile_parse import DockerfileParser [as 别名]
def bump_release(df_path, branch):
    parser = DockerfileParser(df_path)
    oldrelease = parser.labels["Release"]
    if not oldrelease:
        raise RuntimeError("Dockerfile has no Release label")

    m = re.match(r"(.*\D)?(\d+)", oldrelease)
    if not m:
        raise RuntimeError("Release does not end with number")

    num = int(m.group(2))
    newrelease = "{}{:03d}".format(m.group(1), num+1)

    parser.labels["Release"] = newrelease
    return newrelease 
开发者ID:containerbuildsystem,项目名称:osbs-client,代码行数:17,代码来源:throughput-test-harness.py


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