Skip to content

Commit

Permalink
#308: Update script-language-container-tool to version 0.2.1 (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkilias authored Aug 6, 2021
1 parent d2c4f55 commit ede8c62
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 99 deletions.
Empty file modified exaslct_scripts/construct_docker_runner_image_name.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion exaslct_scripts/exaslct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"

EXASLCT_GIT_REF="0.1.0"
EXASLCT_GIT_REF="0.2.1"
RUNNER_IMAGE_NAME="$(bash "$SCRIPT_DIR/construct_docker_runner_image_name.sh" "$EXASLCT_GIT_REF")"

bash $SCRIPT_DIR/exaslct_within_docker_container_without_container_build.sh "$RUNNER_IMAGE_NAME" "${@}"
Expand Down
105 changes: 8 additions & 97 deletions exaslct_scripts/exaslct_within_docker_container.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,103 +16,9 @@ else
terminal_parameter=""
fi

declare -A relevant_mount_point_arguments
relevant_mount_point_arguments["--flavor-path"]=in_path
relevant_mount_point_arguments["--export-path"]=out_path
relevant_mount_point_arguments["--output-directory"]=out_path
relevant_mount_point_arguments["--temporary-base-directory"]=out_path
relevant_mount_point_arguments["--cache-directory"]=in_path
relevant_mount_point_arguments["--save-directory"]=out_path
relevant_mount_point_arguments["--task-dependencies-dot-file"]=out_file
#relevant_mount_point_arguments["--test-folder"]=in_path # TODO reactive in #37
#relevant_mount_point_arguments["--test-file"]=in_file # TODO reactive in #37

function _get_mount_point_path_for_in_dir() {
local current_arg=$1
local dir_path=$2

if [[ -d $dir_path ]]; then
mount_point_paths+=("$dir_path")
else
echo "Input directory $dir_path for parameter $current_arg does not exist."
exit 1
fi
}

function _get_mount_point_path_for_in_file() {
local current_arg=$1
local file_path=$2
if [[ -f $file_path ]]; then
local rel_dir_name=''
rel_dir_name="$(dirname "${file_path}")"
mount_point_paths+=("$rel_dir_name")
else
echo "Input file $file_path for parameter $current_arg does not exist."
exit 1
fi
}

function _get_mount_point_path_for_out_path() {
local dir_path=$1
#Create out directories if necessary
if [[ ! -d $dir_path ]]; then
mkdir -p "$dir_path"
fi
mount_point_paths+=("$dir_path")
}

function _get_mount_point_path_for_out_file() {
local file_path=$1
local rel_dir_name=''
rel_dir_name="$(dirname "${file_path}")"
#Create out directories if necessary
if [[ ! -d $file_path ]]; then
mkdir -p "$rel_dir_name"
fi
mount_point_paths+=("$rel_dir_name")
}

function _get_mount_point_path() {
local current_arg=$1
local next_arg=$2
local arg_type=$3

case $arg_type in
in_path)
_get_mount_point_path_for_in_dir "${current_arg}" "${next_arg}"
;;
in_file)
_get_mount_point_path_for_in_file "${current_arg}" "${next_arg}"
;;
out_path)
_get_mount_point_path_for_out_path "${next_arg}"
;;
out_file)
_get_mount_point_path_for_out_file "${next_arg}"
;;
*)
echo "INVALID ARGUMENT. Please adjust variable relevant_mount_point_arguments in $0!"
exit 1
;;
esac
}

function _get_mount_point_paths() {
local lenArgs="$#"
for ((idxArg = 1; idxArg < lenArgs; idxArg++)); do
current_arg=${!idxArg}
next_arg_idx=$((idxArg + 1))
next_arg=${!next_arg_idx}
#Better way to test if the argument is in $relevant_mount_point_arguments
#would be to use [[ -v ...]], however this does not work correctly with bash 4.2
if [[ -n "${relevant_mount_point_arguments[${current_arg}]-}" ]]; then
_get_mount_point_path $current_arg $next_arg "${relevant_mount_point_arguments[${current_arg}]}"
fi
done
}

SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
declare -a mount_point_paths
_get_mount_point_paths "${@}"
mount_point_paths=($(bash "$SCRIPT_DIR"/mount_point_parsing.sh "${@}"))

quoted_arguments=''
for argument in "${@}"; do
Expand All @@ -129,6 +35,11 @@ for mount_point in "${mount_point_paths[@]}"; do
chown_directories="$chown_directories \"${mount_point//\"/\\\"}\""
done

chown_directories_cmd=''
if [[ -n "$chown_directories" ]]; then
chown_directories_cmd="chown -R $(id -u):$(id -g) $chown_directories;"
fi

#For all mount pounts (directories in argument list) we need
# 1. For the host argument: Resolve relative paths and resolve symbolic links
# 2. For the container argument: Resolve relative paths, but keep symbolic links
Expand All @@ -141,7 +52,7 @@ done

# Still need to "CHOWN" .build_output
# because it is a default value for --output-path, and hence might not be part of $chown_directories
RUN_COMMAND="/script-languages-container-tool/starter_scripts/exaslct_without_poetry.sh $quoted_arguments; RETURN_CODE=\$?; chown -R $(id -u):$(id -g) $chown_directories; chown -R $(id -u):$(id -g) .build_output &> /dev/null; exit \$RETURN_CODE"
RUN_COMMAND="/script-languages-container-tool/starter_scripts/exaslct_without_poetry.sh $quoted_arguments; RETURN_CODE=\$?; $chown_directories_cmd chown -R $(id -u):$(id -g) .build_output &> /dev/null; exit \$RETURN_CODE"

