Skip to content

Commit

Permalink
Support using other variables in variable files.
Browse files Browse the repository at this point in the history
Fixes #28.
  • Loading branch information
Arik Kfir committed Dec 3, 2017
1 parent 60fd910 commit 154b012
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion examples/run-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ echo "Building..." >&2
$(dirname $0)/../.buildkite/build.sh ${VERSION} 2>&1 1>> ./.build.log
[[ $? != 0 ]] && echo "Build failed! (inspect '.build.log' for details)" >&2 && exit 1

source $(dirname $0)/../deployster.sh --no-pull $@
DVERSION="${VERSION}" source \
$(dirname $0)/../deployster.sh --no-pull \
--var bar="hi!" \
--var-file vars.1.yaml \
--var-file vars.2.yaml \
$@
1 change: 1 addition & 0 deletions examples/vars.1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo: bar-is-{{ bar }}
1 change: 1 addition & 0 deletions examples/vars.2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chu: foo-is-{{ foo }}
10 changes: 6 additions & 4 deletions src/deployster.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def __init__(self) -> None:

def add_file(self, path: str) -> None:
with open(path, 'r') as stream:
if path.endswith('.json'):
source = json.loads(stream)
else:
source = yaml.load(stream)
environment = jinja2.Environment(undefined=jinja2.StrictUndefined)
try:
source = yaml.load(environment.from_string(stream.read()).render(self.data))
except UndefinedError as e:
raise UserError(f"error in '{path}': {e.message}") from e
util.merge_into(self._data, source)

def add_variable(self, key: str, value: str) -> None:
Expand Down Expand Up @@ -285,6 +286,7 @@ def __init__(self, context: Context, manifest_files: Sequence[Path]) -> None:
}
for manifest_file in manifest_files:
with open(manifest_file, 'r') as f:
# TODO: load JSON manifests too (no reason why not, just use 'json.loads')
environment = jinja2.Environment(undefined=jinja2.StrictUndefined)
try:
manifest = yaml.load(environment.from_string(f.read()).render(context.data))
Expand Down

0 comments on commit 154b012

Please sign in to comment.