From 19ab694d8ad5dad9bfc7d43dba14d3ff46700389 Mon Sep 17 00:00:00 2001 From: Huy Huynh Date: Mon, 9 Jul 2018 10:43:20 -0700 Subject: [PATCH] Add utiliti for generating magic schema (#158) --- marketplace/deployer_util/magic_schema.sh | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 marketplace/deployer_util/magic_schema.sh diff --git a/marketplace/deployer_util/magic_schema.sh b/marketplace/deployer_util/magic_schema.sh new file mode 100755 index 00000000..fcf3c0e2 --- /dev/null +++ b/marketplace/deployer_util/magic_schema.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +for i in "$@" +do +case $i in + --deployer=*) + deployer="${i#*=}" + shift + ;; + *) + echo "Unrecognized flag: $i" + exit 1 + ;; +esac +done + +[[ -z "$deployer" ]] && >&2 echo "--deployer required" && exit 1 + +name_key="$(/bin/extract_schema_key.py --type NAME)" +namespace_key="$(/bin/extract_schema_key.py --type NAMESPACE)" + +# Provision resources with magic name and namespaces. +# Provisioned manifests are inserted into the original schema +# under top-level __manifests__ field. +printf '{%s: "m4g1cn8m3", %s: "m4g1cn8m32p4c3"}' "${name_key}" "${namespace_key}" \ + | /bin/provision.py --values_file=- --deployer_image="${deployer}" \ + | /bin/set_app_labels.py --manifests=- --dest=- --name="m4g1cn8m3" --namespace="m4g1cn8m32p4c3" \ + | /bin/yaml2json \ + | jq -s . \ + | jq '{"__manifests__": .}' \ + | jq -s '.[0] * .[1]' <(cat /data/schema.yaml | /bin/yaml2json) - \ + | /bin/json2yaml