+set_template_info() {
+
+ templates=`cat $config_file | docker run -rm -i -a stdin -a stdout $image ruby -e \
+ "require 'yaml'; puts YAML.load(STDIN.readlines.join)['templates']"`
+
+
+ arrTemplates=(${templates// / })
+ config_data=$(cat $config_file)
+
+ input="hack: true"
+
+
+ for template in "${arrTemplates[@]}"
+ do
+ [ ! -z $template ] && {
+ input="$input _FILE_SEPERATOR_ $(cat $template)"
+ }
+ done
+
+ # we always want our config file last so it takes priority
+ input="$input _FILE_SEPERATOR_ $config_data"
+
+ read -r -d '' env_ruby << 'RUBY'
+ require 'yaml'
+
+ input=STDIN.readlines.join
+ env = {}
+ input.split('_FILE_SEPERATOR_').each do |yml|
+ yml.strip!
+ begin
+ env.merge!(YAML.load(yml)['env'] || {})
+ rescue => e
+ puts yml
+ p e
+ end
+ end
+ puts env.map{|k,v| "-e #{k}=#{v}" }.join(" ")
+RUBY
+
+ env=`exec echo "$input" | docker run -rm -i -a stdin -a stdout $image ruby -e "$env_ruby"`
+ echo "Calculated ENV: $env"
+}
+