#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version           :  202303142021-git
# @@Author           :  Jason Hempstead
# @@Contact          :  jason@casjaysdev.pro
# @@License          :  LICENSE.md
# @@ReadME           :  build-project --help
# @@Copyright        :  Copyright: (c) 2023 Jason Hempstead, Casjays Developments
# @@Created          :  Tuesday, Mar 14, 2023 20:21 EDT
# @@File             :  build-project
# @@Description      :
# @@Changelog        :  New script
# @@TODO             :  Better documentation
# @@Other            :
# @@Resource         :
# @@Terminal App     :  no
# @@sudo/root        :  no
# @@Template         :  shell/sh
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HOME="${USER_HOME:-$HOME}"
USER="${SUDO_USER:-$USER}"
RUN_USER="${SUDO_USER:-$USER}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Export variables
WORKDIR="${WORKDIR:-/data/build}"
BUILDAH_ISOLATION="${BUILDAH_ISOLATION:-chroot}"
PLATFORMS="${PLATFORMS:---platform=linux/amd64,linux/arm64}"
DOCKER_FILE="${*:-$(find "$WORKDIR" -maxdepth 10 -name 'Dockerfile*' 2>/dev/null | grep '^' || false)}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main application
if [ -n "$DOCKER_FILE" ]; then
  for file in $DOCKER_FILE; do
    buildah build $PLATFORMS "$file"
  done
else
  echo "Can not find any dockerfiles in /data/build"
  exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# End application
# ex: ts=2 sw=2 et filetype=sh
