[ANSIBLE] Add ghcr.io to simulated hosts list
[oom/offline-installer.git] / build / creating_data / docker-images-collector.sh
index 71f2e72..89af77a 100755 (executable)
@@ -2,7 +2,7 @@
 
 #   COPYRIGHT NOTICE STARTS HERE
 #
-#   Copyright 2019-2020 © Samsung Electronics Co., Ltd.
+#   Copyright 2019-2021 © Samsung Electronics Co., Ltd.
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
 #
 #   COPYRIGHT NOTICE ENDS HERE
 
-### This script is preparing docker images list based on kubernetes project
+### This script is preparing docker images list based on OOM project
 
-### NOTE: helm needs to be installed; it is required for correct processing
-### of helm charts in oom directory; chartmuseum is also required if using
-### helm v3
+### NOTE: helm and docker need to be installed; those are required for correct processing
+### of helm charts in oom directory; helm push plugin is also  required if
+### using helm v3
 
 # Fail fast settings
 set -e
 
 usage () {
     echo "      "
-    echo "  This script is preparing docker images list based on kubernetes project"
+    echo "  This script is preparing docker images list based on OOM project"
     echo "      Usage:"
     echo "        ./$(basename $0) [OPTION]... <path to project> [<output list file>]"
     echo "      "
     echo "      Options:"
-    echo "          -h | --help      Show script usage synopsis"
-    echo "          -p | --helm-port Chart repository server port"
-    echo "          -b | --helm-bin  Path to Helm executable"
+    echo "          -h | --help            Show script usage synopsis"
+    echo "          -p | --helm-port       Chart repository server port"
+    echo "          -b | --helm-bin        Path to Helm executable"
     echo "      "
     echo "      Example: ./$(basename $0) /root/oom/kubernetes/onap"
     echo "      "
-    echo "      Dependencies: helm, python-yaml, make, chartmuseum (helm v3 only)"
+    echo "      Dependencies: helm, python-yaml, make"
     echo "      "
     exit 1
 }
@@ -75,13 +75,14 @@ create_list() {
 kill_chart_repo() {
     if [[ "${HELM_VERSION}" =~ "v3" ]];
     then
-        # Kill chartmuseum
-        # FIXME
-        echo "not implemented"
+        if [ $(docker ps -aq -f name="^chartmuseum-${HELM_REPO_PORT}$") ];
+        then
+            docker kill "chartmuseum-${HELM_REPO_PORT}"
+        fi
     else
-        # Kill helm executable
         for pid in $(pgrep -f "${HELM_BIN} serve --address ${HELM_REPO}");
         do
+            # Kill helm repository server process
             kill $pid
         done
     fi
@@ -118,9 +119,11 @@ check_chart_repo() {
     sleep 2 # let the helm repository process settle
     if [[ "${HELM_VERSION}" =~ "v3" ]];
     then
-        # Check chartmuseum
-        # FIXME
-        echo "not implemented"
+        if [ ! $(docker ps -aq -f name="^chartmuseum-${HELM_REPO_PORT}$") ];
+        then
+            echo "Fatal: Helm chart repository docker container failed to start"
+            exit 1
+        fi
     else
         if [ $(pgrep -f "${HELM_BIN} serve --address ${HELM_REPO}" -c) -eq 0 ];
         then
@@ -194,16 +197,23 @@ if [ -e "${LIST}" ]; then
 fi
 
 HELM_HOME=$(mktemp -p /tmp -d .helm.XXXXXXXX)
+export HELM_HOME
 
+kill_chart_repo # make sure it's not already running
 if [[ "${HELM_VERSION}" =~ "v3" ]];
 then
     # Setup helm v3
-    # FIXME
-    echo "not implemented"
+    export HELM_CONFIG_HOME="${HELM_HOME}/.config"
+    export HELM_CACHE_HOME="${HELM_HOME}/.cache"
+    mkdir --mode=777 ${HELM_HOME}/chartmuseum
+    docker run --rm -it -d -p ${HELM_REPO_PORT}:8080 \
+      --name "chartmuseum-${HELM_REPO_PORT}" \
+      -e STORAGE=local -e STORAGE_LOCAL_ROOTDIR=/charts \
+      -v ${HELM_HOME}/chartmuseum:/charts chartmuseum/chartmuseum
+    sleep 2 # let the chartmuseum process settle
+    ${HELM_BIN} repo add local "http://${HELM_REPO}"
 else
     # Setup helm v2
-    export HELM_HOME
-    kill_chart_repo # make sure it's not already running
     mkdir -p "${PROJECT_DIR}/../${HELM_REPO_PATH}"
     ${HELM_BIN} init --skip-refresh -c --local-repo-url "http://${HELM_REPO}"
     ${HELM_BIN} serve --address ${HELM_REPO} --repo-path "${PROJECT_DIR}/../${HELM_REPO_PATH}" &