3 # COPYRIGHT NOTICE STARTS HERE
5 # Copyright 2019 © 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 and working, 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) <path to project> [<output list file>]"
35 echo " Example: ./$(basename $0) /root/oom/kubernetes/onap"
37 echo " Dependencies: helm, python-yaml, make"
45 from __future__ import print_function
49 with open("${1}", 'r') as f:
50 values = yaml.load(f, Loader=yaml.SafeLoader)
52 enabled = filter(lambda x: values[x].get('enabled', False) == True, values)
53 print(' '.join(enabled))
58 if [ -d "${PROJECT_DIR}/../${1}" ]; then
59 SUBSYS_DIR="${PROJECT_DIR}/../${1}"
60 elif [ -d "${PROJECT_DIR}/../common/${1}" ]; then
61 SUBSYS_DIR="${PROJECT_DIR}/../common/${1}"
63 >&2 echo -e \n" !!! ${1} sybsystem does not exist !!!"\n
65 helm template "${SUBSYS_DIR}" | grep 'image:\ \|tag_version:\ \|h._image' |
66 sed -e 's/^.*\"h._image\"\ :\ //; s/^.*\"\(.*\)\".*$/\1/' \
67 -e 's/\x27\|,//g; s/^.*\(image\|tag_version\):\ //' | tr -d '\r'
71 if [ "${1}" == "-h" ] || [ "${1}" == "--help" ] || [ $# -lt 1 ]; then
77 LISTS_DIR="$(readlink -f $(dirname ${0}))/../data_lists"
78 HELM_REPO="local http://127.0.0.1:8879"
79 PROJECT="$(basename ${1})"
81 if [ ! -f "${PROJECT_DIR}/../Makefile" ]; then
82 echo "Wrong path to project directory entered"
84 elif [ -z "${LIST}" ]; then
86 LIST="${LISTS_DIR}/${PROJECT}_docker_images.list"
89 if [ -e "${LIST}" ]; then
90 mv -f "${LIST}" "${LIST}.bk"
91 MSG="$(realpath ${LIST}) already existed\nCreated backup $(realpath ${LIST}).bk\n"
95 if pgrep -x "helm" > /dev/null; then
96 echo "helm is already running"
98 helm init -c > /dev/null
102 # Create helm repository
103 if ! helm repo list 2>&1 | awk '{ print $1, $2 }' | grep -q "$HELM_REPO" > /dev/null; then
104 helm repo add "$HELM_REPO"
108 pushd "${PROJECT_DIR}/.."
109 echo "Building project..."
110 make all > /dev/null; make ${PROJECT} > /dev/null
113 # Create the list from all enabled subsystems
114 echo "Creating the list..."
115 if [ "${PROJECT}" == "onap" ]; then
116 COMMENT="OOM commit $(git --git-dir="${PROJECT_DIR}/../../.git" rev-parse HEAD)"
117 for subsystem in `parse_yaml "${PROJECT_DIR}/values.yaml"`; do
118 create_list ${subsystem}
119 done | sort -u > ${LIST}
122 create_list ${PROJECT} | sort -u > ${LIST}
125 # Add comment reffering to the project
126 sed -i "1i# generated from ${COMMENT}" "${LIST}"
129 echo -e 'The list has been created:\n '"${LIST}"