Use a custom image for building and more scripts

This commit is contained in:
Nikolai Rodionov
2023-04-24 18:01:13 +02:00
parent 27b1b4acc0
commit b5e304bc3c
10 changed files with 213 additions and 48 deletions

32
scripts/build-container.pl Executable file
View File

@ -0,0 +1,32 @@
#! /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";