Add logic for building extra helm build

This adds the build-extra-helm-charts script
that looks for *.helm.build build files. And
then runs the build command provided in the
required BUILD_COMMAND field. It is also
expected an OUTPUTS field on the helm.build
with a pattern indicating the path to
outputs of this build.

Testplan:
PASS - Run jenkins job to run custom helm app
       build

Change-Id: I23cb4a488af1eaf83cfe5c0216557b183744de08
Signed-off-by: Romulo Leite <romulo.leite@windriver.com>
This commit is contained in:
Romulo Leite 2024-05-07 15:51:18 -03:00
parent 1f92282164
commit c4dbb6cb4b
2 changed files with 115 additions and 2 deletions

View File

@ -0,0 +1,107 @@
#!/bin/bash
#
# Copyright (c) 2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
source ${MY_REPO}/build-tools/git-utils.sh || exit 1
VERBOSE=false
function usage {
cat >&2 <<EOF
Usage:
$(basename $0) [ --verbose ]
Options:
--verbose:
Verbose output
--help:
Give this help list
EOF
}
# Find helm.build
function get_extra_files {
find ${GIT_LIST} -maxdepth 3 -type f -name "*helm.build" -and -path "*/debian/*.helm.build"
}
function perform_build {
local extra_build_file=$1
export SOURCE_PATH=${extra_build_file%%/debian/*}
local BUILD_COMMAND OUTPUT_PATTERN
BUILD_COMMAND=$(source "$extra_build_file" && echo "$BUILD_COMMAND") || exit 1
OUTPUT_PATTERN=$(source "$extra_build_file" && echo "$OUTPUTS") || exit 1
if [ "$VERBOSE" = true ] ; then
echo "Build command found: $BUILD_COMMAND"
echo "Output files will be in the following pattern: $OUTPUT_PATTERN"
fi
echo "Running $BUILD_COMMAND command on $SOURCE_PATH"
echo $OUTPUT_PATTERN
cd "$SOURCE_PATH" && ./$BUILD_COMMAND || exit 1
local output_dir
output_dir=$(dirname $(dirname $OUTPUT_PATTERN))
# Create extra helm charts list
local list_file="$output_dir/extra-helm-charts.lst"
if [ ! -f "$$list_file" ]; then
touch "$list_file" || exit 1
fi
ls $OUTPUT_PATTERN >> "$list_file" || exit 1
}
OPTS=$(getopt -o h,a:,A:,B:,r:,i:,l:,p: -l help,verbose -- "$@")
if [ $? -ne 0 ]; then
usage
exit 1
fi
eval set -- "${OPTS}"
while true; do
case $1 in
--)
# End of getopt arguments
shift
break
;;
--verbose)
VERBOSE=true
shift
;;
-h | --help )
usage
exit 1
;;
*)
usage
exit 1
;;
esac
done
declare -a EXTRA_FILES
EXTRA_FILES=($(get_extra_files)) || exit 1
if [ ${#EXTRA_FILES[@]} -eq 0 ]; then
echo "WARNING: Could not find helm.build files" >&2
exit 0
fi
if [ "$VERBOSE" = true ] ; then
echo" .helm.build files found: $EXTRA_FILES"
fi
for extra_file in ${EXTRA_FILES}; do
perform_build $extra_file
done
exit 0

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2018 Wind River Systems, Inc.
# Copyright (c) 2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -929,5 +929,11 @@ else
build_application_tarball
fi
exit 0
EXTRA_HELM_CHARTS="build-extra-helm-charts.sh"
echo "Running build extra helm charts"
MY_SCRIPT_DIR=$(realpath "$(dirname "$0")")
"$MY_SCRIPT_DIR/$EXTRA_HELM_CHARTS" || exit 1
exit 0