blob: e13b915004c402f89887024c7acacdc1de45ca8a [file] [log] [blame]
Tomáš Levoraa5a6e7c2019-03-04 16:40:09 +01001#! /usr/bin/env bash
2
3# COPYRIGHT NOTICE STARTS HERE
4#
5# Copyright 2019 © Samsung Electronics Co., Ltd.
6#
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
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
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.
18#
19# COPYRIGHT NOTICE ENDS HERE
20
21### This script is preparing docker images list based on kubernetes project
22
23### NOTE: helm needs to be installed and working, it is required for correct processing
24### of helm charts in oom directory
25
26# Fail fast settings
27set -e
28
29usage () {
30 echo " "
31 echo " This script is preparing docker images list based on kubernetes project"
32 echo " Usage:"
33 echo " ./$(basename $0) <project version> <path to project> [<output list file>]"
34 echo " "
35 echo " Example: ./$(basename $0) onap_3.0.2 /root/oom/kubernetes/onap"
36 echo " "
37 echo " Dependencies: helm, python-yaml, make"
38 echo " "
39 exit 1
40}
41
42parse_yaml() {
43python - <<PYP
44#!/usr/bin/python
45from __future__ import print_function
46import yaml
47import sys
48
49with open("${1}", 'r') as f:
50 values = yaml.load(f)
51
52 enabled = filter(lambda x: values[x].get('enabled', False) == True, values)
53 print(' '.join(enabled))
54PYP
55}
56
57create_list() {
58 helm template "${PROJECT_DIR}/../${1}" | grep 'image:\ \|tag_version:\ \|h._image' |
59 sed -e 's/^.*\"h._image\"\ :\ //; s/^.*\"\(.*\)\".*$/\1/' \
60 -e 's/\x27\|,//g; s/^.*\(image\|tag_version\):\ //' | tr -d '\r'
61}
62
63# Configuration
64TAG="${1}"
65PROJECT_DIR="${2}"
66LIST="${3}"
67LISTS_DIR="$(readlink -f $(dirname ${0}))/../data_lists"
68HELM_REPO="local http://127.0.0.1:8879"
69
70if [ "${1}" == "-h" ] || [ "${1}" == "--help" ] || [ $# -lt 2 ]; then
71 usage
72elif [ ! -f "${PROJECT_DIR}/../Makefile" ]; then
73 echo "Wrong path to project directory entered"
74 exit 1
75elif [ -z "${LIST}" ]; then
76 mkdir -p ${LISTS_DIR}
77 LIST="${LISTS_DIR}/${TAG}-docker_images.list"
78fi
79
80if [ -e "${LIST}" ]; then
81 mv -f "${LIST}" "${LIST}.bk"
82 MSG="$(realpath ${LIST}) already existed\nCreated backup $(realpath ${LIST}).bk\n"
83fi
84
85PROJECT="$(basename ${2})"
86
87# Setup helm
88if pgrep -x "helm" > /dev/null; then
89 echo "helm is already running"
90else
91 helm init -c > /dev/null
92 helm serve &
93fi
94
95# Create helm repository
96if ! helm repo list 2>&1 | awk '{ print $1, $2 }' | grep -q "$HELM_REPO" > /dev/null; then
97 helm repo add "$HELM_REPO"
98fi
99
100# Make all
101pushd "${PROJECT_DIR}/.."
102echo "Building project..."
103make all > /dev/null; make ${PROJECT} > /dev/null
104popd
105
106# Create the list from all enabled subsystems
107echo "Creating the list..."
108if [ "${PROJECT}" == "onap" ]; then
109 for subsystem in `parse_yaml "${PROJECT_DIR}/values.yaml"`; do
110 create_list ${subsystem}
111 done
112else
113 create_list ${PROJECT}
114fi | sort -u > ${LIST}
115
116echo -e ${MSG}
117echo -e 'The list has been created:\n '"${LIST}"
118exit 0