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"
94 sleep 2 # let the helm process settle
95 if [ $(pgrep -f "helm serve --address ${HELM_REPO}" -c) -eq 0 ];
97 echo "Fatal: Helm chart repository server failed to start"
102 # Proccess input options
103 if [ $# -lt 1 ]; then
115 validate_port "${PORT}"
119 echo "Unknown option ${1}"
132 LISTS_DIR="$(readlink -f $(dirname ${0}))/../data_lists"
133 HELM_REPO_HOST="127.0.0.1"
134 HELM_REPO_PORT="${PORT:-8879}"
135 HELM_REPO="${HELM_REPO_HOST}:${HELM_REPO_PORT}"
136 HELM_REPO_PATH="dist/packages" # based on PACKAGE_DIR defined in oom/kubernetes/Makefile
137 DOCKER_CONTAINER="generate-certs-${HELM_REPO_PORT}" # oom-cert-service container name override
138 PROJECT="$(basename ${1})"
140 if [ ! -f "${PROJECT_DIR}/../Makefile" ]; then
141 echo "Wrong path to project directory entered"
143 elif [ -z "${LIST}" ]; then
144 mkdir -p ${LISTS_DIR}
145 LIST="${LISTS_DIR}/${PROJECT}_docker_images.list"
147 # $2 is not empty - ensure LIST path exists
148 LIST_DIR="$(dirname ${LIST})"
149 mkdir -p "${LIST_DIR}"
150 MSG="${LIST_DIR} didn't exist, created\n"
153 if [ -e "${LIST}" ]; then
154 mv -f "${LIST}" "${LIST}.bk"
155 MSG="$(realpath ${LIST}) already existed\nCreated backup $(realpath ${LIST}).bk\n"
159 HELM_HOME=$(mktemp -p /tmp -d .helm.XXXXXXXX)
161 kill_helm # make sure it's not already running
162 mkdir -p "${PROJECT_DIR}/../${HELM_REPO_PATH}"
163 helm init -c --local-repo-url "http://${HELM_REPO}"
164 helm serve --address ${HELM_REPO} --repo-path "${PROJECT_DIR}/../${HELM_REPO_PATH}" &
165 helm repo remove stable 2>/dev/null || true
169 pushd "${PROJECT_DIR}/.."
170 echo "Building project..."
171 export SKIP_LINT=TRUE
172 export DOCKER_CONTAINER
173 make -e all > /dev/null; make -e ${PROJECT} > /dev/null
176 # Create the list from all enabled subsystems
177 echo "Creating the list..."
178 if [ "${PROJECT}" == "onap" ]; then
179 COMMENT="OOM commit $(git --git-dir="${PROJECT_DIR}/../../.git" rev-parse HEAD)"
180 for subsystem in `parse_yaml "${PROJECT_DIR}/resources/overrides/onap-all.yaml"`; do
181 create_list ${subsystem}
182 done | sort -u > ${LIST}
185 create_list ${PROJECT} | sort -u > ${LIST}
188 # Add comment reffering to the project
189 sed -i "1i# generated from ${COMMENT}" "${LIST}"
192 echo -e 'The list has been created:\n '"${LIST}"
194 # Remove temporary helm directory