56 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
| #!/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
 | |
| # ---------------------------------------------------------------------------
 | |
| 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";
 | |
| 0 == system ("buildah login --username $username --password $password $container_registry") or die $!;
 | |
| 0 == system ("buildah build -t $tag .") or die $!;
 | |
| 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";
 | |
| 	0 == system ("buildah tag $tag $latest_tag") or die $!;
 | |
|     0 == system ("buildah push $latest_tag") or die $!;
 | |
| }
 | |
| 
 | |
| print "Thanks!\n";
 | 
