build: Get rid of ApplicationSets
This commit is contained in:
@ -2,26 +2,69 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $chart_version = `cat chart/Chart.yaml | yq '.version'` or die;
|
||||
my $chart_version = `cat chart/Chart.yaml | yq '.version'` or die $1;
|
||||
chomp($chart_version);
|
||||
|
||||
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
||||
chomp($git_branch);
|
||||
my $git_commit_sha = `git rev-parse HEAD`;
|
||||
chomp($git_commit_sha);
|
||||
my $main_branch = "main";
|
||||
|
||||
print
|
||||
print $chart_version;
|
||||
# - kubectl get -f ./kube/applicationset.yaml -o yaml > /tmp/appset.yaml
|
||||
# - yq -i "del(.metadata.resourceVersion)" /tmp/appset.yaml
|
||||
# - yq -i "del(.metadata.generation)" /tmp/appset.yaml
|
||||
# - yq -i "del(.metadata.uid)" /tmp/appset.yaml
|
||||
# - yq -i "del(.status)" /tmp/appset.yaml
|
||||
# - yq -i "del(.spec.generators[].list.elements[] | select(.branch == \"$ARGO_APP_BRANCH\"))" /tmp/appset.yaml
|
||||
# - yq -i "del(.spec.generators[].list.elements[] | select(.commit_sha == \"$ARGO_APP_IMAGE_TAG\"))" /tmp/appset.yaml
|
||||
# - yq -i '. *= load("./kube/applicationset.yaml")' /tmp/appset.yaml
|
||||
# - envsubst < ./kube/main.yaml > /tmp/elements.yaml
|
||||
# - yq -i '.spec.generators[].list.elements += load("/tmp/elements.yaml")' /tmp/appset.yaml
|
||||
# - kubectl apply -f /tmp/appset.yaml
|
||||
#
|
||||
my $main_branch = "main";
|
||||
my $values = "";
|
||||
my $remark_secret = `openssl rand -hex 12`;
|
||||
chomp($remark_secret);
|
||||
|
||||
$ENV{'ARGO_APP_CHART_VERSION'} = $chart_version;
|
||||
$ENV{'ARGO_APP_BRANCH'} = $git_branch;
|
||||
$ENV{'ARGO_APP_HOSTNAME'} = "$git_branch-dev.badhouseplants.net";
|
||||
$ENV{'ARGO_APP_IMAGE_TAG'} = $git_commit_sha;
|
||||
$ENV{'ARGO_REMARK_SECRET'} = $remark_secret;
|
||||
|
||||
# ----------------------------------
|
||||
# -- Fill the Application manifest
|
||||
# -- with correct values
|
||||
# ----------------------------------
|
||||
if ($git_branch eq $main_branch) {
|
||||
print "Using the main values file\n";
|
||||
print `envsubst < ./kube/values-main.yaml > /tmp/values.yaml` or die $!;
|
||||
} else {
|
||||
print "Using the preview values file\n";
|
||||
print `envsubst < ./kube/values-preview.yaml > /tmp/values.yaml` or die $!;
|
||||
}
|
||||
print `yq -i '.values' /tmp/values.yaml` or die $!;
|
||||
print `envsubst < ./kube/application.yaml > /tmp/application.yaml` or die $!;
|
||||
print `yq -i '.spec.source.helm.values = load_str("/tmp/values.yaml")' /tmp/application.yaml` or die $!;
|
||||
|
||||
if(!defined $ENV{DEPLOY_SCRIPT_DEBUG}){
|
||||
print `kubectl apply -f /tmp/application.yaml` or die $!;
|
||||
print `argocd app sync -l application=badhouseplants -l branch=$git_branch` or die $!;
|
||||
print `argocd app wait -l application=badhouseplants -l branch=$git_branch` or die $!;
|
||||
}
|
||||
# ----------------------------------
|
||||
# -- Remove all `Applications` for
|
||||
# -- branches that do not exists
|
||||
# ----------------------------------
|
||||
my @all_applications = `argocd app list -l application=badhouseplants -o yaml | yq '.[].metadata.name'` or die $!;
|
||||
chomp(@all_applications);
|
||||
foreach my $app (@all_applications) {
|
||||
$app =~ s/badhouseplants-//;
|
||||
}
|
||||
|
||||
my @all_branches = `git branch --format='%(refname:short)' -r` or die $!;
|
||||
chomp(@all_branches);
|
||||
foreach my $branch (@all_branches) {
|
||||
$branch =~ s/origin\///;
|
||||
}
|
||||
|
||||
foreach my $app (@all_applications) {
|
||||
if ( !grep( /^$app$/, @all_branches ) ) {
|
||||
if ($app ne "application") {
|
||||
print "$app should be removed\n";
|
||||
if(!defined $ENV{DEPLOY_SCRIPT_DEBUG}){
|
||||
print `argocd app delete --yes badhouseplants-$app` or die $!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user