本文整理汇总了Python中atomic_reactor.core.DockerTasker.logs方法的典型用法代码示例。如果您正苦于以下问题:Python DockerTasker.logs方法的具体用法?Python DockerTasker.logs怎么用?Python DockerTasker.logs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic_reactor.core.DockerTasker
的用法示例。
在下文中一共展示了DockerTasker.logs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logs
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import logs [as 别名]
def test_logs():
if MOCK:
mock_docker()
t = DockerTasker()
container_id = t.run(input_image_name, command="id")
try:
t.wait(container_id)
output = t.logs(container_id, stderr=True, stream=False)
assert "\n".join(output).startswith("uid=")
finally:
t.remove_container(container_id)
示例2: _load_results
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import logs [as 别名]
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
示例3: BuildManager
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import logs [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)