Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed decoding step and activate decoding by client #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions i2_client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
permission, please contact the copyright holders and delete this file.
"""

import json
import logging
import re
import tempfile
Expand Down Expand Up @@ -91,13 +90,13 @@ def _build_docker_img(
log.info(f"Building '{tag}'...")

try:
generator = client.build(path=str(Path.cwd()), tag=tag, **additional_args)
generator = client.build(
path=str(Path.cwd()), tag=tag, decode=True, **additional_args
)
output = generator.__next__()
except docker.errors.APIError as error:
raise docker.errors.BuildError(reason=error.explanation, build_log=error)

output = json.loads(output.decode())

# Setup progress bar
num_steps = int(output["stream"].split()[1].split("/")[-1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work because we need the output to determine the number of steps.

Case like this (b'{"stream":"\\n"}\r\n') happend lot of times during the build, just ignore with something like:

output = json.loads(output.decode().split("\n")[0])

Maybe add this to the other place where we decode the docker output if it happend at all step.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pattern is not regular, sometimes there is a lot of /n before the content we want. but I will try ur solution nevertheless


Expand All @@ -111,7 +110,6 @@ def _build_docker_img(
while True:
try:
output = generator.__next__()
output = json.loads(output.decode())

if "stream" in output:
stream = re.sub(r" +", " ", output["stream"]).replace("\n", "")
Expand Down