Fix log with test
This commit is contained in:
+15
-9
@@ -148,26 +148,28 @@ class BlenderDocker:
|
|||||||
logger = self._get_logger('test')
|
logger = self._get_logger('test')
|
||||||
container_name = f"Blender-Docker-Testing-{self._blender_version.tag_name_slugify()}"
|
container_name = f"Blender-Docker-Testing-{self._blender_version.tag_name_slugify()}"
|
||||||
command = ['./blender', '--version']
|
command = ['./blender', '--version']
|
||||||
|
container = None
|
||||||
try:
|
try:
|
||||||
print(f'Testing your Blender Docker image {self._docker_image_name}')
|
print(f'Testing your Blender Docker image {self._docker_image_name}')
|
||||||
logger.info(f'Testing image "{self._docker_image_name}" in container "{container_name}" '
|
logger.info(f'Testing image "{self._docker_image_name}" in container "{container_name}" '
|
||||||
f'with command: {" ".join(command)}')
|
f'with command: {" ".join(command)}')
|
||||||
|
|
||||||
test = self._docker_client.containers.run(
|
# auto_remove is intentionally NOT used: Docker can remove the container
|
||||||
|
# right after it exits, racing with the logs() call below and turning a
|
||||||
|
# real container-side error into an unrelated 409 "dead or marked for
|
||||||
|
# removal" API error. We remove the container ourselves once logs are read.
|
||||||
|
container = self._docker_client.containers.run(
|
||||||
name=container_name,
|
name=container_name,
|
||||||
image=self._docker_image_name,
|
image=self._docker_image_name,
|
||||||
command=command,
|
command=command,
|
||||||
auto_remove=True,
|
|
||||||
remove=True,
|
|
||||||
detach=True,
|
detach=True,
|
||||||
stdout=True,
|
stdout=True,
|
||||||
stderr=True,
|
stderr=True,
|
||||||
stream=True,
|
|
||||||
)
|
)
|
||||||
result = test.wait()
|
result = container.wait()
|
||||||
exit_code = result.get('StatusCode')
|
exit_code = result.get('StatusCode')
|
||||||
|
|
||||||
container_logs = test.logs(stdout=True, stderr=True).decode('utf-8', errors='replace').strip()
|
container_logs = container.logs(stdout=True, stderr=True).decode('utf-8', errors='replace').strip()
|
||||||
for raw_line in container_logs.split('\n'):
|
for raw_line in container_logs.split('\n'):
|
||||||
line = _clean_log_line(raw_line)
|
line = _clean_log_line(raw_line)
|
||||||
if line:
|
if line:
|
||||||
@@ -194,10 +196,14 @@ class BlenderDocker:
|
|||||||
except APIError as e:
|
except APIError as e:
|
||||||
logger.exception(f'API error while testing "{self._docker_image_name}": {e}')
|
logger.exception(f'API error while testing "{self._docker_image_name}": {e}')
|
||||||
print(f'API error: {e}')
|
print(f'API error: {e}')
|
||||||
for line in e.build_log:
|
|
||||||
if 'stream' in line:
|
|
||||||
print(line['stream'].strip())
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
if container is not None:
|
||||||
|
try:
|
||||||
|
container.remove(force=True)
|
||||||
|
except APIError:
|
||||||
|
pass
|
||||||
|
|
||||||
def push(self):
|
def push(self):
|
||||||
self._docker_client.images.push(
|
self._docker_client.images.push(
|
||||||
|
|||||||
Reference in New Issue
Block a user