Skip to content

Commit

Permalink
Added more options to the upload_harbor script and related documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bczoma committed Jun 10, 2019
1 parent 9939af3 commit bbfbf7b
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 25 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,39 @@ cd solace-pks # repo root directory

**Hint:** You may skip the rest of this step if not using a private Docker image registry (Harbor). The free PubSub+ Standard Edition is available from the [public Docker Hub registry](//hub.docker.com/r/solace/solace-pubsub-standard/tags/ ), the image reference is `solace/solace-pubsub-standard:<TagName>`.

To get the Solace message broker Docker image, go to the Solace Developer Portal and download the Solace PubSub+ software message broker as a **docker** image or obtain your version from Solace Support.
To get the Solace message broker Docker image URL, go to the Solace Developer Portal and download the Solace PubSub+ software message broker as a **docker** image or obtain your version from Solace Support.

| PubSub+ Standard<br/>Docker Image | PubSub+ Enterprise Evaluation Edition<br/>Docker Image
| :---: | :---: |
| Free, up to 1k simultaneous connections,<br/>up to 10k messages per second | 90-day trial version, unlimited |
| [Download Standard docker image](http://dev.solace.com/downloads/ ) | [Download Evaluation docker image](http://dev.solace.com/downloads#eval ) |

To load the Solace Docker image into a docker registry, follow the general steps below; for specifics, consult the user guide of the registry you are using.
If using Harbor for private Docker registry, use the `upload_harbor.sh` script provided in the script directory. You can pass the Solace image reference as a public Docker image location or a Http download Url (the Solace image `md5` checksum must also be available from the Http download Url). Also provide the Harbor host and project names and additionally, if using signed images set the `DOCKER_CONTENT_TRUST=1` and `DOCKER_CONTENT_TRUST_SERVER` environment variables. Check the script inline comments for defaults.

Note: ensure the project with a user configured exists in Harbor, Docker is logged in to the Harbor server as user, as well as Docker Notary is configured for Harbor. Consult your Harbor documentation for details.

```sh
cd ~/workspace/solace-pks/scripts
# Define variables up-front to be passed to the "upload_harbor" script:
[SOLACE_IMAGE_URL=<docker-repo-or-download-link>] \
HARBOR_HOST=<hostname> \
[HARBOR_PROJECT=<project>] \
[DOCKER_CONTENT_TRUST=[0|1] \
[DOCKER_CONTENT_TRUST_SERVER=<full-server-url-with-port>] \
upload_harbor.sh
## Example-1: upload the latest from Docker Hub to Harbor
# HARBOR_HOST=<harbor-server> ./upload_harbor.sh
## Example-2: upload from a Http Url to Harbor
# HARBOR_HOST=<harbor-server> \
# SOLACE_IMAGE_URL=https://<server-location>/solace-pubsub-standard-9.1.0.118-docker.tar.gz ./upload_harbor.sh
```
To load the Solace Docker image into other private Docker registry, follow the general steps below; for specifics, consult the documentation of the registry you are using.
* Prerequisite: local installation of [Docker](//docs.docker.com/get-started/ ) is required
* First load the image to the local docker registry:
```sh
# Option a): If you have a tar.gz Docker image file
# Option a): If you have a local tar.gz Docker image file
sudo docker load -i <solace-pubsub-XYZ-docker>.tar.gz
# Option b): You can use the public Solace Docker image from Docker Hub
sudo docker pull solace/solace-pubsub-standard:latest # or specific <TagName>
Expand Down
107 changes: 85 additions & 22 deletions scripts/upload_harbor.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,96 @@
#!/bin/bash
set -e

SOLACE_EDITION="${SOLACE_EDITION:-standard}"
DOCKER_SOLACE_TAG="${DOCKER_SOLACE_TAG:-latest}"
set -e # fail out in case of error encountered
## Params:
# SOLACE_IMAGE_URL can be a Docker repo reference or a download URL
SOLACE_IMAGE_URL="${SOLACE_IMAGE_URL:-solace/solace-pubsub-standard:latest}"
# HARBOR_HOST is the fully qualified hostname of the Harbor server
HARBOR_HOST="$HARBOR_HOST"
# The Harbor project, default is "solace"
HARBOR_PROJECT="${HARBOR_PROJECT:-solace}"
DOCKER_CONTENT_TRUST="${DOCKER_CONTENT_TRUST:-0}"
# DOCKER_CONTENT_TRUST must be set to 1 if using signed images
export DOCKER_CONTENT_TRUST="${DOCKER_CONTENT_TRUST:-0}"
# DOCKER_CONTENT_TRUST_SERVER - use it for signed images, specify it if not https://${HARBOR_HOST}:4443
export DOCKER_CONTENT_TRUST_SERVER="${DOCKER_CONTENT_TRUST_SERVER:-https://${HARBOR_HOST}:4443}"

echo "SOLACE_EDITION=$SOLACE_EDITION"
echo "DOCKER_SOLACE_TAG=$DOCKER_SOLACE_TAG"
##
# Provide help if needed
if [ "$#" -gt "0" ] ; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "Usage (define variables to be used for the script first as here):
[SOLACE_IMAGE_URL=<docker-repo-or-download-link>] \\
HARBOR_HOST=<hostname> \\
[HARBOR_PROJECT=<project>] \\
[DOCKER_CONTENT_TRUST=[0|1] \\
[DOCKER_CONTENT_TRUST_SERVER=<full-server-url-with-port>] \\
upload_harbor.sh
Check script inline comments for more details."
exit 1
else
echo "Invalid argument(s), check -h or --help"
exit 1
fi
fi
# Check for minimum params
if [[ -z "$HARBOR_HOST" ]]; then
>&2 echo "HARBOR_HOST must be defined, cannot push image to Harbor"
exit 1
fi
echo "Using:"
echo "SOLACE_IMAGE_URL=$SOLACE_IMAGE_URL"
echo "HARBOR_HOST=$HARBOR_HOST"
echo "HARBOR_PROJECT=$HARBOR_PROJECT"
echo "DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST"
echo "DOCKER_CONTENT_TRUST_SERVER=$DOCKER_CONTENT_TRUST_SERVER"

echo
echo "#############################################################"
echo "Pushing solace-pubsub-${SOLACE_EDITION} to harbor (${HARBOR_HOST}/${HARBOR_PROJECT})"
echo

if [[ -n "$HARBOR_HOST" ]]; then
docker_hub_solace="solace/solace-pubsub-${SOLACE_EDITION}:${DOCKER_SOLACE_TAG}"
docker_harbor_solace="${HARBOR_HOST}/${HARBOR_PROJECT}/solace-pubsub-${SOLACE_EDITION}:${DOCKER_SOLACE_TAG}"

DOCKER_CONTENT_TRUST=0 docker pull "$docker_hub_solace"
docker tag "$docker_hub_solace" "$docker_harbor_solace"
docker push "$docker_harbor_solace"
else
>&2 echo "HARBOR_HOST must be defined, cannot push image to Harbor"
exit 1
# Remove any existing Solace image from local docker registry
if [ "`docker images | grep solace-`" ] ; then
echo "Removing existing Solace images from local docker repo"
docker rmi -f `docker images | grep solace- | awk '{print $3}'` > /dev/null 2>&1
fi
# Loading provided Solace image reference
echo "Trying to load ${SOLACE_IMAGE_URL} into local Docker registry:"
if [ -z "`DOCKER_CONTENT_TRUST=0 docker pull ${SOLACE_IMAGE_URL}`" ] ; then
echo "Found that ${SOLACE_IMAGE_URL} was not a docker registry uri, retrying if it is a download link"
wget -q -O solos.info -nv ${SOLACE_IMAGE_URL}.md5
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 - exiting."
exit 1
fi
echo "Reference md5sum is: ${MD5_SUM}"
echo "Now downloading URL provided and validating"
wget -q -O ${SolOS_LOAD} ${SOLACE_IMAGE_URL}
## 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}
fi
# 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_URL} 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_HARBOR_IMAGE=${HARBOR_PROJECT}/${SOLACE_IMAGE_NAME}:${SOLACE_IMAGE_TAG}
# Tag and load to Harbor now
docker_hub_solace=${SOLACE_IMAGE_URL}
docker_harbor_solace="${HARBOR_HOST}/${SOLACE_HARBOR_IMAGE}"
docker tag $SOLACE_IMAGE_ID "$docker_harbor_solace"
docker push "$docker_harbor_solace" || { echo "Push to Harbor failed, ensure it is accessible and Docker is logged in with the correct user"; exit 1; }
echo "Success - Harbor image location: $docker_harbor_solace"

0 comments on commit bbfbf7b

Please sign in to comment.