Skip to content

Commit

Permalink
Refactoring run_workflow_and_argo.sh (#1244)
Browse files Browse the repository at this point in the history
* Refactoring run_workflow_and_argo.sh

* COPY ./functions.sh ${HOME}/functions.sh

* Small fix
  • Loading branch information
koropets authored May 19, 2022
1 parent 921a740 commit 3ef0800
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 16 additions & 19 deletions run_workflow_and_argo.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3ef0800

Please sign in to comment.