Skip to content

Commit

Permalink
GCE image load script now also accepts a docker image registry or a l…
Browse files Browse the repository at this point in the history
…ocal file (#27)

* Fixed gcloud no longer takes "gcloud docker";  node performance tuning

* Revised GCE image load script; added capability to load local file and docker registry; improved robustness

* Updating travis script

* Additional doc + test improvements
  • Loading branch information
bczoma authored and PhilippeKhalife committed Jul 3, 2019
1 parent 59f39c4 commit a37257f
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 115 deletions.
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ before_install:
- echo $GCP_KEY_FILE | base64 -d > ./keyfile
- gcloud auth activate-service-account -q $(jq -r .client_email keyfile) --key-file=./keyfile --project $(jq -r .project_id keyfile)
- rm ./keyfile
- gcloud auth configure-docker --quiet

install: true

script:
- echo "Testing solace image to gkr"
- echo "Testing solace image to GCR"
- cd scripts
- chmod 755 copy_solace_image_to_gkr.sh
- ./copy_solace_image_to_gkr.sh -u $SOLACE_STANDARD_DOCKER_URL_PARAMETER_VALUE | tee results
- export `grep SOLACE_IMAGE_URL results`
- export STANDARD_IMAGE_URL=$SOLACE_IMAGE_URL
- "export STANDARD_IMAGE_URL=\"$(cat results | awk -F location: '{printf $2}')\""
- gcloud container images describe $STANDARD_IMAGE_URL
- ./copy_solace_image_to_gkr.sh -u $SOLACE_EVAL_DOCKER_URL_PARAMETER_VALUE | tee results
- export `grep SOLACE_IMAGE_URL results`
- export EVAL_IMAGE_URL=$SOLACE_IMAGE_URL
- "export EVAL_IMAGE_URL=\"$(cat results | awk -F location: '{printf $2}')\""
- gcloud container images describe $EVAL_IMAGE_URL
- echo "Testing cluster create script"
- chmod 755 create_cluster.sh
- echo "Testing cluster create script with no perf tuning"
Expand All @@ -39,9 +40,9 @@ script:
- echo "Testing cluster create script with perf tuning"
- export TESTCLUSTERNAME2="sol-gke-travistest-$(date +%s)"
- ./create_cluster.sh -z us-central1-b,us-central1-c,us-central1-f -c $TESTCLUSTERNAME2 -m g1-small -i cos -p
- gcloud compute instances list --filter 'tags.items:$TESTCLUSTERNAME2' --format='table(name,zone,status)' | sed 1d $rpt
- gcloud compute instances list --format='table(name,zone,status,tags.items)' | grep "'$TESTCLUSTERNAME2'"
- command="sudo ls /etc/sysctl.d"
- list=`gcloud compute instances list --filter tags.items:$TESTCLUSTERNAME2 --format='table(name,zone,status)' | sed 1d $rpt`
- list=`gcloud compute instances list --format='table(name,zone,status,tags.items)' | grep "'$TESTCLUSTERNAME2'"`
- # Check if occurrences of 99-sysctl.conf and 98-solace-sysctl.conf equal
- a=`while read -r a b c ; do (gcloud compute ssh --ssh-flag="-T -o StrictHostKeyChecking=no" --zone $b $a -- "$command" &) ; done <<< "$list" ; sleep 2 ; wait` ; echo $a
- bash -c "if [[ `echo \"$a\" | grep -o 99 | wc -l` != `echo \"$a\" | grep -o 98 | wc -l` ]] ; then echo \"Occurrences of 99-sysctl.conf and 98-solace-sysctl.conf not equal\" ; exit 1 ; fi"
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ The docker image reference can be:
* The script can be executed from an installed Google Cloud SDK Shell or open a Google Cloud Shell from the Cloud Platform Console.

* If using Google Cloud SDK Shell, also setup following dependencies:
* docker, gcloud and kubectl installed
* docker and gcloud CLI installed
* use `gcloud init` to setup account locally
* proper Google Cloud permissions have been set: `container.clusterRoleBindings.create` permission is required
* [authenticate to the container registry](//cloud.google.com/container-registry/docs/advanced-authentication), running `gcloud auth configure-docker`

* If using the Cloud Shell from the Cloud Platform Console, it can be started in the browser from the red underlined icon in the upper right:

Expand All @@ -77,17 +78,26 @@ The docker image reference can be:
<br>
<br>

* In the shell paste the download URL of the Solace PubSub+ software message broker Docker image from [step 2](https://github.com/SolaceDev/solace-gke-quickstart/tree/SolaceDockerHubSupport#step-2-obtain-a-reference-to-the-docker-image-of-the-solace--pubsub-message-broker-to-be-deployed ).). As an alternative to using the download link you can also use load versions hosted remotely (if so, a .md5 file needs to be created in the same remote directory).
* Get and use the script:

```sh
wget https://raw.githubusercontent.com/SolaceProducts/solace-gke-quickstart/master/scripts/copy_solace_image_to_gkr.sh
chmod 755 copy_solace_image_to_gkr.sh
./copy_solace_image_to_gkr.sh -u <DOWNLOAD_URL>
chmod +x copy_solace_image_to_gkr.sh
# Note how the parameter is assigned through setting env for the script
SOLACE_IMAGE_REF=<solace-image-location> ./copy_solace_image_to_gkr.sh
```

`<solace-image-location>` can be one of the followings:
- name of a Docker image from a publicly available Docker image registry (default is `solace/solace-pubsub-standard:latest`)
- a Solace Docker image download URL obtained from the [Solace Downloads site](//solace.com/downloads/)
- a web server download URL - the corresponding `md5` file must be collocated with the Solace Docker image
- path to a Solace Docker image tar.gz file in the local file system

Run `./copy_solace_image_to_gkr.sh -h` for additional help.

<br>

* The script will end with showing a `SOLACE_IMAGE_URL` link required for [Step 5](https://github.com/SolaceDev/solace-gke-quickstart/tree/SolaceDockerHubSupport#step-5-use-google-cloud-sdk-or-cloud-shell-to-deploy-solace-message-broker-pods-and-service-to-that-cluster ). You can view the new entry on the Google Container Registry in the Cloud Platform Console:
* The script will end with showing the "GCR image location" required for [Step 5](https://github.com/SolaceDev/solace-gke-quickstart/tree/SolaceDockerHubSupport#step-5-use-google-cloud-sdk-or-cloud-shell-to-deploy-solace-message-broker-pods-and-service-to-that-cluster ). You can view the new entry on the Google Container Registry in the Cloud Platform Console:

![alt text](/images/google_container_registry.png "Google Container Registry")

Expand Down
208 changes: 106 additions & 102 deletions scripts/copy_solace_image_to_gkr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,111 +14,115 @@
# 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.

# The purpose of this script is to:
# - take a URL to a Solace VMR docker container
# - validate the container against known MD5
# - load the container to create a local instance
# - upload the instance into google container registery
# - clean up load docker

OPTIND=1 # Reset in case getopts has been used previously in the shell.

# Initialize our own variables:
solace_url=""

verbose=0

while getopts "u:" opt; do
case "$opt" in
u) solace_url=$OPTARG
;;
esac
done

shift $((OPTIND-1))
[ "$1" = "--" ] && shift

verbose=1
echo "`date` INFO: solace_url=$solace_url ,Leftovers: $@"

solace_directory=.

echo "###############################################################"
if [[ ${solace_url} == *"em.solace.com"* ]]; then
wget -q -O solace-redirect ${solace_url}
wget -q -O ${solace_directory}/solace-redirect ${solace_url} || echo "There has been an issue with downloading the redirect"
REAL_LINK=`egrep -o "https://[a-zA-Z0-9\.\/\_\?\=%]*" ${solace_directory}/solace-redirect`
LOAD_NAME="`echo $REAL_LINK | awk -v FS="(download/|?)" '{print $2}'`"
# a redirect link provided by solace
wget -O ${solace_directory}/solos.info -nv https://products.solace.com/download/${LOAD_NAME}_MD5
elif [[ ${solace_url} == *"solace.com/download"* ]]; then
REAL_LINK=${solace_url}
# the new download url
wget -O ${solace_directory}/solos.info -nv ${solace_url}_MD5
else
REAL_LINK=${solace_url}
# an already-existing load (plus its md5 file) hosted somewhere else (e.g. in an s3 bucket)
wget -O ${solace_directory}/solos.info -nv ${solace_url}.md5
fi

IFS=' ' read -ra SOLOS_INFO <<< `cat ${solace_directory}/solos.info`
MD5_SUM=${SOLOS_INFO[0]}
SolOS_LOAD=${SOLOS_INFO[1]}
if [ -z ${MD5_SUM} ]; then
echo "`date` ERROR: Missing md5sum for the Solace load" | tee /dev/stderr
exit 1
#
## Params:
# SOLACE_IMAGE_REF can be a Docker image name from an accessible registry, a download URL or a local file
SOLACE_IMAGE_REF="${SOLACE_IMAGE_REF:-solace/solace-pubsub-standard:latest}"
# GCR_HOST is the fully qualified hostname of the GCR server
GCR_HOST="${GCR_HOST:-gcr.io}"
# The GCR project, default is the current GCP project id
GCR_PROJECT="${GCR_PROJECT:-`gcloud info | tr -d '[]' | awk '/project:/ {print $2}'`}"
##
if [ "$#" -gt "0" ] ; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
# Provide help if needed
echo "Usage:
# First assign params to the env to be used by the script:
# SOLACE_IMAGE_REF defaults to solace/solace-pubsub-standard:latest from Docker Hub
[SOLACE_IMAGE_REF=<docker-repo-or-download-link>] \\
# GCR_HOST defaults to gcr.io
[GCR_HOST=<hostname>] \\
# GCR_PROJECT defaults to the current GCP project
[GCR_PROJECT=<project>] \\
copy_solace_image_to_gkr.sh
Check script inline comments for more details."
exit 1
else
## Parse legacy params:
OPTIND=1
while getopts "u:" opt; do
case "$opt" in
u)
SOLACE_IMAGE_REF=$OPTARG
;;
*)
echo "Invalid argument(s), check -h or --help"
exit 1
;;
esac
done
fi
fi
echo "`date` INFO: Reference md5sum is: ${MD5_SUM}"
echo "`date` INFO: Download from URL provided and validate"
wget -q -O ${solace_directory}/${SolOS_LOAD} ${REAL_LINK}
LOCAL_OS_INFO=`md5sum ${SolOS_LOAD}`
IFS=' ' read -ra SOLOS_INFO <<< ${LOCAL_OS_INFO}
LOCAL_MD5_SUM=${SOLOS_INFO[0]}
if [ ${LOCAL_MD5_SUM} != ${MD5_SUM} ]; then
echo "`date` ERROR: Possible corrupt Solace load, md5sum do not match" | tee /dev/stderr
##
echo "Using:"
echo "SOLACE_IMAGE_REF=$SOLACE_IMAGE_REF"
echo "GCR_HOST=$GCR_HOST"
echo "GCR_PROJECT=$GCR_PROJECT"
echo
echo "#############################################################"
# check pre-requisites gcloud and docker
command -v gcloud >/dev/null 2>&1 || { echo >&2 "'gcloud' must be installed, aborting."; exit 1; }
if ! docker images >/dev/null 2>&1 || ! service docker status | grep -o running >/dev/null ; then
echo "'docker' must be installed, running and accessible from current user."
exit 1
else
echo "`date` INFO: Successfully downloaded ${SolOS_LOAD}"
fi
echo "`date` INFO: LOAD DOCKER IMAGE INTO LOCAL REGISTRY"
echo "########################################################################"
if [ "`docker images "solace-*" -q`" ] ; then
echo "`date` INFO: Removing existing images first..."
docker rmi -f `docker images "solace-*" -q`
# Remove any existing Solace image from local docker registry
if [ "`docker images | grep solace-`" ] ; then
echo "Cleaning existing Solace images from local docker repo"
docker rmi -f `docker images | grep solace- | awk '{print $3}'` > /dev/null 2>&1
fi
docker load -i ${solace_directory}/${SolOS_LOAD}
local_repo=`docker images "solace-*" | grep solace`
echo "`date` INFO: Current docker images are:"
echo ${local_repo}
repoName=`echo $local_repo | awk '{print$1}'`
tag=`echo $local_repo | awk '{print$2}'`
imageId=`echo $local_repo | awk '{print$3}'`
echo "`date` INFO: PUSH SOLACE PUBSUB+ IMAGE INSTANCE INTO GOOGLE CONTAINER REGISTRY"
echo "##########################################################################################"
if [ -z "${DEVSHELL_PROJECT_ID}" ]; then
DEVSHELL_PROJECT_ID=`gcloud projects list | awk 'FNR>1 {print$1}'`
if [ "`gcloud projects list | awk 'END{print NR}'`" -gt "2" ]; then
echo "Detected following multiple GCP projects. Please run 'export DEVSHELL_PROJECT_ID=' set to the correct one and then rerun this script!" | tee /dev/stderr
echo "`gcloud projects list | awk '{print$1}'`"
exit 1
# Loading provided Solace image reference
echo "Trying to load ${SOLACE_IMAGE_REF} as Docker ref into local Docker registry..."
if ! docker pull ${SOLACE_IMAGE_REF} ; then
echo "Loading as Docker ref failed, retrying to load as local file..."
if ! docker load -i ${SOLACE_IMAGE_REF} ; then
echo "Loading as a local file failed, retrying as a download link"
if [[ ${SOLACE_IMAGE_REF} == *"solace.com/download"* ]]; then
MD5_URL=${SOLACE_IMAGE_REF}_MD5
else
MD5_URL=${SOLACE_IMAGE_REF}.md5
fi
wget -q -O solos.info -nv ${MD5_URL}
IFS=' ' read -ra SOLOS_INFO <<< `cat solos.info`
MD5_SUM=${SOLOS_INFO[0]}
SolOS_LOAD=${SOLOS_INFO[1]}
if [ -z ${MD5_SUM} ]; then
echo "Missing md5sum for the Solace load, tried ${SOLACE_IMAGE_REF}.md5 - exiting."
exit 1
fi
echo "Reference md5sum is: ${MD5_SUM}"
echo "Now downloading URL provided and validating"
wget -q -O ${SolOS_LOAD} ${SOLACE_IMAGE_REF}
## Check MD5
LOCAL_OS_INFO=`md5sum ${SolOS_LOAD}`
IFS=' ' read -ra SOLOS_INFO <<< ${LOCAL_OS_INFO}
LOCAL_MD5_SUM=${SOLOS_INFO[0]}
if [ -z "${MD5_SUM}" ] || [ "${LOCAL_MD5_SUM}" != "${MD5_SUM}" ]; then
echo "Possible corrupt Solace load, md5sum do not match - exiting."
exit 1
else
echo "Successfully downloaded ${SolOS_LOAD}"
fi
## Load the image tarball
docker load -i ${SolOS_LOAD}
rm solos.info ${SolOS_LOAD} # cleanup local files
fi
fi
docker tag ${imageId} gcr.io/${DEVSHELL_PROJECT_ID}/${repoName}:${tag}
gcloud docker -- push gcr.io/${DEVSHELL_PROJECT_ID}/${repoName}:${tag}
echo "`date` INFO: CLEANUP"
echo "##########################################"
docker rmi gcr.io/${DEVSHELL_PROJECT_ID}/${repoName}:${tag}
docker rmi ${imageId}
export SOLACE_IMAGE_URL=gcr.io/${DEVSHELL_PROJECT_ID}/${repoName}:${tag}
echo "`date` INFO: Record the image reference in the GCR you will need to for next steps"
echo "SOLACE_IMAGE_URL=${SOLACE_IMAGE_URL}"
# Determine image details
SOLACE_IMAGE_ID=`docker images | grep solace | awk '{print $3}'`
if [ -z "${SOLACE_IMAGE_ID}" ] ; then
echo "Could not load a valid Solace docker image - exiting."
exit 1
fi
echo "Loaded ${SOLACE_IMAGE_REF} to local docker repo"
SOLACE_IMAGE_NAME=`docker images | grep solace | awk '{split($0,a,"solace/"); print a[2]}' | awk '{print $1}'`
if [ -z $SOLACE_IMAGE_NAME ] ; then SOLACE_IMAGE_NAME=`docker images | grep solace | awk '{print $1}'`; fi
SOLACE_IMAGE_TAG=`docker images | grep solace | awk '{print $2}'`
SOLACE_GCR_IMAGE=${GCR_PROJECT}/${SOLACE_IMAGE_NAME}:${SOLACE_IMAGE_TAG}
# Tag and load to GCR now
docker_hub_solace=${SOLACE_IMAGE_REF}
docker_gcr_solace="${GCR_HOST}/${SOLACE_GCR_IMAGE}"
docker tag $SOLACE_IMAGE_ID "$docker_gcr_solace"
docker push "$docker_gcr_solace" || { echo "Push to GCR failed, ensure it is accessible and Docker is logged in with the correct user"; exit 1; }
echo "Success - GCR image location: $docker_gcr_solace"
2 changes: 1 addition & 1 deletion scripts/create_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ echo "`date` INFO: cluster_name=${cluster_name}, machine_type=${machine_type}, i
# multi-region bridge performance tuning
# arguments: $1=clustername
node_performance_tuning () {
list=`gcloud compute instances list --filter tags.items:$1 --format='table(name,zone,status)' | sed 1d $rpt`
list=`gcloud compute instances list --format='table(name,zone,status,tags.items)' | grep "'$1'"`
echo "List of nodes created:"
echo "$list"
echo 'Applying multi-region bridge performance tuning to nodes...'
Expand Down

0 comments on commit a37257f

Please sign in to comment.