diff --git a/Dockerfile b/Dockerfile index 76bd1ef93..bd300e17e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,7 @@ RUN curl -sLO https://github.com/argoproj/argo-workflows/releases/download/$ARGO gzip -d < argo-linux-amd64.gz > /usr/local/bin/argo &&\ chmod +x /usr/local/bin/argo +COPY ./functions.sh ${HOME}/functions.sh COPY ./run_workflow_and_argo.sh ${HOME}/run_workflow_and_argo.sh # Baking in example configs for running tests, as docker.client.containers.run diff --git a/functions.sh b/functions.sh new file mode 100644 index 000000000..727f9fb23 --- /dev/null +++ b/functions.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +function store_config { + config_path="$1" + if [[ -z "${MACHINE_CONFIG}" && -z "${GORDO_NAME}" ]]; then + cp /code/config_crd.yml "$config_path" + elif [[ -z "${MACHINE_CONFIG}" ]]; then + # $GORDO_NAME is set + kubectl get gordos ${GORDO_NAME} -o json > "$config_path" + else + echo "$MACHINE_CONFIG" > "$config_path" + fi +} + +function argo_submit { + generated_config_path="$1" + argo lint "$generated_config_path" + if [ "$ARGO_SUBMIT" = true ] ; then + if [[ -n "$ARGO_SERVICE_ACCOUNT" ]]; then + argo submit --serviceaccount "$ARGO_SERVICE_ACCOUNT" "$generated_config_path" + else + argo submit "$generated_config_path" + fi + fi +} diff --git a/run_workflow_and_argo.sh b/run_workflow_and_argo.sh index 85e6a93c1..177feb5da 100755 --- a/run_workflow_and_argo.sh +++ b/run_workflow_and_argo.sh @@ -1,34 +1,31 @@ #!/usr/bin/env bash + set -e + +functions_dir=$(dirname $0) +. $functions_dir/functions.sh + if [[ -n "${DEBUG_SHOW_WORKFLOW}" ]]; then set -x fi -if [[ -z "${MACHINE_CONFIG}" && -z "${GORDO_NAME}" ]]; then - cp /code/config_crd.yml /tmp/config.yml -elif [[ -z "${MACHINE_CONFIG}" ]]; then - # $GORDO_NAME is set - kubectl get gordos ${GORDO_NAME} -o json > /tmp/config.yml -else - echo "$MACHINE_CONFIG" > /tmp/config.yml -fi + +tmpdir="${TMPDIR:-/tmp}" + +config_path="$tmpdir/config.yml" +generated_config_path="$tmpdir/generated-config.yml" + +store_config "$config_path" if [[ -n "${DEBUG_SHOW_WORKFLOW}" ]]; then echo "===CONFIG===" - cat /tmp/config.yml + cat "$config_path" fi -gordo workflow generate --machine-config /tmp/config.yml --output-file /tmp/generated-config.yml +gordo workflow generate --machine-config "$config_path" --output-file "$generated_config_path" if [[ -n "${DEBUG_SHOW_WORKFLOW}" ]]; then echo "===GENERATED CONFIG===" - cat /tmp/generated-config.yml + cat "$generated_config_path" fi -argo lint /tmp/generated-config.yml -if [ "$ARGO_SUBMIT" = true ] ; then - if [[ -n "$ARGO_SERVICE_ACCOUNT" ]]; then - argo submit --serviceaccount "$ARGO_SERVICE_ACCOUNT" /tmp/generated-config.yml - else - argo submit /tmp/generated-config.yml - fi -fi +argo_submit "$generated_config_path"