This repository has been archived on 2024-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
badhouseplants-net-old/scripts/build-container.pl

33 lines
1.3 KiB
Perl
Raw Permalink Normal View History

#! /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";
2023-05-23 15:53:26 +00:00
print `buildah login --username $username --password $password $container_registry` or die $!;
print `buildah build -t $tag .` or die $!;
print `buildah push $tag` or die $!;
# -------------------------------------------------
2023-05-23 15:53:26 +00:00
# -- Push the latest if the branch is main
# -------------------------------------------------
if ( $git_branch eq $main_branch) {
my $latest_tag = "$container_registry/$image_name:latest";
2023-05-23 15:53:26 +00:00
print `buildah tag $tag $latest_tag` or die $!;
print `buildah push $latest_tag` or die $!;
}
print "Thanks!\n";