本文整理汇总了Python中atomic_reactor.core.DockerTasker.commit_container方法的典型用法代码示例。如果您正苦于以下问题:Python DockerTasker.commit_container方法的具体用法?Python DockerTasker.commit_container怎么用?Python DockerTasker.commit_container使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic_reactor.core.DockerTasker
的用法示例。
在下文中一共展示了DockerTasker.commit_container方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remove_image
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import commit_container [as 别名]
def test_remove_image(temp_image_name):
if MOCK:
mock_docker(inspect_should_fail=True)
t = DockerTasker()
container_id = t.run(input_image_name, command="id")
t.wait(container_id)
image_id = t.commit_container(container_id, image=temp_image_name)
try:
t.remove_container(container_id)
finally:
t.remove_image(image_id)
assert not t.image_exists(temp_image_name)
示例2: test_commit_container
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import commit_container [as 别名]
def test_commit_container(temp_image_name):
if MOCK:
mock_docker()
t = DockerTasker()
container_id = t.run(INPUT_IMAGE, command="id")
t.wait(container_id)
image_id = t.commit_container(container_id, message="test message", image=temp_image_name)
try:
assert t.image_exists(image_id)
finally:
t.remove_container(container_id)
t.remove_image(image_id)
示例3: BuildManager
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import commit_container [as 别名]
class BuildManager(BuilderStateMachine):
"""
initiates build and waits for it to finish, then it collects data
"""
def __init__(self, build_image, build_args):
BuilderStateMachine.__init__(self)
self.build_image = build_image
self.build_args = build_args
self.image = build_args['image']
self.uri = build_args['source']['uri']
self.temp_dir = None
# build image after build
self.buildroot_image_id = None
self.buildroot_image_name = None
self.dt = DockerTasker()
def _build(self, build_method):
"""
build image from provided build_args
:return: BuildResults
"""
logger.info("building image '%s'", self.image)
self._ensure_not_built()
self.temp_dir = tempfile.mkdtemp()
temp_path = os.path.join(self.temp_dir, BUILD_JSON)
try:
with open(temp_path, 'w') as build_json:
json.dump(self.build_args, build_json)
self.build_container_id = build_method(self.build_image, self.temp_dir)
try:
logs_gen = self.dt.logs(self.build_container_id, stream=True)
wait_for_command(logs_gen)
return_code = self.dt.wait(self.build_container_id)
except KeyboardInterrupt:
logger.info("killing build container on user's request")
self.dt.remove_container(self.build_container_id, force=True)
results = BuildResults()
results.return_code = 1
return results
else:
results = self._load_results(self.build_container_id)
results.return_code = return_code
return results
finally:
shutil.rmtree(self.temp_dir)
def _load_results(self, container_id):
"""
load results from recent build
:return: BuildResults
"""
if self.temp_dir:
dt = DockerTasker()
# FIXME: load results only when requested
# results_path = os.path.join(self.temp_dir, RESULTS_JSON)
# df_path = os.path.join(self.temp_dir, 'Dockerfile')
# try:
# with open(results_path, 'r') as results_fp:
# results = json.load(results_fp, cls=BuildResultsJSONDecoder)
# except (IOError, OSError) as ex:
# logger.error("Can't open results: '%s'", repr(ex))
# for l in self.dt.logs(self.build_container_id, stream=False):
# logger.debug(l.strip())
# raise RuntimeError("Can't open results: '%s'" % repr(ex))
# results.dockerfile = open(df_path, 'r').read()
results = BuildResults()
results.build_logs = dt.logs(container_id, stream=False)
results.container_id = container_id
return results
def commit_buildroot(self):
"""
create image from buildroot
:return:
"""
logger.info("committing buildroot")
self._ensure_is_built()
commit_message = "docker build of '%s' (%s)" % (self.image, self.uri)
self.buildroot_image_name = ImageName(
repo="buildroot-%s" % self.image,
# save the time when image was built
tag=datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
self.buildroot_image_id = self.dt.commit_container(self.build_container_id, commit_message)
return self.buildroot_image_id
def push_buildroot(self, registry):
logger.info("pushing buildroot to registry")
self._ensure_is_built()
image_name_with_registry = self.buildroot_image_name.copy()
image_name_with_registry.registry = registry
return self.dt.tag_and_push_image(
self.buildroot_image_id,
image_name_with_registry)