Use Shipyard Docker Container for Tools Scripts
We will move away from installation of shipyard CLI/client binaries and will make use of the shipyard docker container instead for our CI/CD integration environment. Change-Id: I253cbc1e2f9310b9c11195e1c68b97ee8d0efead
This commit is contained in:
parent
f7d02238c3
commit
8db6e6e7b5
@ -43,27 +43,11 @@ fi
|
||||
# Define Variables
|
||||
collection=$1
|
||||
directory=$2
|
||||
namespace="${namespace:-ucp}"
|
||||
|
||||
# Clone shipyard repository if it does not exists
|
||||
if [[ ! -d shipyard ]]; then
|
||||
git clone --depth=1 https://github.com/att-comdev/shipyard.git
|
||||
fi
|
||||
|
||||
# Set up Genesis host with the Shipyard Client
|
||||
# This will allow us to use the Shipyard CLI
|
||||
sudo apt install python3-pip -y
|
||||
sudo pip3 install --upgrade pip
|
||||
cd shipyard && sudo pip3 install -r requirements.txt
|
||||
sudo python3 setup.py install
|
||||
|
||||
# Export Environment Variables
|
||||
export OS_USER_DOMAIN_NAME="${OS_USER_DOMAIN_NAME:-default}"
|
||||
export OS_PROJECT_DOMAIN_NAME="${OS_PROJECT_DOMAIN_NAME:-default}"
|
||||
export OS_PROJECT_NAME="${OS_PROJECT_NAME:-service}"
|
||||
export OS_USERNAME="${OS_USERNAME:-shipyard}"
|
||||
export OS_PASSWORD="${OS_PASSWORD:-password}"
|
||||
export OS_AUTH_URL="${OS_AUTH_URL:-http://keystone.${namespace}.svc.cluster.local:80/v3}"
|
||||
# Get the path of the directory where the script is located
|
||||
# Source Base Docker Command
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd ${DIR} && source shipyard_docker_base_command.sh
|
||||
|
||||
# The directory will contain all the .yaml files with Drydock, Promenade,
|
||||
# Armada, and Divingbell configurations. It will also contain all the
|
||||
@ -75,7 +59,9 @@ export OS_AUTH_URL="${OS_AUTH_URL:-http://keystone.${namespace}.svc.cluster.loca
|
||||
# Note that we will also make use of the '--replace' option so that the
|
||||
# script can be executed multiple times to replace existing collection
|
||||
echo -e "Loading YAMLs as named collection..."
|
||||
shipyard create configdocs ${collection} --replace --directory=${directory}
|
||||
|
||||
${base_docker_command} -v ${directory}:/target ${SHIPYARD_IMAGE} \
|
||||
create configdocs ${collection} --replace --directory=/target
|
||||
|
||||
# Following the creation of a configdocs collection in the Shipyard buffer,
|
||||
# the configdocs must be committed before Shipyard is able to use them as
|
||||
@ -84,7 +70,4 @@ shipyard create configdocs ${collection} --replace --directory=${directory}
|
||||
# Deckhand when 'commit configdocs' command is executed. Shipyard will
|
||||
# only mark the revision as committed if the validations are successful
|
||||
echo -e "Committing Configdocs..."
|
||||
shipyard commit configdocs
|
||||
|
||||
# Exit the script
|
||||
exit 0
|
||||
${base_docker_command} ${SHIPYARD_IMAGE} commit configdocs
|
||||
|
@ -39,6 +39,11 @@ run_action () {
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
|
||||
# Get the path of the directory where the script is located
|
||||
# Source Base Docker Command
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd ${DIR} && source shipyard_docker_base_command.sh
|
||||
|
||||
# Execute action
|
||||
echo -e "Execute ${action} Dag...\n"
|
||||
|
||||
@ -46,9 +51,9 @@ run_action () {
|
||||
# to be passed in while redeploy_server requires user to indicate which
|
||||
# server to redeploy
|
||||
if ! [[ ${server} ]] && [[ ${action} ]]; then
|
||||
shipyard create action ${action}
|
||||
${base_docker_command} ${SHIPYARD_IMAGE} create action ${action}
|
||||
elif [[ ${action} == 'redeploy_server' && ${server} ]]; then
|
||||
shipyard create action redeploy_server --param="server-name=${server}"
|
||||
${base_docker_command} ${SHIPYARD_IMAGE} create action redeploy_server --param="server-name=${server}"
|
||||
else
|
||||
echo "Invalid Input!"
|
||||
exit 1
|
||||
@ -69,18 +74,37 @@ run_action () {
|
||||
# is included here for information only.
|
||||
#
|
||||
# Print current list of actions in Shipyard
|
||||
shipyard get actions
|
||||
${base_docker_command} ${SHIPYARD_IMAGE} get actions
|
||||
|
||||
# Retrieve the ID of the action that is currently being executed
|
||||
# We will attempt to fetch the action ID for 3 times
|
||||
echo -e "Retrieving Action ID...\n"
|
||||
action_id=`shipyard get actions | grep ${action} | grep -i Processing | awk '{print $2}'`
|
||||
action_id=`${base_docker_command} ${SHIPYARD_IMAGE} get actions | grep ${action} | grep -i Processing | awk '{print $2}'`
|
||||
|
||||
if ! [[ ${action_id} ]]; then
|
||||
echo "Unable to Retrieve Action ID!"
|
||||
exit 1
|
||||
else
|
||||
echo "The Action ID is" ${action_id}
|
||||
fi
|
||||
# Initialize variables
|
||||
retrieve_shipyard_action_counter=0
|
||||
retrieve_shipyard_action_limit=2
|
||||
|
||||
while [[ $retrieve_shipyard_action_counter -le ${retrieve_shipyard_action_limit} ]];
|
||||
do
|
||||
if [[ ${action_id} ]]; then
|
||||
echo -e "The Action ID is" ${action_id}
|
||||
break
|
||||
|
||||
elif [[ $retrieve_shipyard_action_counter == ${retrieve_shipyard_action_limit} ]]; then
|
||||
echo -e "Failed to Retrieve Action ID!"
|
||||
exit 1
|
||||
|
||||
else
|
||||
echo -e "Unable to Retrieve Action ID!"
|
||||
echo -e "Retrying in 30 seconds..."
|
||||
sleep 30
|
||||
|
||||
action_id=`${base_docker_command} ${SHIPYARD_IMAGE} get actions | grep ${action} | grep -i Processing | awk '{print $2}'`
|
||||
|
||||
((retrieve_shipyard_action_counter ++))
|
||||
fi
|
||||
done
|
||||
|
||||
# Initialize 'action_lifecycle' to 'Pending'
|
||||
action_lifecycle="Pending"
|
||||
@ -91,8 +115,8 @@ run_action () {
|
||||
while true;
|
||||
do
|
||||
# Get Current State of Action Lifecycle
|
||||
describe_action=`shipyard describe ${action_id}`
|
||||
action_lifecycle=`echo ${describe_action} | awk '{print $6}'`
|
||||
describe_action=`${base_docker_command} ${SHIPYARD_IMAGE} describe ${action_id}`
|
||||
action_lifecycle=`echo ${describe_action} | awk '{print $29}'`
|
||||
|
||||
if [[ $action_lifecycle == "Complete" ]]; then
|
||||
echo -e '\nSuccessfully performed' ${action}
|
||||
@ -127,12 +151,5 @@ run_action () {
|
||||
fi
|
||||
}
|
||||
|
||||
# Note that we will need to execute the deckhand_load_yaml
|
||||
# script first before the deploy_site script
|
||||
# Check to ensure that the Shipyard CLI has been installed on
|
||||
# the Genesis host during the deckhand YAML load phase. Exit
|
||||
# script if Shipyard CLI is not installed.
|
||||
command -v shipyard >/dev/null 2>&1 || { echo >&2 "Please install Shipyard CLI before executing the script."; exit 1; }
|
||||
|
||||
# Calls 'run_action' function
|
||||
run_action "${@}"
|
||||
|
@ -29,35 +29,21 @@ set -ex
|
||||
# is not available, the user will need to ensure that the /etc/hosts file is
|
||||
# properly updated before running the script.
|
||||
|
||||
# Define Variables
|
||||
#
|
||||
# NOTE: User will need to set up the required environment variables
|
||||
# before executing this script if they differ from the default values.
|
||||
#
|
||||
namespace="${namespace:-ucp}"
|
||||
SHIPYARD_IMAGE="${SHIPYARD_IMAGE:-quay.io/attcomdev/shipyard:latest}"
|
||||
|
||||
# Define Base Docker Command
|
||||
# NOTE: We will mount the current directory so that any directories
|
||||
# would be relative to that
|
||||
# NOTE: We will map the host directory to '/home/shipyard/host' on
|
||||
# the Shipyard docker container
|
||||
base_docker_command=$(cat << EndOfCommand
|
||||
sudo docker run
|
||||
-e OS_AUTH_URL=${OS_AUTH_URL:-http://keystone.${namespace}.svc.cluster.local:80/v3}
|
||||
-e OS_USERNAME=${OS_USERNAME:-shipyard}
|
||||
-e OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-default}
|
||||
-e OS_PASSWORD=${OS_PASSWORD:-password}
|
||||
-e OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-default}
|
||||
-e OS_PROJECT_NAME=${OS_PROJECT_NAME:-service}
|
||||
--rm --net=host
|
||||
-v $(pwd):/home/shipyard/host/
|
||||
EndOfCommand
|
||||
)
|
||||
# Get the path of the directory where the script is located
|
||||
# Source Base Docker Command
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd ${DIR} && source shipyard_docker_base_command.sh
|
||||
|
||||
# Execute Shipyard CLI
|
||||
#
|
||||
# NOTE: We will mount the current directory so that any directories
|
||||
# would be relative to that
|
||||
#
|
||||
# NOTE: We will map the host directory to '/home/shipyard/host' on
|
||||
# the Shipyard docker container
|
||||
#
|
||||
# We will pass all arguments in and the Shipyard CLI will perform
|
||||
# the actual validation and execution. Exceptions will also be
|
||||
# handled by the Shipyard CLI as this is meant to be a thin wrapper
|
||||
# script
|
||||
${base_docker_command} ${SHIPYARD_IMAGE} $@
|
||||
${base_docker_command} -v $(pwd):/home/shipyard/host ${SHIPYARD_IMAGE} $@
|
||||
|
36
tools/shipyard_docker_base_command.sh
Normal file
36
tools/shipyard_docker_base_command.sh
Normal file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2018 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.
|
||||
|
||||
# Define Variables
|
||||
#
|
||||
# NOTE: User will need to set up the required environment variables
|
||||
# before executing this script if they differ from the default values.
|
||||
#
|
||||
NAMESPACE="${NAMESPACE:-ucp}"
|
||||
SHIPYARD_IMAGE="${SHIPYARD_IMAGE:-quay.io/attcomdev/shipyard:latest}"
|
||||
|
||||
# Define Base Docker Command
|
||||
base_docker_command=$(cat << EndOfCommand
|
||||
sudo docker run -t --rm --net=host
|
||||
-e http_proxy=${HTTP_PROXY}
|
||||
-e https_proxy=${HTTPS_PROXY}
|
||||
-e OS_AUTH_URL=${OS_AUTH_URL:-http://keystone.${NAMESPACE}.svc.cluster.local:80/v3}
|
||||
-e OS_USERNAME=${OS_USERNAME:-shipyard}
|
||||
-e OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-default}
|
||||
-e OS_PASSWORD=${OS_PASSWORD:-password}
|
||||
-e OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-default}
|
||||
-e OS_PROJECT_NAME=${OS_PROJECT_NAME:-service}
|
||||
EndOfCommand
|
||||
)
|
Loading…
Reference in New Issue
Block a user