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; chartmuseum is also required if using
32 echo " This script is preparing docker images list based on kubernetes project"
34 echo " ./$(basename $0) [OPTION]... <path to project> [<output list file>]"
37 echo " -h | --help Show script usage synopsis"
38 echo " -p | --helm-port Chart repository server port"
39 echo " -b | --helm-bin Path to Helm executable"
41 echo " Example: ./$(basename $0) /root/oom/kubernetes/onap"
43 echo " Dependencies: helm, python-yaml, make, chartmuseum (helm v3 only)"
54 with open("${1}", 'r') as f:
55 values = yaml.load(f, Loader=yaml.SafeLoader)
56 enabled = filter(lambda x: values[x].get('enabled', False) == True, values)
57 print(' '.join(enabled))
62 if [ -d "${PROJECT_DIR}/../${1}" ]; then
63 SUBSYS_DIR="${PROJECT_DIR}/../${1}"
64 elif [ -d "${PROJECT_DIR}/../common/${1}" ]; then
65 SUBSYS_DIR="${PROJECT_DIR}/../common/${1}"
67 >&2 echo -e \n" !!! ${1} sybsystem does not exist !!!"\n
69 ${HELM_BIN} template --set global.masterPassword=TemplatePassword,global.offlineDeploymentBuild=true -f ${PROJECT_DIR}/values.yaml "${SUBSYS_DIR}" | grep 'image:\ \|tag_version:\ \|h._image' |
70 sed -e 's/^.*\"h._image\"\ :\ //; s/^.*\"\(.*\)\".*$/\1/' \
71 -e 's/\x27\|,//g; s/^.*\(image\|tag_version\):\ //' | tr -d '\r'
74 # Kill helm repository if already running
76 if [[ "${HELM_VERSION}" =~ "v3" ]];
80 echo "not implemented"
82 # Kill helm executable
83 for pid in $(pgrep -f "${HELM_BIN} serve --address ${HELM_REPO}");
93 echo "Error: No valid port number provided"
96 if ! [[ "$1" =~ ^[0-9]*$ ]];
98 echo "Error: "${1}" is not a valid port number"
106 echo "Error: No path to executable provided"
109 if ! [[ -x ${1} && -f ${1} ]];
111 echo "Error: ${1} is not an executable"
118 sleep 2 # let the helm repository process settle
119 if [[ "${HELM_VERSION}" =~ "v3" ]];
123 echo "not implemented"
125 if [ $(pgrep -f "${HELM_BIN} serve --address ${HELM_REPO}" -c) -eq 0 ];
127 echo "Fatal: Helm chart repository server failed to start"
133 # Proccess input options
134 if [ $# -lt 1 ]; then
146 validate_port "${PORT}"
151 validate_bin "${BIN}"
155 echo "Unknown option ${1}"
168 LISTS_DIR="$(readlink -f $(dirname ${0}))/../data_lists"
169 HELM_BIN=${BIN:-helm}
170 HELM_REPO_HOST="127.0.0.1"
171 HELM_REPO_PORT="${PORT:-8879}"
172 HELM_REPO="${HELM_REPO_HOST}:${HELM_REPO_PORT}"
173 HELM_REPO_PATH="dist/packages" # based on PACKAGE_DIR defined in oom/kubernetes/Makefile
174 HELM_VERSION=$(${HELM_BIN} version -c --template "{{.Version}}")
175 DOCKER_CONTAINER="generate-certs-${HELM_REPO_PORT}" # oom-cert-service container name override
176 PROJECT="$(basename ${1})"
178 if [ ! -f "${PROJECT_DIR}/../Makefile" ]; then
179 echo "Wrong path to project directory entered"
181 elif [ -z "${LIST}" ]; then
182 mkdir -p ${LISTS_DIR}
183 LIST="${LISTS_DIR}/${PROJECT}_docker_images.list"
185 # $2 is not empty - ensure LIST path exists
186 LIST_DIR="$(dirname ${LIST})"
187 mkdir -p "${LIST_DIR}"
188 MSG="${LIST_DIR} didn't exist, created\n"
191 if [ -e "${LIST}" ]; then
192 mv -f "${LIST}" "${LIST}.bk"
193 MSG="$(realpath ${LIST}) already existed\nCreated backup $(realpath ${LIST}).bk\n"
196 HELM_HOME=$(mktemp -p /tmp -d .helm.XXXXXXXX)
198 if [[ "${HELM_VERSION}" =~ "v3" ]];
202 echo "not implemented"
206 kill_chart_repo # make sure it's not already running
207 mkdir -p "${PROJECT_DIR}/../${HELM_REPO_PATH}"
208 ${HELM_BIN} init --skip-refresh -c --local-repo-url "http://${HELM_REPO}"
209 ${HELM_BIN} serve --address ${HELM_REPO} --repo-path "${PROJECT_DIR}/../${HELM_REPO_PATH}" &
210 ${HELM_BIN} repo remove stable 2>/dev/null || true
215 pushd "${PROJECT_DIR}/.."
216 echo "Building project..."
217 export SKIP_LINT=TRUE
218 export DOCKER_CONTAINER
220 make -e all > /dev/null; make -e ${PROJECT} > /dev/null
223 # Create the list from all enabled subsystems
224 echo "Creating the list..."
225 if [ "${PROJECT}" == "onap" ]; then
226 COMMENT="OOM commit $(git --git-dir="${PROJECT_DIR}/../../.git" rev-parse HEAD)"
227 for subsystem in `parse_yaml "${PROJECT_DIR}/resources/overrides/onap-all.yaml"`; do
228 create_list ${subsystem}
229 done | sort -u > ${LIST}
232 create_list ${PROJECT} | sort -u > ${LIST}
235 # Add comment reffering to the project
236 sed -i "1i# generated from ${COMMENT}" "${LIST}"
239 echo -e 'The list has been created:\n '"${LIST}"
243 # Remove temporary helm directory