HOST_DOCKER_SOCKER_PATH="/var/run/docker.sock"
CONTAINER_DOCKER_SOCKER_PATH="/var/run/docker.sock"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127e350e15f14416bcda11e073f4f2e5615b7846e4b3adb0cbeaaee4ffe51c4779507581d924b78951c7b1416410e63664e326de45cbe807f38f319b2ebb866c exaslct_within_docker_container.sh
af67ec0600650d540254c062b28b73ddcec1171733812025cb4eec01ed77191ddbb5223236f8e9470df9032ac8539c4065b9541946001e03a7bd875fea2387cb exaslct_within_docker_container.sh
Empty file.
129 changes: 129 additions & 0 deletions exaslct_scripts/mount_point_parsing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env bash

#set -e => immediately exit if any command [1] has a non-zero exit status
#set -u => reference to any variable you haven't previously defined is an error and causes the program to immediately exit.
#set -o pipefailt => This setting prevents errors in a pipeline from being masked.
# If any command in a pipeline fails,
# that return code will be used as the return code of the whole pipeline.
set -euo pipefail

declare -A relevant_mount_point_arguments
relevant_mount_point_arguments["--flavor-path"]=in_path
relevant_mount_point_arguments["--export-path"]=out_path
relevant_mount_point_arguments["--output-directory"]=out_path
relevant_mount_point_arguments["--temporary-base-directory"]=out_path
relevant_mount_point_arguments["--cache-directory"]=in_path
relevant_mount_point_arguments["--save-directory"]=out_path
relevant_mount_point_arguments["--task-dependencies-dot-file"]=out_file
#relevant_mount_point_arguments["--test-folder"]=in_path # TODO reactive in #37
#relevant_mount_point_arguments["--test-file"]=in_file # TODO reactive in #37

function _get_mount_point_path_for_in_dir() {
local current_arg=$1
local dir_path=$2

if [[ -d $dir_path ]]; then
mount_point_paths+=("$dir_path")
else
>&2 echo "Input directory $dir_path for parameter $current_arg does not exist."
exit 1
fi
}

function _get_mount_point_path_for_in_file() {
local current_arg=$1
local file_path=$2
if [[ -f $file_path ]]; then
local rel_dir_name=''
rel_dir_name="$(dirname "${file_path}")"
mount_point_paths+=("$rel_dir_name")
else
>&2 echo "Input file $file_path for parameter $current_arg does not exist."
exit 1
fi
}

function _get_mount_point_path_for_out_path() {
local dir_path=$1
#Create out directories if necessary
if [[ ! -d $dir_path ]]; then
mkdir -p "$dir_path"
fi
mount_point_paths+=("$dir_path")
}

function _get_mount_point_path_for_out_file() {
local file_path=$1
local rel_dir_name=''
rel_dir_name="$(dirname "${file_path}")"
#Create out directories if necessary
if [[ ! -d $file_path ]]; then
mkdir -p "$rel_dir_name"
fi
mount_point_paths+=("$rel_dir_name")
}

function _get_mount_point_path() {
local current_arg=$1
local next_arg=$2
local arg_type=$3

case $arg_type in
in_path)
_get_mount_point_path_for_in_dir "${current_arg}" "${next_arg}"
;;
in_file)
_get_mount_point_path_for_in_file "${current_arg}" "${next_arg}"
;;
out_path)
_get_mount_point_path_for_out_path "${next_arg}"
;;
out_file)
_get_mount_point_path_for_out_file "${next_arg}"
;;
*)
>&2 echo "INVALID ARGUMENT. Please adjust variable relevant_mount_point_arguments in $0!"
exit 1
;;
esac
}

function _get_mount_point_paths() {
local lenArgs="$#"
for ((idxArg = 1; idxArg < lenArgs; idxArg++)); do
current_arg=${!idxArg}
next_arg_idx=$((idxArg + 1))
next_arg=${!next_arg_idx}
#Better way to test if the argument is in $relevant_mount_point_arguments
#would be to use [[ -v ...]], however this does not work correctly with bash 4.2
if [[ -n "${relevant_mount_point_arguments[${current_arg}]-}" ]]; then
_get_mount_point_path $current_arg $next_arg "${relevant_mount_point_arguments[${current_arg}]}"
fi
done
}

function _format_parameters() {
result=""
for param in "${@}"; do
local found=0
for check_param in "${!relevant_mount_point_arguments[@]}"; do
if [[ $param == "${check_param}"=* ]]; then
first_part="$(echo $param | cut -d= -f 1)"
second_part="$(echo $param | cut -d= -f 2-)"
result="$result $first_part $second_part"
found=1
break
fi
done
if [[ $found -eq 0 ]]; then
result="$result $param"
fi
done
echo "$result"
}

declare -a mount_point_paths
formatted_params=$(_format_parameters "${@}")
_get_mount_point_paths $formatted_params

echo "${mount_point_paths[@]}"
1 change: 1 addition & 0 deletions exaslct_scripts/mount_point_parsing.sh.sha512sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9481d697fa3a9143a3571171c69b7b5bcb13902aebc83d879f34e874c1878b1e7d74d7217dc18ba77c7b502f753cb505f94afc141e5153458fc7b61a6ac28ee6 mount_point_parsing.sh

0 comments on commit ede8c62

Please sign in to comment.