-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b87832
commit d9536a1
Showing
2 changed files
with
35 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,20 +1,47 @@ | ||
#! /usr/bin/env sh | ||
#! /usr/bin/env bash | ||
|
||
nomad_token=$1 | ||
nomad_address=$2 | ||
nomad_job_file_path=$3 | ||
replaced_nomad_job_file_path=/tmp/nomad-deploy/jobs/$(basename "$3") | ||
# additional_vars=$(echo -n "$4" | tr -d '\n') | ||
additional_vars=$4 | ||
|
||
produce_replaced_nomad_file() { | ||
# Make the temporary directory and create the new job file | ||
mkdir -p /tmp/nomad-deploy/jobs | ||
touch "$replaced_nomad_job_file_path" | ||
if [[ $additional_vars == "" ]] | ||
then | ||
echo 'No additional vars found' | ||
# Just copy the job file straight across, no replacement of env vars | ||
cat "$nomad_job_file_path" > "$replaced_nomad_job_file_path" | ||
else | ||
local additional_vars_array=("$additional_vars") | ||
local keys_to_replace=() | ||
for pair in ${additional_vars_array[*]} | ||
do | ||
# collect the keys_to_replace of each additional var in an array | ||
keys_to_replace+=("\$${pair%=*}") | ||
done | ||
# replace the contents of the job file with the required env vars | ||
envsubst "${keys_to_replace[*]}" > "$replaced_nomad_job_file_path" < "$nomad_job_file_path" | ||
fi | ||
} | ||
|
||
if [ -f "$nomad_job_file_path" ]; then | ||
echo "$nomad_job_file_path exists" | ||
echo would run: | ||
echo nomad job run "$nomad_job_file_path" "-address=$nomad_address" "-token=$nomad_token" | ||
export "${additional_vars?}" | ||
produce_replaced_nomad_file | ||
echo with additional vars: | ||
echo "$additional_vars" | ||
echo job file with replaced vars: | ||
cat "$replaced_nomad_job_file_path" | ||
echo would run: | ||
echo nomad job run "$replaced_nomad_job_file_path" "-address=$nomad_address" "-token=$nomad_token" | ||
else | ||
echo "$nomad_job_file_path does not exist" | ||
echo ls: | ||
ls | ||
exit 1 | ||
fi | ||
|
||
|