Adding registry flag 54/9954/2
authorbeierlm <mark.beierl@canonical.com>
Thu, 5 Nov 2020 22:04:05 +0000 (17:04 -0500)
committerbeierlm <mark.beierl@canonical.com>
Fri, 6 Nov 2020 21:56:27 +0000 (16:56 -0500)
Allow alternate registry to be supplied, with optional credentials.

If registry is just host:port/path, no credentials will be used
If user:pass@host:port/path, user and pass will be supplied as
credentials.

Change-Id: I8acf67b2916fea059fb306782388910e543b4046
Signed-off-by: beierlm <mark.beierl@canonical.com>
installers/charmed_install.sh
installers/full_install_osm.sh

index f0f729e..b56ed16 100755 (executable)
@@ -18,6 +18,8 @@
 K8S_CLOUD_NAME="k8s-cloud"
 KUBECTL="microk8s.kubectl"
 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
+PATH=/snap/bin:${PATH}
+
 function check_arguments(){
     while [ $# -gt 0 ] ; do
         case $1 in
@@ -29,6 +31,7 @@ function check_arguments(){
             --microstack) MICROSTACK=y ;;
             --ha) BUNDLE="cs:osm-ha" ;;
             --tag) TAG="$2" ;;
+            --registry) REGISTRY_INFO="$2" ;;
         esac
         shift
     done
@@ -43,7 +46,7 @@ function install_snaps(){
         mkdir -p ~/.kube
         sudo chown -f -R `whoami` ~/.kube
         KUBEGRP="microk8s"
-        microk8s status --wait-ready
+        sg ${KUBEGRP} -c "microk8s status --wait-ready"
     else
         KUBECTL="kubectl"
         sudo snap install kubectl --classic
@@ -195,6 +198,27 @@ function wait_for_port(){
 }
 
 function deploy_charmed_osm(){
+    if [ -v REGISTRY_INFO ] ; then
+        registry_parts=(${REGISTRY_INFO//@/ })
+        if [ ${#registry_parts[@]} -eq 1 ] ; then
+            # No credentials supplied
+            REGISTRY_USERNAME=""
+            REGISTRY_PASSWORD=""
+            REGISTRY_URL=${registry_parts[0]}
+        else
+            credentials=${registry_parts[0]}
+            credential_parts=(${credentials//:/ })
+            REGISTRY_USERNAME=${credential_parts[0]}
+            REGISTRY_PASSWORD=${credential_parts[1]}
+            REGISTRY_URL=${registry_parts[1]}
+        fi
+        # Ensure the URL ends with a /
+        case $REGISTRY_URL in
+            */) ;;
+            *) REGISTRY_URL=${REGISTRY_URL}/
+        esac
+    fi
+
     create_overlay
     echo "Creating OSM model"
     if [ -v KUBECFG ]; then
@@ -204,7 +228,11 @@ function deploy_charmed_osm(){
     fi
     echo "Deploying OSM with charms"
     images_overlay=""
+    if [ -v REGISTRY_URL ]; then
+       [ ! -v TAG ] && TAG='latest'
+    fi
     [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
+
     if [ -v BUNDLE ]; then
         juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
     else
@@ -326,36 +354,44 @@ EOF
 }
 
 function generate_images_overlay(){
+    if [ ! -z "$REGISTRY_USERNAME" ] ; then
+        REGISTRY_CREDENTIALS=$(cat <<EOF
+
+      image_username: $REGISTRY_USERNAME
+      image_password: $REGISTRY_PASSWORD
+EOF
+    );
+fi
+
     cat << EOF > /tmp/images-overlay.yaml
 applications:
   lcm-k8s:
     options:
-      image: opensourcemano/lcm:$TAG
+      image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
   mon-k8s:
     options:
-      image: opensourcemano/mon:$TAG
+      image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
   ro-k8s:
     options:
-      image: opensourcemano/ro:$TAG
+      image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
   nbi-k8s:
     options:
-      image: opensourcemano/nbi:$TAG
+      image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
   pol-k8s:
     options:
-      image: opensourcemano/pol:$TAG
+      image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
   ui-k8s:
     options:
-      image: opensourcemano/light-ui:$TAG
+      image: ${REGISTRY_URL}opensourcemano/light-ui:$TAG ${REGISTRY_CREDENTIALS}
   pla:
     options:
-      image: opensourcemano/pla:$TAG
+      image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
   ng-ui:
     options:
-      image: opensourcemano/ng-ui:$TAG
+      image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
   keystone:
     options:
-      image: opensourcemano/keystone:$TAG
-
+      image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
 EOF
     mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
 }
index 9ae5da2..be02fa5 100755 (executable)
@@ -72,7 +72,8 @@ function usage(){
     echo -e "     [--lxd-cred <yaml path>]:    Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
     echo -e "     [--microstack]:              Installs microstack as a vim. (--charmed option)"
     echo -e "     [--ha]:                      Installs High Availability bundle. (--charmed option)"
-    echo -e "     [--tag]:                     Docker image tag"
+    echo -e "     [--tag]:                     Docker image tag. (--charmed option)"
+    echo -e "     [--registry]:                Docker registry with optional credentials as user:pass@hostname:port (--charmed option)"
 
 }
 
@@ -1694,6 +1695,7 @@ while getopts ":b:r:c:n:k:u:R:D:o:O:m:N:H:S:s:w:t:U:P:A:l:L:K:-: hy" o; do
             [ "${OPTARG}" == "vca" ] && continue
             [ "${OPTARG}" == "ha" ] && continue
             [ "${OPTARG}" == "tag" ] && continue
+            [ "${OPTARG}" == "registry" ] && continue
             [ "${OPTARG}" == "pla" ] && INSTALL_PLA="y" && continue
             [ "${OPTARG}" == "volume" ] && OPENSTACK_ATTACH_VOLUME="true" && continue
             echo -e "Invalid option: '--$OPTARG'\n" >&2