diff --git a/script/image_name.sh b/script/image_name.sh new file mode 100644 index 0000000..0f217ca --- /dev/null +++ b/script/image_name.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +## Returns the correct image name to run a notebook. +## If the test name's environmental variable exists, return that. +## otherwise: +## if the second argument passed is 'true' return the tag value for the image read from the version.txt file. +## else returns 'latest' +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +function image_name () { + base="regression-tests-$1" + if [ "$2" = true ]; then + recent_tag=$(<"$SCRIPT_DIR/../test/$1/version.txt") + else + recent_tag="latest" + fi + env_image_name=$(echo "${base}_IMAGE" | tr '[:lower:]' '[:upper:]' | tr '-' '_') + default_image="ghcr.io/nasa/${base}:${recent_tag}" + echo "${!env_image_name:-${default_image}}" +} diff --git a/script/test-in-bamboo.sh b/script/test-in-bamboo.sh index 2e26012..6b239da 100755 --- a/script/test-in-bamboo.sh +++ b/script/test-in-bamboo.sh @@ -6,16 +6,9 @@ set -ex -## Returns the image name to pull from docker. If the test name's -## environmental variable exists, return that, otherwise return the default -## value for the image read from the version.txt file. -function image_name () { - base="regression-tests-$1" - recent_tag=$(<"./test/$1/version.txt") - env_image_name=$(echo "${base}_IMAGE" | tr '[:lower:]' '[:upper:]' | tr '-' '_') - default_image="ghcr.io/nasa/${base}:${recent_tag}" - echo "${!env_image_name:-${default_image}}" -} +## Import function image_name that determines the images to pull from docker. +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/image_name.sh" if [[ -z "${HARMONY_ENVIRONMENT}" ]]; then echo "HARMONY_ENVIRONMENT must be set to run this script" @@ -51,7 +44,7 @@ echo "harmony host url: ${harmony_host_url}" image_names=() all_tests=(harmony harmony-regression hoss hga n2z swath-projector trajectory-subsetter variable-subsetter regridder hybig) for image in "${all_tests[@]}"; do - image_names+=($(image_name "$image")) + image_names+=($(image_name "$image" true)) done # download all of the images and output their names @@ -65,11 +58,11 @@ done ## run the tests cd test \ && export HARMONY_HOST_URL="${harmony_host_url}" \ - AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \ - AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \ - EDL_USER="${EDL_USER}" \ - EDL_PASSWORD="${EDL_PASSWORD}" \ - && ./run_notebooks.sh + AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \ + AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \ + EDL_USER="${EDL_USER}" \ + EDL_PASSWORD="${EDL_PASSWORD}" \ + && ./run_notebooks.sh --use-versions # Copy the notebook artefacts up to S3: if [[ -z "${REGRESSION_TEST_OUTPUT_BUCKET}" ]]; then diff --git a/test/run_notebooks.sh b/test/run_notebooks.sh index f700b97..3a38373 100755 --- a/test/run_notebooks.sh +++ b/test/run_notebooks.sh @@ -4,16 +4,11 @@ RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color -## Returns the correct image name. If the test name's -## environmental variable exists, return that, otherwise return the default -## value for the image. -function image_name () { - base="regression-tests-$1" - env_image_name=$(echo "${base}_IMAGE" | tr '[:lower:]' '[:upper:]' | tr '-' '_') - default_image="ghcr.io/nasa/${base}:latest" - echo "${!env_image_name:-${default_image}}" -} - +## Import function that returns correct image names. if flag --use-versions is +## set when this script is called, it will use names form versions.txt +## otherwise it will default to "latest" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/../script/image_name.sh" echo "Running regression tests" @@ -21,7 +16,22 @@ echo "Running regression tests" # Specify the test images to run, by default all built by the Makefile. If # the script is invoked with a list of images, only run those. all_images=(harmony harmony-regression hoss hga n2z swath-projector trajectory-subsetter variable-subsetter regridder hybig) -specified_images=("$@") +specified_images=() +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case "$1" in + --use-versions) + use_versions=true + shift + ;; + *) + specified_images+=("$1") + shift + ;; + esac +done + +## use the user supplied images or the default list of all images. images=("${specified_images[@]:-${all_images[@]}}") # launch all the docker containers and store their process IDs @@ -30,17 +40,17 @@ for image in "${images[@]}"; do # insert AWS Credential variables for n2z only if [[ $image == "n2z" ]]; then - creds="--env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} --env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" + creds="--env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} --env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" else - creds="" + creds="" fi - full_image=$(image_name "$image") + full_image=$(image_name "$image" "$use_versions") echo "running test with $full_image" PIDS+=(${image},$(docker run -d -v ${PWD}/output:/workdir/output \ - ${creds} \ - --env EDL_PASSWORD="${EDL_PASSWORD}" --env EDL_USER="${EDL_USER}" \ - --env harmony_host_url="${HARMONY_HOST_URL}" "${full_image}")) + ${creds} \ + --env EDL_PASSWORD="${EDL_PASSWORD}" --env EDL_USER="${EDL_USER}" \ + --env harmony_host_url="${HARMONY_HOST_URL}" "${full_image}")) done trap ctrl_c SIGINT SIGTERM