From: Alexandru Avadanii Date: Sat, 18 Apr 2020 16:42:08 +0000 (+0200) Subject: blucon.sh: Allow validation/results dir override X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=54018ed1ad8b1a85b32f6b6cdea7d36ed70824b5;p=validation.git blucon.sh: Allow validation/results dir override When running in CI, the validation git repository is cloned in the job workspace, which usually has a custom directory name matching the job name (e.g. bluval-daily-master) instead of the previously hardcoded 'validation' directory name. Also, the results dir should not be a sibling of the validation git repo directory when running in CI, but a subdirectory of the said dir. To accomodate this, allow overriding both previously hardcoded directory paths via environment variables (VALIDATION_DIR, RESULTS_DIR). While at it, add a new '-t' argument for specifying the Docker tag to be used for the validation docker images (previously hardcoded to 'latest') in order to support running docker images associated to a specific Validation release tag (e.g. 3.0.0). JIRA: VAL-95 Change-Id: I4d3c10881de28c64bcca05ff23aa1025f67a1f5e Signed-off-by: Alexandru Avadanii --- diff --git a/bluval/blucon.py b/bluval/blucon.py index 2fce9d0..ee7f706 100644 --- a/bluval/blucon.py +++ b/bluval/blucon.py @@ -53,16 +53,16 @@ def get_volumes(layer): return volume_list -def invoke_docker(bluprint, layer): +def invoke_docker(bluprint, layer, tag): """Start docker container for given layer """ volume_list = get_volumes('common') + get_volumes(layer) cmd = ("docker run --rm" + volume_list + _SUBNET + - " akraino/validation:{0}-latest" + " akraino/validation:{0}-{3}" " /bin/sh -c" " 'cd /opt/akraino/validation " "&& python -B bluval/bluval.py -l {0} {1} {2}'" - .format(layer, ("-o" if _OPTIONAL_ALSO else ""), bluprint)) + .format(layer, ("-o" if _OPTIONAL_ALSO else ""), bluprint, tag)) args = [cmd] try: @@ -73,7 +73,7 @@ def invoke_docker(bluprint, layer): raise BluvalError(OSError) -def invoke_dockers(yaml_loc, layer, blueprint_name): +def invoke_dockers(yaml_loc, layer, blueprint_name, tag): """Parses yaml file and starts docker container for one/all layers """ with open(str(yaml_loc)) as yaml_file: @@ -81,19 +81,20 @@ def invoke_dockers(yaml_loc, layer, blueprint_name): blueprint = yamldoc['blueprint'] if layer is None or layer == "all": for each_layer in blueprint['layers']: - invoke_docker(blueprint_name, each_layer) + invoke_docker(blueprint_name, each_layer, tag) else: - invoke_docker(blueprint_name, layer) + invoke_docker(blueprint_name, layer, tag) @click.command() @click.argument('blueprint') @click.option('--layer', '-l') @click.option('--network', '-n') +@click.option('--tag', '-t') @click.option('--optional_also', '-o', is_flag=True) -def main(blueprint, layer, network, optional_also): +def main(blueprint, layer, network, tag, optional_also): """Takes blueprint name and optional layer. Validates inputs and derives - yaml location from blueprint name. Invokes validate on blue print. + yaml location from blueprint name. Invokes validate on blueprint. """ global _OPTIONAL_ALSO # pylint: disable=global-statement global _SUBNET # pylint: disable=global-statement @@ -107,8 +108,11 @@ def main(blueprint, layer, network, optional_also): if network is not None: _SUBNET = " --net=" + network print("Using", _SUBNET) + if tag is None: + tag = 'latest' + print("Using tag {}".format(tag)) try: - invoke_dockers(yaml_loc, layer, blueprint) + invoke_dockers(yaml_loc, layer, blueprint, tag) except ShowStopperError as err: print('ShowStopperError:', err) except BluvalError as err: diff --git a/bluval/blucon.sh b/bluval/blucon.sh index afe54db..b882f92 100755 --- a/bluval/blucon.sh +++ b/bluval/blucon.sh @@ -18,14 +18,17 @@ if [ -z "$AKRAINO_HOME" ] then - echo "AKRAINO_HOME not available. Setting..." - this_file="$(readlink -f $0)" - bluval_dir="$(dirname $this_file)" - validation_dir="$(dirname $bluval_dir)" - parent_dir="$(dirname $validation_dir)" - export AKRAINO_HOME="$parent_dir" + echo "AKRAINO_HOME not available. Setting ..." + AKRAINO_HOME="$(readlink -f "$(dirname "$0")/../..")" fi + +# Allow overriding VALIDATION_DIR and/or RESULTS_DIR via env vars +VALIDATION_DIR=${VALIDATION_DIR:-"${AKRAINO_HOME}/validation"} +RESULTS_DIR=${RESULTS_DIR:-"${AKRAINO_HOME}/results"} + echo "AKRAINO_HOME=$AKRAINO_HOME" +echo "VALIDATION_DIR=$VALIDATION_DIR" +echo "RESULTS_DIR=$RESULTS_DIR" if [ "$#" -eq 0 ] then @@ -38,6 +41,7 @@ then Options: -l, --layer TEXT -n, --network TEXT + -t, --tag TEXT -o, --optional_also --help Show this message and exit.' @@ -45,13 +49,13 @@ then fi echo "Building docker image" -image_tag=$( (git branch || echo "* local") | grep "^\*" | awk '{print $2}') -docker build -t akraino/validation:blucon-$image_tag $AKRAINO_HOME/validation/bluval +img="akraino/validation:blucon-$(git rev-parse --abbrev-ref HEAD || echo local)" +docker build -t "$img" "$VALIDATION_DIR/bluval" set -x docker run --rm \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v $AKRAINO_HOME/results:/opt/akraino/results \ - -v $AKRAINO_HOME/validation:/opt/akraino/validation \ - akraino/validation:blucon-$image_tag "$@" + -v "$RESULTS_DIR":/opt/akraino/results \ + -v "$VALIDATION_DIR":/opt/akraino/validation \ + "$img" "$@"