3 # COPYRIGHT NOTICE STARTS HERE
5 # Copyright 2019-2020 © Samsung Electronics Co., Ltd.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # COPYRIGHT NOTICE ENDS HERE
21 ### This script is preparing docker images list based on kubernetes project
23 ### NOTE: helm needs to be installed; it is required for correct processing
24 ### of helm charts in oom directory
31 echo " This script is preparing docker images list based on kubernetes project"
33 echo " ./$(basename $0) [OPTION]... <path to project> [<output list file>]"
36 echo " -h | --help Show script usage synopsis"
37 echo " -p | --helm-port Chart repository server port"
39 echo " Example: ./$(basename $0) /root/oom/kubernetes/onap"
41 echo " Dependencies: helm, python-yaml, make"
52 with open("${1}", 'r') as f:
53 values = yaml.load(f, Loader=yaml.SafeLoader)
54 enabled = filter(lambda x: values[x].get('enabled', False) == True, values)
55 print(' '.join(enabled))
60 if [ -d "${PROJECT_DIR}/../${1}" ]; then
61 SUBSYS_DIR="${PROJECT_DIR}/../${1}"
62 elif [ -d "${PROJECT_DIR}/../common/${1}" ]; then
63 SUBSYS_DIR="${PROJECT_DIR}/../common/${1}"
65 >&2 echo -e \n" !!! ${1} sybsystem does not exist !!!"\n
67 helm template --set global.masterPassword=TemplatePassword -f ${PROJECT_DIR}/values.yaml "${SUBSYS_DIR}" | grep 'image:\ \|tag_version:\ \|h._image' |
68 sed -e 's/^.*\"h._image\"\ :\ //; s/^.*\"\(.*\)\".*$/\1/' \
69 -e 's/\x27\|,//g; s/^.*\(image\|tag_version\):\ //' | tr -d '\r'
72 # Kill helm if already running
74 for pid in $(pgrep -f "helm serve --address ${HELM_REPO}");
83 echo "Error: No valid port number provided"
86 if ! [[ "$1" =~ ^[0-9]*$ ]];
88 echo "Error: "${1}" is not a valid port number"
93 # Proccess input options
106 validate_port "${PORT}"
110 echo "Unknown option ${1}"
123 LISTS_DIR="$(readlink -f $(dirname ${0}))/../data_lists"
124 HELM_REPO_HOST="127.0.0.1"
125 HELM_REPO_PORT="${PORT:-8879}"
126 HELM_REPO="${HELM_REPO_HOST}:${HELM_REPO_PORT}"
127 HELM_REPO_PATH="dist/packages" # based on PACKAGE_DIR defined in oom/kubernetes/Makefile
128 DOCKER_CONTAINER="generate-certs-${HELM_REPO_PORT}" # oom-cert-service container name override
129 PROJECT="$(basename ${1})"
131 if [ ! -f "${PROJECT_DIR}/../Makefile" ]; then
132 echo "Wrong path to project directory entered"
134 elif [ -z "${LIST}" ]; then
135 mkdir -p ${LISTS_DIR}
136 LIST="${LISTS_DIR}/${PROJECT}_docker_images.list"
138 # $2 is not empty - ensure LIST path exists
139 LIST_DIR="$(dirname ${LIST})"
140 mkdir -p "${LIST_DIR}"
141 MSG="${LIST_DIR} didn't exist, created\n"
144 if [ -e "${LIST}" ]; then
145 mv -f "${LIST}" "${LIST}.bk"
146 MSG="$(realpath ${LIST}) already existed\nCreated backup $(realpath ${LIST}).bk\n"
150 HELM_HOME=$(mktemp -p /tmp -d .helm.XXXXXXXX)
152 kill_helm # make sure it's not already running
153 mkdir -p "${PROJECT_DIR}/../${HELM_REPO_PATH}"
154 helm init -c --local-repo-url "http://${HELM_REPO}"
155 helm serve --address ${HELM_REPO} --repo-path "${PROJECT_DIR}/../${HELM_REPO_PATH}" &
156 helm repo remove stable 2>/dev/null || true
159 pushd "${PROJECT_DIR}/.."
160 echo "Building project..."
161 export SKIP_LINT=TRUE
162 export DOCKER_CONTAINER
163 make -e all > /dev/null; make -e ${PROJECT} > /dev/null
166 # Create the list from all enabled subsystems
167 echo "Creating the list..."
168 if [ "${PROJECT}" == "onap" ]; then
169 COMMENT="OOM commit $(git --git-dir="${PROJECT_DIR}/../../.git" rev-parse HEAD)"
170 for subsystem in `parse_yaml "${PROJECT_DIR}/resources/overrides/onap-all.yaml"`; do
171 create_list ${subsystem}
172 done | sort -u > ${LIST}
175 create_list ${PROJECT} | sort -u > ${LIST}
178 # Add comment reffering to the project
179 sed -i "1i# generated from ${COMMENT}" "${LIST}"
182 echo -e 'The list has been created:\n '"${LIST}"
184 # Remove temporary helm directory