Skip to content

Commit

Permalink
Locate units using APPLY_ROOT env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Loic Nageleisen committed Jun 25, 2018
1 parent 8a178cd commit 44eeefe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:

lint:
find apply run push lib -type f -not -iname '*.*' | xargs shellcheck -s bash
6 changes: 5 additions & 1 deletion apply
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function usage() {
function host_targets() {
local host="$*"

cat < "$host" | tr '\n' ' '
cat < "${APPLY_ROOT}"/"$host" | tr '\n' ' '
}

function push_each() {
Expand All @@ -28,6 +28,10 @@ function push_each() {
fi
}

if [[ -z "${APPLY_ROOT:-}" ]]; then
APPLY_ROOT="."
fi

if [[ $# -lt 1 ]]; then
usage
fi
Expand Down
6 changes: 5 additions & 1 deletion push
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ function usage() {
exit 1
}

if [[ -z "${APPLY_ROOT:-}" ]]; then
APPLY_ROOT="."
fi

if [[ $# -lt 1 ]]; then
usage
fi
Expand All @@ -33,7 +37,7 @@ remote="$1"

tmp=$(ssh "$remote" 'mktemp -d')
echo -e -n "\033[33m** pushing to\033[0m $remote:$tmp"
if scp -q -r groups units run lib "$remote":"$tmp"; then
if scp -q -r "${APPLY_ROOT}"/{groups,units,run,lib} "$remote":"$tmp"; then
echo -e " \033[32mOK\033[0m"
fi

Expand Down
10 changes: 7 additions & 3 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ function usage() {
}

function root_path() {
cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
if [[ -z "${APPLY_ROOT:-}" ]]; then
cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
else
echo "$APPLY_ROOT"
fi
}

function read_group() {
Expand All @@ -19,7 +23,7 @@ function read_group() {
if [[ ! "$item" == '#'* ]]; then
echo "$item"
fi
done < "$(root_path)/$target"
done < "$(root_path)/$target"
}

function run_group() {
Expand All @@ -33,7 +37,7 @@ function run_group() {
}

function run_unit() {
/bin/bash -l -c "set -e; set -u; set -o pipefail; source lib; source '$*'"
/bin/bash -l -c "set -e; set -u; set -o pipefail; source lib; source '$(root_path)/$*'"
}

function log_file() {
Expand Down

0 comments on commit 44eeefe

Please sign in to comment.