You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
4.6 KiB
Bash
186 lines
4.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Copyright 2019 AT&T Intellectual Property. All other rights reserved.
|
|
#
|
|
# 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.
|
|
|
|
DEFAULT_TERM_OPTS=' '
|
|
# Set an interactive mode only if there is a TTY available.
|
|
test -t 1 && test -t 0 && DEFAULT_TERM_OPTS='-it'
|
|
: ${TERM_OPTS:=${DEFAULT_TERM_OPTS}}
|
|
|
|
# Python YAML module required to read versions.yaml
|
|
if grep -iq suse /etc/os-release; then
|
|
rpm -q python3-pyaml --quiet || zypper --non-interactive install python3-pyaml
|
|
else
|
|
dpkg -s python3-yaml &> /dev/null || apt -y install python3-yaml
|
|
fi
|
|
|
|
ENV_FILE=$(mktemp)
|
|
trap "{ rm -f $ENV_FILE; }" EXIT
|
|
|
|
# prepare docker environment file
|
|
cat > $ENV_FILE << EOF
|
|
PEGLEG_PASSPHRASE=${PEGLEG_PASSPHRASE:-password123}
|
|
PEGLEG_SALT=${PEGLEG_SALT:-password123}
|
|
|
|
OS_AUTH_URL=${OS_AUTH_URL:-http://keystone-api.ucp.svc.cluster.local:5000/v3}
|
|
OS_PASSWORD=${OS_PASSWORD:-password123}
|
|
OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-default}
|
|
OS_PROJECT_NAME=${OS_PROJECT_NAME:-service}
|
|
OS_USERNAME=${OS_USERNAME:-shipyard}
|
|
OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-default}
|
|
OS_IDENTITY_API_VERSION=${OS_IDENTITY_API_VERSION:-3}
|
|
EOF
|
|
|
|
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ >/dev/null 2>&1 && pwd )"
|
|
|
|
USER=$(id -u)
|
|
GROUP=$(id -g)
|
|
|
|
# Key/value lookups from manifests
|
|
manifests_lookup(){
|
|
|
|
local file="$1"
|
|
local schema="$2"
|
|
local mdata_name="$3"
|
|
local key_path="$4"
|
|
local oper="$5"
|
|
local allow_fail="$6"
|
|
|
|
FAIL=false
|
|
RESULT=`python3 -c "
|
|
|
|
import yaml,sys
|
|
y = yaml.load_all(open('$file'))
|
|
for x in y:
|
|
if x.get('schema') == '$schema':
|
|
if x['metadata']['name'] == '$mdata_name':
|
|
if isinstance(x$key_path,list):
|
|
if '$oper' == 'get_size':
|
|
print(len(x$key_path))
|
|
break
|
|
else:
|
|
for i in x$key_path:
|
|
print(i)
|
|
break
|
|
else:
|
|
if '$oper' == 'dict_keys':
|
|
print(' '.join(x$key_path.keys()))
|
|
break
|
|
else:
|
|
print(x$key_path)
|
|
break
|
|
else:
|
|
sys.exit(1)" 2>&1` || FAIL=true
|
|
|
|
if [[ $FAIL = true ]] && [[ $allow_fail != true ]]; then
|
|
echo "error: Lookup failed for schema '$schema', \
|
|
metadata.name '$mdata_name', key path '$key_path'" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
versions_lookup() {
|
|
manifests_lookup "${REPO_DIR}/global/software/config/versions.yaml" \
|
|
'pegleg/SoftwareVersions/v1' \
|
|
'software-versions' "$1"
|
|
IMAGE_URL=$RESULT
|
|
}
|
|
|
|
|
|
help() {
|
|
echo -n "Usage: airship <pegleg|promenade|shipyard> [OPTION]...
|
|
|
|
Examples:
|
|
tools/airship pegleg site -r /target collect airsloop -s collect
|
|
tools/airship promenade generate-certs -o /target/certs /target/collect/*.yaml
|
|
tools/airship promenade build-all -o /target/bundle /target/collect/*.yaml /target/certs/*.yaml
|
|
tools/airship shipyard get actions
|
|
"
|
|
}
|
|
|
|
pegleg() {
|
|
|
|
versions_lookup "['data']['images']['ucp']['pegleg']['pegleg']"
|
|
|
|
cat >> $ENV_FILE << EOF
|
|
USER=pegleg
|
|
EOF
|
|
|
|
docker run --rm --net=host $TERM_OPTS \
|
|
-u "${USER}:${GROUP}" \
|
|
-w /target \
|
|
-v $(pwd):/target \
|
|
-v ${HOME}/.ssh:/target/.ssh \
|
|
--env-file $ENV_FILE \
|
|
$IMAGE_URL $@
|
|
}
|
|
|
|
promenade() {
|
|
|
|
versions_lookup "['data']['images']['ucp']['promenade']['promenade']"
|
|
|
|
# support proxy for pulling k8s binary
|
|
cat >> $ENV_FILE << EOF
|
|
http_proxy=${http_proxy:-}
|
|
https_proxy=${https_proxy:-}
|
|
no_proxy=${no_proxy:-}
|
|
HTTP_PROXY=${HTTP_PROXY:-}
|
|
HTTPS_PROXY=${HTTPS_PROXY:-}
|
|
NO_PROXY=${NO_PROXY:-}
|
|
# Promenade specific variables for downloading hyperkube image to generate genesis.sh
|
|
PROMENADE_TMP=/tmp
|
|
PROMENADE_TMP_LOCAL=/tmp
|
|
EOF
|
|
|
|
docker run --rm --net=host $TERM_OPTS \
|
|
-u "${USER}:${GROUP}" \
|
|
-w /target \
|
|
-v $(pwd):/target \
|
|
-v /tmp:/tmp \
|
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
--env-file $ENV_FILE \
|
|
$IMAGE_URL $@
|
|
}
|
|
|
|
shipyard() {
|
|
|
|
versions_lookup "['data']['images']['ucp']['shipyard']['shipyard']"
|
|
|
|
SHIPYARD_IMAGE=$RESULT
|
|
docker run --rm --net=host $TERM_OPTS \
|
|
-u "${USER}:${GROUP}" \
|
|
-w /target \
|
|
-v $(pwd):/target \
|
|
--env-file $ENV_FILE \
|
|
$IMAGE_URL $@
|
|
}
|
|
|
|
|
|
case "$1" in
|
|
'pegleg')
|
|
pegleg $@
|
|
;;
|
|
'promenade')
|
|
promenade $@
|
|
;;
|
|
'shipyard')
|
|
shift;
|
|
shipyard $@
|
|
;;
|
|
*) help
|
|
exit 1
|
|
;;
|
|
esac
|