in src/image.py [0:0]
def docker_build(self, fileobj=None, custom_context=False):
"""
Uses low level Docker API Client to actually start the process of building the image.
:param fileobj: FileObject, a readable file-like object pointing to the context tarfile.
:param custom_context: bool
:return: int, Build Status
"""
response = [f"Starting the Build Process for {self.repository}:{self.tag}"]
line_counter = 0
line_interval = 50
for line in self.client.build(
fileobj=fileobj,
path=self.dockerfile,
custom_context=custom_context,
rm=True,
decode=True,
tag=self.ecr_url,
buildargs=self.build_args,
labels=self.labels,
target=self.target,
):
# print the log line during build for every line_interval lines for debugging
if line_counter % line_interval == 0:
LOGGER.debug(line)
line_counter += 1
if line.get("error") is not None:
response.append(line["error"])
self.log.append(response)
self.build_status = constants.FAIL
self.summary["status"] = constants.STATUS_MESSAGE[self.build_status]
self.summary["end_time"] = datetime.now()
LOGGER.info(f"Docker Build Logs: \n {self.get_tail_logs_in_pretty_format(100)}")
LOGGER.error("ERROR during Docker BUILD")
LOGGER.error(
f"Error message received for {self.dockerfile} while docker build: {line}"
)
return self.build_status
if line.get("stream") is not None:
response.append(line["stream"])
elif line.get("status") is not None:
response.append(line["status"])
else:
response.append(str(line))
self.log.append(response)
LOGGER.info(f"DOCKER BUILD LOGS: \n{self.get_tail_logs_in_pretty_format()}")
LOGGER.info(f"Completed Build for {self.repository}:{self.tag}")
self.build_status = constants.SUCCESS
return self.build_status