Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Building those is basically just extracting data and creating a .helm.tar result. Based on pull request #582 by Sumit Jamgade.
- Loading branch information
Showing
4 changed files
with
214 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
################################################################ | ||
# | ||
# Copyright (c) 2020 SUSE 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 | ||
# | ||
################################################################ | ||
|
||
package Build::Helm; | ||
|
||
use strict; | ||
|
||
use Build::SimpleJSON; | ||
|
||
# we do not want to parse the yaml file from the tar here, so just return some | ||
# dummy result | ||
sub parse { | ||
my ($cf, $fn) = @_; | ||
my $fd; | ||
return {'error' => "$fn: $!"} unless open($fd, '<', $fn); | ||
my $ret = { 'name' => 'helmchart', 'deps' => []}; | ||
while (<$fd>) { | ||
chomp; | ||
my @s = split(' ', $_); | ||
next unless @s; | ||
my $k = lc(shift(@s)); | ||
$ret->{'chartfile'} = $s[0] if @s && $k eq 'chart:'; | ||
push @{$ret->{'containertags'}}, @s if @s && $k eq 'tags:'; | ||
} | ||
close $fd; | ||
if (defined($ret->{'chartfile'})) { | ||
return {'error' => "illegal chartfile"} unless $ret->{'chartfile'} ne ''; | ||
return {'error' => "illegal chartfile"} if $ret->{'chartfile'} =~ /[\/\000-\037]/; | ||
return {'error' => "illegal chartfile"} if $ret->{'chartfile'} =~ /^\./; | ||
} | ||
return $ret; | ||
} | ||
|
||
sub show { | ||
my ($release, $chartconfig); | ||
while (@ARGV) { | ||
if (@ARGV > 2 && $ARGV[0] eq '--release') { | ||
(undef, $release) = splice(@ARGV, 0, 2); | ||
} elsif (@ARGV > 2 && $ARGV[0] eq '--chartconfig') { | ||
(undef, $chartconfig) = splice(@ARGV, 0, 2); | ||
} else { | ||
last; | ||
} | ||
} | ||
my ($fn, $field) = @ARGV; | ||
require YAML::XS; | ||
$YAML::XS::LoadBlessed = 0; | ||
my $d = {}; | ||
$d = parse({}, $fn) if $fn; | ||
die("$d->{'error'}\n") if $d->{'error'}; | ||
my $d2 = {}; | ||
if ($chartconfig) { | ||
$d2 = YAML::XS::LoadFile($chartconfig); | ||
die unless $d2; | ||
my $name = $d2->{'name'}; | ||
my $version = $d2->{'version'}; | ||
die("no name\n") unless defined $name; | ||
die("bad name '$name'\n") if $name eq ''; | ||
die("bad name '$name'\n") if $name =~ /\//; | ||
die("bad name '$name'\n") if $name =~ /^[-\.]/; | ||
die("bad name '$name'\n") if $name =~ /[\/\000-\037]/; | ||
die("no version\n") unless defined $version; | ||
die("bad version '$version'\n") if $versioneq ''; | ||
die("bad version '$version'\n") if $version =~ /\//; | ||
die("bad version '$version'\n") if $version =~ /[\/\000-\037]/; | ||
if ($field eq 'manifest') { | ||
my @tags = @{$d->{'containertags'} || []}; | ||
for (@tags) { | ||
s/<NAME>/$name/g; | ||
s/<VERSION>/$version/g; | ||
s/<RELEASE>/$release/g; | ||
} | ||
my $manifest = {}; | ||
$manifest->{'name'} = $name; | ||
$manifest->{'version'} = $version; | ||
$manifest->{'tags'} = \@tags if @tags; | ||
$manifest->{'chart'} = "$name-$version.tgz"; | ||
$manifest->{'_order'} = [ qw{name version tags chart} ]; | ||
print Build::SimpleJSON::unparse($manifest)."\n"; | ||
exit(0); | ||
} | ||
if ($field eq 'config') { | ||
$d2->{'_order'} = [ qw{apiVersion name version kubeVersion description type keywords home sources dependencies maintainers icon appVersion deprecated annotations} ]; | ||
print Build::SimpleJSON::unparse($d2)."\n"; | ||
exit(0); | ||
} | ||
$d = $d2; | ||
$d->{'nameversion'} = "$name-$version"; | ||
} | ||
my $x = $d->{$field}; | ||
$x = [ $x ] unless ref $x; | ||
print "@$x\n"; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
################################################################ | ||
# | ||
# 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 | ||
cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/ | ||
else | ||
cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/ | ||
fi | ||
if test "$?" != 0 ; then | ||
cleanup_and_exit 1 "source copy failed" | ||
fi | ||
fi | ||
} | ||
|
||
recipe_prepare_helm() { | ||
: | ||
} | ||
|
||
recipe_build_helm() { | ||
TOPDIR=/usr/src/packages | ||
mkdir -p "$BUILD_ROOT$TOPDIR/HELM" | ||
local chartfile | ||
chartfile=$(perl -I$BUILD_DIR -MBuild::Helm -e Build::Helm::show -- "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" chartfile) | ||
test -z "$chartfile" -a -e "$BUILD_ROOT$TOPDIR/SOURCES/chart.tar" && chartfile=chart.tar | ||
test -z "$chartfile" -a -e "$BUILD_ROOT$TOPDIR/SOURCES/chart.tgz" && chartfile=chart.tgz | ||
test -z "$chartfile" -a -e "$BUILD_ROOT$TOPDIR/SOURCES/chart.tar.gz" && chartfile=chart.tgz | ||
test -e "$BUILD_ROOT$TOPDIR/SOURCES/$chartfile" || cleanup_and_exit 1 "$chartfile does not exist" | ||
tar -xOf "$BUILD_ROOT$TOPDIR/SOURCES/$chartfile" Chart.yaml > "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" | ||
test -s "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" || cleanup_and_exit 1 "chart does not include Chart.yaml" | ||
# extract data from chart file | ||
args=() | ||
test -n "$RELEASE" && args=("${args[@]}" --release "$RELEASE") | ||
perl -I$BUILD_DIR -MBuild::Helm -e 'Build::Helm::show' -- "${args[@]}" --chartconfig "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" config > "$BUILD_ROOT$TOPDIR/HELM/config.json" | ||
perl -I$BUILD_DIR -MBuild::Helm -e 'Build::Helm::show' -- "${args[@]}" --chartconfig "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" manifest > "$BUILD_ROOT$TOPDIR/HELM/manifest.json" | ||
local nameversion=$(perl -I$BUILD_DIR -MBuild::Helm -e 'Build::Helm::show' -- "${args[@]}" --chartconfig "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" nameversion) | ||
test -n "$nameversion" || cleanup_and_exit 1 "no nameversion"; | ||
# copy (and compress) chart | ||
case $chartfile in | ||
*.tar.gz | *.tgz) | ||
cp "$BUILD_ROOT$TOPDIR/SOURCES/$chartfile" "$BUILD_ROOT$TOPDIR/HELM/$nameversion.tgz" | ||
;; | ||
*.tar) | ||
gzip < "$BUILD_ROOT$TOPDIR/SOURCES/$chartfile" > "$BUILD_ROOT$TOPDIR/HELM/$nameversion.tgz" | ||
;; | ||
*) | ||
cleanup_and_exit 1 | ||
;; | ||
esac | ||
# now create our helm.tar result | ||
(cd "$BUILD_ROOT$TOPDIR/HELM" && tar -cf "$nameversion.helm.tar" manifest.json config.json "$nameversion.tgz") | ||
# get rid of everything else | ||
rm -rf "$BUILD_ROOT$TOPDIR/HELM/manifest.json" | ||
rm -rf "$BUILD_ROOT$TOPDIR/HELM/config.json" | ||
rm -rf "$BUILD_ROOT$TOPDIR/HELM/$nameversion.tgz" | ||
rm -rf "$BUILD_ROOT$TOPDIR/HELM/Chart.yaml" | ||
BUILD_SUCCEEDED=true | ||
} | ||
|
||
recipe_resultdirs_helm() { | ||
echo HELM | ||
} | ||
|
||
recipe_cleanup_helm() { | ||
: | ||
} | ||
|