-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature 839 conda envs in automation (#967)
- Loading branch information
1 parent
64044eb
commit 3267ae6
Showing
68 changed files
with
1,777 additions
and
1,185 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ARG METPLUS_ENV_TAG=metplus_base | ||
ARG METPLUS_IMG_TAG=develop | ||
|
||
FROM dtcenter/metplus-envs:${METPLUS_ENV_TAG} as env | ||
|
||
ARG METPLUS_IMG_TAG=develop | ||
FROM dtcenter/metplus-dev:${METPLUS_IMG_TAG} | ||
|
||
COPY --from=env /usr/lib/jvm/jre /usr/lib/jvm/jre/ | ||
COPY --from=env /usr/share/javazi-1.8/tzdb.dat /usr/share/javazi-1.8/ | ||
COPY --from=env /data/input/GempakToCF.jar /data/input/GempakToCF.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ARG METPLUS_ENV_TAG=metplus_base | ||
ARG METPLUS_IMG_TAG=develop | ||
|
||
FROM dtcenter/metplus-envs:${METPLUS_ENV_TAG} as env | ||
|
||
ARG METPLUS_IMG_TAG=develop | ||
FROM dtcenter/metplus-dev:${METPLUS_IMG_TAG} | ||
|
||
COPY --from=env /usr/local/envs /usr/local/envs/ | ||
|
||
COPY --from=env /usr/local/bin/conda /usr/local/bin/conda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#! /bin/bash | ||
|
||
# The repo source code is cloned to $RUNNER_WORKSPACE/$REPO_NAME | ||
# Setup the workspace path to that for easier access later | ||
REPO_NAME=$(basename $RUNNER_WORKSPACE) | ||
WS_PATH=$RUNNER_WORKSPACE/$REPO_NAME | ||
|
||
# set CI jobs directory variable to easily move it | ||
CI_JOBS_DIR=.github/jobs | ||
|
||
source ${GITHUB_WORKSPACE}/${CI_JOBS_DIR}/bash_functions.sh | ||
|
||
# get branch name for push or pull request events | ||
# add -pull_request if pull request event to keep separated | ||
branch_name=`${GITHUB_WORKSPACE}/${CI_JOBS_DIR}/print_branch_name.py` | ||
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then | ||
branch_name=${branch_name}-pull_request | ||
fi | ||
|
||
# try to pull image from DockerHub | ||
DOCKERHUBTAG=dtcenter/metplus-dev:${branch_name} | ||
time_command docker pull $DOCKERHUBTAG | ||
|
||
# if unsuccessful (i.e. pull request from a fork) | ||
# then build image locally | ||
docker inspect --type=image $DOCKERHUBTAG > /dev/null | ||
if [ $? != 0 ]; then | ||
# if docker pull fails, build locally | ||
echo docker pull failed. Building Docker image locally... | ||
${GITHUB_WORKSPACE}/${CI_JOBS_DIR}/docker_setup.sh | ||
fi | ||
|
||
# | ||
# running unit tests (pytests) | ||
# | ||
if [ "$INPUT_CATEGORIES" == "pytests" ]; then | ||
export METPLUS_ENV_TAG="pytest" | ||
export METPLUS_IMG_TAG=${branch_name} | ||
echo METPLUS_ENV_TAG=${METPLUS_ENV_TAG} | ||
echo METPLUS_IMG_TAG=${METPLUS_IMG_TAG} | ||
|
||
export RUN_TAG=metplus-run-env | ||
|
||
# use BuildKit to build image | ||
export DOCKER_BUILDKIT=1 | ||
|
||
start_seconds=$SECONDS | ||
|
||
# build an image with the pytest conda env and the METplus branch image | ||
# Note: adding --build-arg <arg-name> without any value tells docker to | ||
# use value from local environment (export METPLUS_IMG_TAG) | ||
time_command docker build -t $RUN_TAG \ | ||
--build-arg METPLUS_IMG_TAG \ | ||
--build-arg METPLUS_ENV_TAG \ | ||
-f .github/actions/run_tests/Dockerfile.run \ | ||
. | ||
|
||
echo Running Pytests | ||
command="export METPLUS_PYTEST_HOST=docker; cd internal_tests/pytests; /usr/local/envs/pytest/bin/pytest -vv --cov=../../metplus" | ||
time_command docker run -v $WS_PATH:$GITHUB_WORKSPACE --workdir $GITHUB_WORKSPACE $RUN_TAG bash -c "$command" | ||
exit $? | ||
fi | ||
|
||
# | ||
# running use case tests | ||
# | ||
|
||
# split apart use case category and subset list from input | ||
CATEGORIES=`echo $INPUT_CATEGORIES | awk -F: '{print $1}'` | ||
SUBSETLIST=`echo $INPUT_CATEGORIES | awk -F: '{print $2}'` | ||
|
||
# run all cases if no subset list specified | ||
if [ -z "${SUBSETLIST}" ]; then | ||
SUBSETLIST="all" | ||
fi | ||
|
||
# get METviewer if used in any use cases | ||
all_requirements=`./${CI_JOBS_DIR}/get_requirements.py ${CATEGORIES} ${SUBSETLIST}` | ||
echo All requirements: $all_requirements | ||
NETWORK_ARG="" | ||
if [[ "$all_requirements" =~ .*"metviewer".* ]]; then | ||
echo "Setting up METviewer" | ||
${GITHUB_WORKSPACE}/${CI_JOBS_DIR}/get_metviewer.sh | ||
NETWORK_ARG=--network="container:mysql_mv" | ||
fi | ||
|
||
# export network arg so it can be read by setup_and_run_use_cases.py | ||
export NETWORK_ARG | ||
|
||
# call script to loop over use case groups to | ||
# get data volumes, set up run image, and run use cases | ||
./${CI_JOBS_DIR}/setup_and_run_use_cases.py ${CATEGORIES} ${SUBSETLIST} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#! /bin/bash | ||
|
||
# utility function to run command get log the time it took to run | ||
function time_command { | ||
local start_seconds=$SECONDS | ||
echo "RUNNING: $*" | ||
"$@" | ||
local error=$? | ||
|
||
local duration=$(( SECONDS - start_seconds )) | ||
echo "TIMING: Command took `printf '%02d' $(($duration / 60))`:`printf '%02d' $(($duration % 60))` (MM:SS): '$*'" | ||
if [ ${error} -ne 0 ]; then | ||
echo "ERROR: '$*' exited with status = ${error}" | ||
fi | ||
return $error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#! /usr/bin/env python3 | ||
|
||
################################################################################ | ||
# Used in GitHub Actions (in .github/workflows/testing.yml) to copy logs for | ||
# use cases that reported errors to another directory | ||
|
||
import os | ||
import sys | ||
import shutil | ||
|
||
def main(output_data_dir, error_logs_dir): | ||
"""! Copy log output to error log directory if any use case failed """ | ||
for use_case_dir in os.listdir(output_data_dir): | ||
log_dir = os.path.join(output_data_dir, | ||
use_case_dir, | ||
'logs') | ||
if not os.path.isdir(log_dir): | ||
continue | ||
|
||
# check if there are errors in the metplus.log file and | ||
# only copy directory if there are any errors | ||
metplus_log = os.path.join(log_dir, 'metplus.log') | ||
found_errors = False | ||
with open(metplus_log, 'r') as file_handle: | ||
if 'ERROR:' in file_handle.read(): | ||
found_errors = True | ||
|
||
if not found_errors: | ||
continue | ||
|
||
output_dir = os.path.join(error_logs_dir, | ||
use_case_dir) | ||
log_files = os.listdir(log_dir) | ||
for log_file in log_files: | ||
log_path = os.path.join(log_dir, log_file) | ||
output_path = os.path.join(output_dir, log_file) | ||
print(f"Copying {log_path} to {output_path}") | ||
# create output directory if it doesn't exist | ||
output_dir = os.path.dirname(output_path) | ||
if not os.path.exists(output_dir): | ||
os.makedirs(output_dir) | ||
shutil.copyfile(log_path, output_path) | ||
|
||
if __name__ == '__main__': | ||
output_data_dir = sys.argv[1] | ||
error_logs_dir = sys.argv[2] | ||
main(output_data_dir, error_logs_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
ci/jobs/get_artifact_name.sh → .github/jobs/get_artifact_name.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.