2023-05-27 21:07:58 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# ------------------------------------------------------------------------
|
|
|
|
# -- Copyright 2023 Nikolai Rodionov (allanger)
|
|
|
|
# ------------------------------------------------------------------------
|
|
|
|
# -- Permission is hereby granted, without written agreement and without
|
|
|
|
# -- license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
# -- software and its documentation for any purpose, provided that the
|
|
|
|
# -- above copyright notice and the following two paragraphs appear in
|
|
|
|
# -- all copies of this software.
|
|
|
|
# --
|
|
|
|
# -- IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
# -- DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
# -- ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
# -- IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
# -- DAMAGE.
|
|
|
|
# --
|
|
|
|
# -- THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
# -- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
# -- FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
# -- ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
# -- PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# -- Setup Git variables
|
|
|
|
# -- by default main branch should be "main"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
|
|
|
my $git_commit_sha = `git rev-parse HEAD`;
|
|
|
|
my $main_branch = $ENV{'GIT_MAIN_BRANCH'} || 'main';
|
|
|
|
chomp($git_branch);
|
|
|
|
chomp($git_commit_sha);
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# -- Build the image with SHA tag
|
|
|
|
# -- my main build system is DRONE, so I'm using DRONE variables a lot
|
|
|
|
# ---------------------------------------------------------------------------
|
2024-09-20 04:36:27 +00:00
|
|
|
my $container_registry = $ENV{'CONTAINER_REGISTRY'} || 'zot.badhouseplants.net';
|
2023-08-18 12:57:06 +00:00
|
|
|
my $image_name = $ENV{'PACKAGE_NAME'} | $ENV{'DRONE_REPO'} || "badhouseplants/badhouseplants-net";
|
2023-05-27 21:07:58 +00:00
|
|
|
my $tag = "$container_registry/$image_name:$git_commit_sha";
|
2023-08-18 12:57:06 +00:00
|
|
|
my $custom_tag = $ENV{'CUSTOM_TAG'} || "";
|
2024-09-20 04:55:11 +00:00
|
|
|
my $username = "woody";
|
2024-09-20 04:36:27 +00:00
|
|
|
my $password = $ENV{'REGISTRY_TOKEN'} || "YOU NOT AUTHORIZED, PAL";
|
2023-08-18 13:25:50 +00:00
|
|
|
my $containerfile = $ENV{'CONTAINERFILE'} || "Containerfile";
|
2024-02-27 15:35:31 +00:00
|
|
|
my $args = $ENV{'BUILD_ARGS'};
|
2023-05-27 21:07:58 +00:00
|
|
|
0 == system ("buildah login --username $username --password $password $container_registry") or die $!;
|
2024-02-27 15:35:31 +00:00
|
|
|
0 == system ("buildah bud -t $tag -f $containerfile $args .") or die $!;
|
2023-05-27 21:07:58 +00:00
|
|
|
0 == system ("buildah push $tag") or die $!;
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# -- Push the latest if the branch is main
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
if ( $git_branch eq $main_branch) {
|
|
|
|
my $latest_tag = "$container_registry/$image_name:latest";
|
2023-08-18 12:21:25 +00:00
|
|
|
0 == system ("buildah tag $tag $latest_tag") or die $!;
|
2023-05-27 21:07:58 +00:00
|
|
|
0 == system ("buildah push $latest_tag") or die $!;
|
|
|
|
}
|
2023-08-18 12:21:25 +00:00
|
|
|
if ( $custom_tag ne "" ) {
|
|
|
|
my $custom_tag_final = "$container_registry/$image_name:$custom_tag";
|
|
|
|
0 == system ("buildah tag $tag $custom_tag_final") or die $!;
|
|
|
|
0 == system ("buildah push $custom_tag_final") or die $!;
|
|
|
|
}
|
2023-05-27 21:07:58 +00:00
|
|
|
|
|
|
|
print "Thanks!\n";
|