in src/image.py [0:0]
def push_image(self, tag_value=None):
"""
Pushes the Docker image to ECR using Docker low-level API client for docker.
:param tag_value: str, an optional variable to provide a different tag
:return: int, states if the Push was successful or not
"""
tag = tag_value
if tag_value is None:
tag = self.tag
response = [f"Starting image Push for {self.repository}:{tag}"]
for line in self.client.push(self.repository, tag, stream=True, decode=True):
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 PUSH")
LOGGER.error(
f"Error message received for {self.repository}:{tag} while docker push: {line}"
)
return self.build_status
if line.get("stream") is not None:
response.append(line["stream"])
else:
response.append(str(line))
self.summary["status"] = constants.STATUS_MESSAGE[self.build_status]
self.summary["end_time"] = datetime.now()
self.summary["ecr_url"] = self.ecr_url
if "pushed_uris" not in self.summary:
self.summary["pushed_uris"] = []
self.summary["pushed_uris"].append(f"{self.repository}:{tag}")
response.append(f"Completed Push for {self.repository}:{tag}")
self.log.append(response)
LOGGER.info(f"DOCKER PUSH LOGS: \n {self.get_tail_logs_in_pretty_format(2)}")
return self.build_status