Hello World

File build-recipe-helm of Package build

################################################################
#
# Copyright (c) 2020 SUSE Linux LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################

recipe_setup_helm() {
    TOPDIR="/usr/src/packages"
    test "$DO_INIT_TOPDIR" != false && rm -Rf "$BUILD_ROOT/$TOPDIR"
    mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES"
    if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
	mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
    else
	if test -z "$LINKSOURCES" ; then
	    copy_sources "$MYSRCDIR" "$BUILD_ROOT$TOPDIR/SOURCES/"
	else
	    cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/ || cleanup_and_exit 1 "source copy failed"
	fi
    fi
    chown -hR "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
}

recipe_prepare_helm() {
    rm -rf "$BUILD_ROOT$TOPDIR/BUILD"
    mkdir -p "$BUILD_ROOT$TOPDIR/BUILD"
    cp -dLR "$BUILD_ROOT$TOPDIR/SOURCES/"* "$BUILD_ROOT$TOPDIR/BUILD"
    chown -hR "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR/BUILD"
    cd "$BUILD_ROOT$TOPDIR/BUILD"
    for i in *.tar *.tgz *.tar.gz *.tar.xz ; do
	test -e "$i" || continue
	echo "Unpacking $i ..."
	echo "#!/bin/sh -e" > $BUILD_ROOT/.unpack.command
	shellquote cd "$TOPDIR/BUILD" >> $BUILD_ROOT/.unpack.command
	echo >> $BUILD_ROOT/.unpack.command
	echo -n 'tar -x --owner="'$BUILD_USER'" -f ' >> $BUILD_ROOT/.unpack.command
	shellquote "$i" >> $BUILD_ROOT/.unpack.command
	echo >> $BUILD_ROOT/.unpack.command
	shellquote rm -f "$i" >> $BUILD_ROOT/.unpack.command
	echo >> $BUILD_ROOT/.unpack.command
	chmod 0755 $BUILD_ROOT/.unpack.command
	chroot $BUILD_ROOT su -c /.unpack.command - $BUILD_USER || cleanup_and_exit 1
	rm -f $BUILD_ROOT/.unpack.command
	rm -f "$i"
	ls -l
    done
}

recipe_build_helm() {
    cd "$BUILD_ROOT$TOPDIR/BUILD"
    mkdir -p "$BUILD_ROOT$TOPDIR/HELM"
    chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR/HELM"
    # extract data from chart file
    args=() 
    test -n "$DISTURL" && args=("${args[@]}" --disturl "$DISTURL")
    test -n "$RELEASE" && args=("${args[@]}" --release "$RELEASE")
    local name=$(perl -I$BUILD_DIR -MBuild::Helm -e 'Build::Helm::show' -- "${args[@]}" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" name)
    local version=$(perl -I$BUILD_DIR -MBuild::Helm -e 'Build::Helm::show' -- "${args[@]}" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" version)
    local nameversion="$name-$version"
    # avoid packaging sources services and changes files (also include content from _helmignore)
    chroot $BUILD_ROOT su -c "(cd $TOPDIR/BUILD; [ -f _helmignore ] && mv -f _helmignore .helmignore; echo -e '/*.changes\n/_*\n' >> .helmignore; )"  - $BUILD_USER || cleanup_and_exit 1
    # create chart
    chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && helm package -d $TOPDIR/HELM ."  - $BUILD_USER || cleanup_and_exit 1
    test -f "$BUILD_ROOT$TOPDIR/HELM/$nameversion.tgz" || cleanup_and_exit 1 "helm package command did not create $nameversion.tgz"
    # extract generated Chart.yaml file
    tar -xOf "$BUILD_ROOT$TOPDIR/HELM/$nameversion.tgz" -- "$name/Chart.yaml" > "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml"
    test -s "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" || cleanup_and_exit 1 "helm chart does not contain $name/Chart.yaml"
    # generate helminfo
    perl -I$BUILD_DIR -MBuild::Helm -e 'Build::Helm::show' -- "${args[@]}" --origrecipe "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" --chart "$BUILD_ROOT$TOPDIR/HELM/$nameversion.tgz" "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" helminfo > "$BUILD_ROOT$TOPDIR/HELM/$nameversion.helminfo" || cleanup_and_exit 1
    rm -f "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml"
    BUILD_SUCCEEDED=true
}

recipe_resultdirs_helm() {
    echo HELM
}

recipe_cleanup_helm() {
    :
}