Skip to content

Commit ce2302c

Browse files
cli: show output of docker build (#882)
Show output of docker build by making use of docker-py's low level API fixes #785 Co-authored-by: Ivo Jimenez <[email protected]>
1 parent b672201 commit ce2302c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/popper/runner_host.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,17 @@ def _create_container(self, cid, step):
212212
if build:
213213
log.info(f"[{step.id}] docker build {img}:{tag} {build_ctx_path}")
214214
if not self._config.dry_run:
215-
self._d.images.build(
216-
path=build_ctx_path, tag=f"{img}:{tag}", rm=True, pull=True
215+
streamer = self._d.api.build(
216+
decode=True, path=build_ctx_path, tag=f"{img}:{tag}", rm=True,
217217
)
218+
for chunk in streamer:
219+
if self._config.quiet:
220+
continue
221+
if "stream" in chunk:
222+
lines = [line for line in chunk["stream"].splitlines() if line]
223+
for line in lines:
224+
log.step_info(line.strip())
225+
218226
elif not self._config.skip_pull and not step.skip_pull:
219227
log.info(f"[{step.id}] docker pull {img}:{tag}")
220228
if not self._config.dry_run:

src/test/test_runner_host.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ def test_get_build_info(self):
275275
def test_docker_basic_run(self):
276276
repo = self.mk_repo()
277277
conf = ConfigLoader.load(workspace_dir=repo.working_dir)
278+
test_string = "STEP_INFO:popper:Successfully tagged popperized/bin:master"
278279

279280
with WorkflowRunner(conf) as r:
280281
wf_data = {"steps": [{"uses": "popperized/bin/sh@master", "args": ["ls"],}]}
281-
r.run(WorkflowParser.parse(wf_data=wf_data))
282+
with self.assertLogs(log, level="STEP_INFO") as cm:
283+
r.run(WorkflowParser.parse(wf_data=wf_data))
284+
self.assertTrue(test_string in cm.output, f"Got cmd output: {cm.output}")
282285

283286
wf_data = {
284287
"steps": [
@@ -303,6 +306,13 @@ def test_docker_basic_run(self):
303306
}
304307
self.assertRaises(SystemExit, r.run, WorkflowParser.parse(wf_data=wf_data))
305308

309+
conf = ConfigLoader.load(workspace_dir=repo.working_dir, quiet=True)
310+
with WorkflowRunner(conf) as r:
311+
wf_data = {"steps": [{"uses": "popperized/bin/sh@master", "args": ["ls"],}]}
312+
with self.assertLogs(log, level="STEP_INFO") as cm:
313+
r.run(WorkflowParser.parse(wf_data=wf_data))
314+
self.assertTrue(test_string not in cm.output)
315+
306316
repo.close()
307317
shutil.rmtree(repo.working_dir, ignore_errors=True)
308318

0 commit comments

Comments
 (0)