Now handling the script's own crashes: saving to log and build status file (close #25).

This commit is contained in:
antux18 2024-07-29 15:17:22 +02:00
parent e8b25b74a7
commit 14ca1da160
2 changed files with 45 additions and 33 deletions

View File

@ -71,6 +71,7 @@ The following are the possible results of the build:
- `baseimage_unavailable`: The base image needed for this container is not available. - `baseimage_unavailable`: The base image needed for this container is not available.
- `artifact_unavailable`: The artifact could not be downloaded. - `artifact_unavailable`: The artifact could not be downloaded.
- `dockerfile_not_found`: No Dockerfile has been found in the location specified in the configuration file. - `dockerfile_not_found`: No Dockerfile has been found in the location specified in the configuration file.
- `script_crash`: An error has occurred with the script itself.
- `unknown_error`: Any other error. - `unknown_error`: Any other error.
### Artifact hash log ### Artifact hash log

19
ecg.py
View File

@ -21,6 +21,7 @@ import logging
import datetime import datetime
import sys import sys
import string import string
import traceback
def trim(url): def trim(url):
""" """
@ -375,7 +376,8 @@ def main():
description = "ECG is a program that automates software environment checking for scientific artifacts. " description = "ECG is a program that automates software environment checking for scientific artifacts. "
"It is meant to be executed periodically to analyze variations in the software environment of the artifact through time." "It is meant to be executed periodically to analyze variations in the software environment of the artifact through time."
) )
parser.add_argument('-v', '--verbose', parser.add_argument(
'-v', '--verbose',
action = 'store_true', action = 'store_true',
help = "Shows more details on what is being done." help = "Shows more details on what is being done."
) )
@ -409,7 +411,8 @@ def main():
"If not specified, cache is disabled.", "If not specified, cache is disabled.",
required = False required = False
), ),
parser.add_argument('--docker-cache', parser.add_argument(
'--docker-cache',
action = 'store_true', action = 'store_true',
help = "Use cache for Docker 'build'." help = "Use cache for Docker 'build'."
) )
@ -433,6 +436,8 @@ def main():
# Parsing the input file including the configuration of the artifact's # Parsing the input file including the configuration of the artifact's
# image: # image:
config_path = args.config config_path = args.config
status = ""
try:
config_file = open(config_path, "r") config_file = open(config_path, "r")
config = json.loads(config_file.read()) config = json.loads(config_file.read())
# config = yaml.safe_load(config_file) # config = yaml.safe_load(config_file)
@ -448,12 +453,10 @@ def main():
use_cache = True use_cache = True
dl_dir = cache_dir dl_dir = cache_dir
artifact_dir = download_sources(config, arthashlog_path, dl_dir, use_cache) artifact_dir = download_sources(config, arthashlog_path, dl_dir, use_cache)
status = ""
# If download was successful: # If download was successful:
if artifact_dir != "": if artifact_dir != "":
artifact_name = os.path.splitext(os.path.basename(config_path))[0] artifact_name = os.path.splitext(os.path.basename(config_path))[0]
return_code, build_output = build_image(config, artifact_dir, artifact_name, args.docker_cache) return_code, build_output = build_image(config, artifact_dir, artifact_name, args.docker_cache)
status = ""
if return_code == 0: if return_code == 0:
status = "success" status = "success"
check_env(config, artifact_dir, artifact_name, pkglist_path) check_env(config, artifact_dir, artifact_name, pkglist_path)
@ -466,6 +469,14 @@ def main():
else: else:
logging.fatal("Artifact could not be downloaded!") logging.fatal("Artifact could not be downloaded!")
status = "artifact_unavailable" status = "artifact_unavailable"
except Exception as err:
# Handles any possible script's own crashes:
formatted_err = str(''.join(traceback.format_exception(None, err, err.__traceback__)))
log_file = open(log_path, "a")
log_file.write(formatted_err)
log_file.close()
print(formatted_err)
status = "script_crash"
buildresult_saver(status, buildstatus_path, config_path) buildresult_saver(status, buildstatus_path, config_path)
if __name__ == "__main__": if __name__ == "__main__":