33 lines
1.3 KiB
Perl
Executable File
33 lines
1.3 KiB
Perl
Executable File
#! /usr/bin/perl
|
|
use strict;
|
|
use warnings;
|
|
# -------------------------------------------------
|
|
# -- Setup Git variables
|
|
# -------------------------------------------------
|
|
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
|
my $git_commit_sha = `git rev-parse HEAD`;
|
|
my $main_branch = "main";
|
|
chomp($git_branch);
|
|
chomp($git_commit_sha);
|
|
# -------------------------------------------------
|
|
# -- Build the image with SHA tag
|
|
# -------------------------------------------------
|
|
my $container_registry = $ENV{'CONTAINER_REGISTRY'} || 'git.badhouseplants.net';
|
|
my $image_name = $ENV{'DRONE_REPO'} || "badhouseplants/badhouseplants-net";
|
|
my $tag = "$container_registry/$image_name:$git_commit_sha";
|
|
my $username = $ENV{'DRONE_USERNAME'} || "allanger";
|
|
my $password = $ENV{'GITEA_TOKEN'} || "YOU NOT AUTHORIZED, PAL";
|
|
print `buildah login --username $username --password $password $container_registry` or die;
|
|
print `buildah build -t $tag .` or die;
|
|
print `buildah push $tag` or die;
|
|
# -------------------------------------------------
|
|
# -- Push the lates if the branch is main
|
|
# -------------------------------------------------
|
|
if ( $git_branch eq $main_branch) {
|
|
my $latest_tag = "$container_registry/$image_name:latest";
|
|
print `buildah tag $tag $latest_tag` or die;
|
|
print `buildah push $latest_tag` or die;
|
|
}
|
|
|
|
print "Thanks!\n";
|