本文整理汇总了Python中atomic_reactor.inner.DockerBuildWorkflow.build_docker_image方法的典型用法代码示例。如果您正苦于以下问题:Python DockerBuildWorkflow.build_docker_image方法的具体用法?Python DockerBuildWorkflow.build_docker_image怎么用?Python DockerBuildWorkflow.build_docker_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic_reactor.inner.DockerBuildWorkflow
的用法示例。
在下文中一共展示了DockerBuildWorkflow.build_docker_image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_workflow_plugin_results
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_plugin_results():
"""
Verifies the results of plugins in different phases
are stored properly.
"""
this_file = inspect.getfile(PreRaises)
mock_docker()
fake_builder = MockInsideBuilder()
flexmock(InsideBuilder).new_instances(fake_builder)
prebuild_plugins = [{'name': 'pre_build_value'}]
postbuild_plugins = [{'name': 'post_build_value'}]
prepublish_plugins = [{'name': 'pre_publish_value'}]
exit_plugins = [{'name': 'exit_value'}]
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
prebuild_plugins=prebuild_plugins,
prepublish_plugins=prepublish_plugins,
postbuild_plugins=postbuild_plugins,
exit_plugins=exit_plugins,
plugin_files=[this_file])
workflow.build_docker_image()
assert workflow.prebuild_results == {'pre_build_value': 'pre_build_value_result'}
assert workflow.postbuild_results == {'post_build_value': 'post_build_value_result'}
assert workflow.prepub_results == {'pre_publish_value': 'pre_publish_value_result'}
assert workflow.exit_results == {'exit_value': 'exit_value_result'}
示例2: test_syntax_error
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_syntax_error():
"""
tests reporting of syntax errors
"""
flexmock(DockerfileParser, content='df_content')
mock_docker()
fake_builder = MockInsideBuilder()
def raise_exc(*args, **kwargs):
explanation = ("Syntax error - can't find = in \"CMD\". "
"Must be of the form: name=value")
http_error = requests.HTTPError('500 Server Error')
raise docker.errors.APIError(message='foo',
response=http_error,
explanation=explanation)
yield {}
fake_builder.tasker.build_image_from_path = raise_exc
flexmock(InsideBuilder).new_instances(fake_builder)
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image')
with pytest.raises(PluginFailedException):
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()
assert "Syntax error" in workflow.build_result.fail_reason
示例3: test_workflow_compat
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_compat(request):
"""
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.
"""
this_file = inspect.getfile(PreWatched)
mock_docker()
fake_builder = MockInsideBuilder()
flexmock(InsideBuilder).new_instances(fake_builder)
watch_exit = Watcher()
fake_logger = FakeLogger()
existing_logger = atomic_reactor.plugin.logger
def restore_logger():
atomic_reactor.plugin.logger = existing_logger
request.addfinalizer(restore_logger)
atomic_reactor.plugin.logger = fake_logger
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
postbuild_plugins=[{'name': 'store_logs_to_file',
'args': {
'watcher': watch_exit
}}],
plugin_files=[this_file])
workflow.build_docker_image()
assert watch_exit.was_called()
assert len(fake_logger.errors) > 0
示例4: test_workflow
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow():
"""
Test normal workflow.
"""
this_file = inspect.getfile(PreWatched)
mock_docker()
fake_builder = MockInsideBuilder()
flexmock(InsideBuilder).new_instances(fake_builder)
watch_pre = Watcher()
watch_prepub = Watcher()
watch_post = Watcher()
watch_exit = Watcher()
workflow = DockerBuildWorkflow(
MOCK_SOURCE,
"test-image",
prebuild_plugins=[{"name": "pre_watched", "args": {"watcher": watch_pre}}],
prepublish_plugins=[{"name": "prepub_watched", "args": {"watcher": watch_prepub}}],
postbuild_plugins=[{"name": "post_watched", "args": {"watcher": watch_post}}],
exit_plugins=[{"name": "exit_watched", "args": {"watcher": watch_exit}}],
plugin_files=[this_file],
)
workflow.build_docker_image()
assert watch_pre.was_called()
assert watch_prepub.was_called()
assert watch_post.was_called()
assert watch_exit.was_called()
示例5: test_plugin_errors
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_plugin_errors(plugins, should_fail, should_log):
"""
Try bad plugin configuration.
"""
this_file = inspect.getfile(PreRaises)
mock_docker()
fake_builder = MockInsideBuilder()
flexmock(InsideBuilder).new_instances(fake_builder)
fake_logger = FakeLogger()
atomic_reactor.plugin.logger = fake_logger
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
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()
else:
workflow.build_docker_image()
assert watcher.was_called()
if should_log:
assert len(fake_logger.errors) > 0
else:
assert len(fake_logger.errors) == 0
示例6: test_layer_sizes
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_layer_sizes():
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(SOURCE, 'test-image',
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()
expected = [
{'diff_id': u'sha256:diff_id1-oldest', 'size': 4},
{'diff_id': u'sha256:diff_id2', 'size': 3},
{'diff_id': u'sha256:diff_id3', 'size': 2},
{'diff_id': u'sha256:diff_id4-newest', 'size': 1}
]
assert workflow.layer_sizes == expected
示例7: test_autorebuild_stop_prevents_build
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_autorebuild_stop_prevents_build():
"""
test that a plugin that raises AutoRebuildCanceledException results in actually skipped build
"""
this_file = inspect.getfile(PreWatched)
mock_docker()
fake_builder = MockInsideBuilder()
flexmock(InsideBuilder).new_instances(fake_builder)
watch_prepub = Watcher()
watch_post = Watcher()
watch_exit = Watcher()
workflow = DockerBuildWorkflow(
MOCK_SOURCE,
"test-image",
prebuild_plugins=[{"name": "stopstopstop", "args": {}}],
prepublish_plugins=[{"name": "prepub_watched", "args": {"watcher": watch_prepub}}],
postbuild_plugins=[{"name": "post_watched", "args": {"watcher": watch_post}}],
exit_plugins=[{"name": "exit_watched", "args": {"watcher": watch_exit}}],
plugin_files=[this_file],
)
with pytest.raises(AutoRebuildCanceledException):
workflow.build_docker_image()
assert not watch_prepub.was_called()
assert not watch_post.was_called()
assert watch_exit.was_called()
assert workflow.autorebuild_canceled == True
示例8: test_build
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_build(is_failed, image_id):
"""
tests docker build api plugin working
"""
flexmock(DockerfileParser, content='df_content')
mock_docker()
fake_builder = MockInsideBuilder(image_id=image_id)
flexmock(InsideBuilder).new_instances(fake_builder)
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image')
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
示例9: test_workflow_docker_build_error_reports
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_docker_build_error_reports(steps_to_fail, step_reported):
"""
Test if first error is reported properly. (i.e. exit plugins are not
hiding the original root cause)
"""
def exc_string(step):
return 'test_workflow_docker_build_error_reports.{}'.format(step)
def construct_watcher(step):
watcher = Watcher(raise_exc=Exception(exc_string(step)) if step in steps_to_fail else None)
return watcher
flexmock(DockerfileParser, content='df_content')
this_file = inspect.getfile(PreRaises)
mock_docker()
fake_builder = MockInsideBuilder(failed=True)
flexmock(InsideBuilder).new_instances(fake_builder)
watch_pre = construct_watcher('pre')
watch_buildstep = construct_watcher('buildstep')
watch_prepub = construct_watcher('prepub')
watch_post = construct_watcher('post')
watch_exit = construct_watcher('exit')
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
prebuild_plugins=[{'name': 'pre_watched',
'is_allowed_to_fail': False,
'args': {
'watcher': watch_pre
}}],
buildstep_plugins=[{'name': 'buildstep_watched',
'is_allowed_to_fail': False,
'args': {
'watcher': watch_buildstep,
}}],
prepublish_plugins=[{'name': 'prepub_watched',
'is_allowed_to_fail': False,
'args': {
'watcher': watch_prepub,
}}],
postbuild_plugins=[{'name': 'post_watched',
'is_allowed_to_fail': False,
'args': {
'watcher': watch_post
}}],
exit_plugins=[{'name': 'exit_watched',
'is_allowed_to_fail': False,
'args': {
'watcher': watch_exit
}}],
plugin_files=[this_file])
with pytest.raises(Exception) as exc:
workflow.build_docker_image()
assert exc_string(step_reported) in str(exc)
示例10: test_plugin_errors
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_plugin_errors(request, plugins, should_fail, should_log):
"""
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)
fake_logger = FakeLogger()
existing_logger = atomic_reactor.plugin.logger
def restore_logger():
atomic_reactor.plugin.logger = existing_logger
request.addfinalizer(restore_logger)
atomic_reactor.plugin.logger = fake_logger
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
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 len(fake_logger.errors) > 0
else:
assert len(fake_logger.errors) == 0
示例11: test_workflow_errors
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_errors():
"""
This is a test for what happens when plugins fail.
When a prebuild plugin fails, no postbuild plugins should run.
However, all the exit plugins should run.
"""
this_file = inspect.getfile(PreRaises)
mock_docker()
fake_builder = MockInsideBuilder()
flexmock(InsideBuilder).new_instances(fake_builder)
watch_pre = Watcher()
watch_post = Watcher()
watch_exit = Watcher()
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
prebuild_plugins=[{'name': 'pre_raises',
'args': {}},
{'name': 'pre_watched',
'args': {
'watcher': watch_pre
}}],
postbuild_plugins=[{'name': 'post_watched',
'args': {
'watcher': watch_post
}}],
exit_plugins=[{'name': 'exit_raises',
'args': {}
},
{'name': 'exit_watched',
'args': {
'watcher': watch_exit
}}],
plugin_files=[this_file])
with pytest.raises(PluginFailedException):
workflow.build_docker_image()
# A pre-build plugin caused the build to fail, so post-build
# plugins should not run.
assert not watch_post.was_called()
# But all exit plugins should run, even if one of them also raises
# an exception.
assert watch_exit.was_called()
# All plugins of the same type (e.g. pre-build) are run, even if
# one of them failed.
assert watch_pre.was_called()
示例12: test_workflow_base_images
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_base_images():
"""
Test workflow for base images
"""
flexmock(DockerfileParser, content='df_content')
this_file = inspect.getfile(PreWatched)
mock_docker()
fake_builder = MockInsideBuilder(is_base_image=True)
flexmock(InsideBuilder).new_instances(fake_builder)
watch_pre = Watcher()
watch_prepub = Watcher()
watch_buildstep = Watcher()
watch_post = Watcher()
watch_exit = Watcher()
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
prebuild_plugins=[{'name': 'pre_watched',
'args': {
'watcher': watch_pre
}}],
buildstep_plugins=[{'name': 'buildstep_watched',
'args': {
'watcher': watch_buildstep
}}],
prepublish_plugins=[{'name': 'prepub_watched',
'args': {
'watcher': watch_prepub,
}}],
postbuild_plugins=[{'name': 'post_watched',
'args': {
'watcher': watch_post
}}],
exit_plugins=[{'name': 'exit_watched',
'args': {
'watcher': watch_exit
}}],
plugin_files=[this_file])
workflow.build_docker_image()
assert watch_pre.was_called()
assert watch_prepub.was_called()
assert watch_buildstep.was_called()
assert watch_post.was_called()
assert watch_exit.was_called()
with pytest.raises(KeyError):
assert workflow.base_image_inspect
示例13: build_image_here
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def build_image_here(source, image,
parent_registry=None, target_registries=None, parent_registry_insecure=False,
target_registries_insecure=False, dont_pull_base_image=False, **kwargs):
"""
build image from provided dockerfile (specified by `source`) in current environment
:param source: dict, where/how to get source code to put in image
:param image: str, tag for built image ([registry/]image_name[:tag])
:param parent_registry: str, registry to pull base image from
:param target_registries: list of str, list of registries to push image to (might change in future)
:param parent_registry_insecure: bool, allow connecting to parent registry over plain http
:param target_registries_insecure: bool, allow connecting to target registries over plain http
:param dont_pull_base_image: bool, don't pull or update base image specified in dockerfile
:return: BuildResults
"""
build_json = {
"image": image,
"source": source,
"parent_registry": parent_registry,
"target_registries": target_registries,
"parent_registry_insecure": parent_registry_insecure,
"target_registries_insecure": target_registries_insecure,
"dont_pull_base_image": dont_pull_base_image,
}
build_json.update(kwargs)
m = DockerBuildWorkflow(**build_json)
return m.build_docker_image()
示例14: test_workflow_docker_build_error
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_docker_build_error():
"""
This is a test for what happens when the docker build fails.
"""
this_file = inspect.getfile(PreRaises)
mock_docker()
fake_builder = MockInsideBuilder(failed=True)
flexmock(InsideBuilder).new_instances(fake_builder)
watch_prepub = Watcher()
watch_post = Watcher()
watch_exit = Watcher()
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
prepublish_plugins=[{'name': 'prepub_watched',
'args': {
'watcher': watch_prepub,
}}],
postbuild_plugins=[{'name': 'post_watched',
'args': {
'watcher': watch_post
}}],
exit_plugins=[{'name': 'exit_watched',
'args': {
'watcher': watch_exit
}}],
plugin_files=[this_file])
assert workflow.build_docker_image().is_failed()
# No subsequent build phases should have run except 'exit'
assert not watch_prepub.was_called()
assert not watch_post.was_called()
assert watch_exit.was_called()
示例15: test_workflow_docker_build_error
# 需要导入模块: from atomic_reactor.inner import DockerBuildWorkflow [as 别名]
# 或者: from atomic_reactor.inner.DockerBuildWorkflow import build_docker_image [as 别名]
def test_workflow_docker_build_error():
"""
This is a test for what happens when the docker build fails.
"""
flexmock(DockerfileParser, content='df_content')
this_file = inspect.getfile(PreRaises)
mock_docker()
fake_builder = MockInsideBuilder(failed=True)
flexmock(InsideBuilder).new_instances(fake_builder)
watch_pre = Watcher()
watch_buildstep = Watcher(raise_exc=Exception())
watch_prepub = Watcher()
watch_post = Watcher()
watch_exit = Watcher()
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image',
prebuild_plugins=[{'name': 'pre_watched',
'args': {
'watcher': watch_pre
}}],
buildstep_plugins=[{'name': 'buildstep_watched',
'args': {
'watcher': watch_buildstep,
}}],
prepublish_plugins=[{'name': 'prepub_watched',
'args': {
'watcher': watch_prepub,
}}],
postbuild_plugins=[{'name': 'post_watched',
'args': {
'watcher': watch_post
}}],
exit_plugins=[{'name': 'exit_watched',
'args': {
'watcher': watch_exit
}}],
plugin_files=[this_file])
with pytest.raises(Exception):
workflow.build_docker_image()
# No subsequent build phases should have run except 'exit'
assert watch_pre.was_called()
assert watch_buildstep.was_called()
assert not watch_prepub.was_called()
assert not watch_post.was_called()
assert watch_exit.was_called()