🦈🏠🐜 Initial Commit 🐜🦈🏠

This commit is contained in:
casjay
2023-04-06 19:28:01 -04:00
commit 9b376b0fd6
166 changed files with 79846 additions and 0 deletions

115
init/bin/act-runner Normal file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf '%s\n' "# - - - Initializing act_runner - - - #"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SERVICE_NAME="act_runner"
SCRIPT_NAME="$(basename "$0" 2>/dev/null)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run trap command on exit
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "true" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM EXIT
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Default predefined variables
exitCode=0 # default exit code
WORKDIR="" # set working directory
DATA_DIR="/data" # set data directory
RUN_DIR="/run/init.d" # set scripts pid dir
ETC_DIR="/etc/act_runner" # set etc directory
CONF_DIR="/config/act_runner" # set config directory
LOG_DIR="/data/logs/act_runner" # set log directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# execute command variables
SERVICE_UID="0" # set the user id
SERVICE_USER="root" # execute command as another user
EXEC_CMD_BIN="act_runner" # command to execute
EXEC_CMD_ARGS="daemon " # command arguments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional variables
GITEA_PORT="${GITEA_PORT:-$SERVICE_PORT}"
RUNNER_AUTH_TOKEN="${RUNNER_AUTH_TOKEN:-}"
GITEA_HOSTNAME="${GITEA_SERVER:-${DOMAINNAME:-$HOSTNAME}}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# simple cd function
__cd() { mkdir -p "$1" && builtin cd "$1" || exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# process check functions
__pcheck() { [ -n "$(type -P pgrep 2>/dev/null)" ] && pgrep -x "$1" &>/dev/null && return 0 || return 10; }
__pgrep() { __pcheck "${1:-EXEC_CMD_BIN}" || __ps aux 2>/dev/null | grep -Fw " ${1:-$EXEC_CMD_BIN}" | grep -qv ' grep' | grep '^' && return 0 || return 10; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check if process is already running
__proc_check() {
local cmd_bin="" cmd_name=""
cmd_bin="${1:-$EXEC_CMD_BIN}"
cmd_name="$(basename "$cmd_bin")"
if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then
SERVICE_IS_RUNNING="true"
touch "$SERVICE_PID_FILE"
echo "$cmd_name is already running"
return 0
else
return 1
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# create directories
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
[ -d "$CONF_DIR" ] || mkdir -p "$CONF_DIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# create directories if variable is yes
[ "$IS_WEB_SERVER" = "yes" ] && { [ -d "$WWW_DIR" ] || mkdir -p "$WWW_DIR"; }
[ "$IS_DATABASE_SERVICE" = "yes" ] && mkdir -p "$DATABASE_DIR" && chmod -f 777 "$DATABASE_DIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# copy config files
[ -d "$CONF_DIR" ] && cp -Rf "$CONF_DIR/." "$ETC_DIR/"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# custom commands
if [ ! -f "$CONF_DIR/default.conf" ]; then
echo "# Settings for the default gitea runner" >"$CONF_DIR/default.conf"
echo "RUNNER_NAME=\"local\"" >>"$CONF_DIR/default.conf"
echo "RUNNER_LABELS=\"ubuntu-latest\"" >>"$CONF_DIR/default.conf"
echo "RUNNER_AUTH_TOKEN=\"${RUNNER_AUTH_TOKEN:-}\"" >>"$CONF_DIR/default.conf"
echo "GITEA_HOSTNAME=\"${GITEA_HOSTNAME:-}\"" >>"$CONF_DIR/default.conf"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# fix permissions
chmod -f 777 "$LOG_DIR" "$RUN_DIR"
[ -d "$DATABASE_DIR" ] && chmod -f 777 "$DATABASE_DIR"
if [ -n "$SERVICE_USER" ] && [ "$SERVICE_USER" != "root" ]; then
if grep -s -q "$SERVICE_USER:" "/etc/passwd"; then
chown -Rf $SERVICE_USER:$SERVICE_USER "$ETC_DIR" "$WWW_DIR" "$LOG_DIR" && echo "changed ownership to $SERVICE_USER"
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Initialize runners
for runner in "$CONF_DIR"/*.conf; do
runner_name="$(basename "$runner")"
runner_name="${runner_name//.conf/}"
RUNNER_LABELS="linux"
RUNNER_NAME="$runner_name"
GITEA_HOSTNAME="${GITEA_HOSTNAME:-$HOSTNAME}"
while :; do
[ -f "$RUN_DIR/act_runner.$RUNNER_NAME.pid" ] && break
if [ -z "$RUNNER_AUTH_TOKEN" ]; then
echo "Error: Can not start runner: RUNNER_AUTH_TOKEN is not set" >&2
echo "visit $GITEA_HOSTNAME:$GITEA_PORT/admin/runners" >&2
echo "And edit $runner" >&2
fi
[ -f "$runner" ] && . "$runner"
if [ -n "$RUNNER_AUTH_TOKEN" ]; then
echo "RUNNER_AUTH_TOKEN has been set"
(act_runner register --labels "$RUNNER_LABELS" --name "$RUNNER_NAME" --instance "http://$GITEA_HOSTNAME" --token "$RUNNER_AUTH_TOKEN" --no-interactive || return 1) &
[ $? -eq 0 ] && echo "$!" >"$RUN_DIR/act_runner.$RUNNER_NAME.pid"
break
else
sleep 120
fi
done
done
echo "$$" >"$RUN_DIR/act_runner.pid"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit $exitCode

42
init/bin/buildah-build Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202303142021-git
# @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.com
# @@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

147
init/bin/ddns Executable file
View File

@@ -0,0 +1,147 @@
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202303291250-git
# @@Author : Jason Hempstead
# @@Contact : git-admin@casjaysdev.com
# @@License : WTFPL
# @@ReadME : ddns --help
# @@Copyright : Copyright: (c) 2023 Jason Hempstead, Casjays Developments
# @@Created : Wednesday, Mar 29, 2023 12:50 EDT
# @@File : ddns
# @@Description : newScript
# @@Changelog : newScript
# @@TODO : Refactor code
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : bash/system
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
APPNAME="$(basename "$0")"
VERSION="202303291250-git"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options
set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__run_dns() { named-checkconf -z "/etc/named.conf" && named -c "/etc/named.conf" || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SHORT_HOST="$(hostname -s)"
DOMAIN_HOST="${DOMAIN_NAME:-$(hostname -f || echo 'test')}"
NETDEV="$(ip route 2>/dev/null | grep default | sed -e "s/^.*dev.//" -e "s/.proto.*//" | awk '{print $1}')"
IPV4_ADDR="$(ifconfig $NETDEV 2>/dev/null | grep -E "venet|inet" | grep -v "127.0.0." | grep 'inet' | grep -v inet6 | awk '{print $2}' | sed s/addr://g | head -n1 | grep '^' || echo '')"
IPV6_ADDR="$(ifconfig "$NETDEV" 2>/dev/null | grep -E "venet|inet" | grep 'inet6' | grep -i global | awk '{print $2}' | head -n1 | grep '^' || echo '')"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DATE="$(date +'%Y%m%d%M')"
OLD_DATE="${OLD_DATE:-2018020901}"
DOMAIN_NAME="${DOMAIN_NAME:-$FULL_HOST}"
IPV4_ADDR_GATEWAY="$(ip route show default | awk '/default/ {print $3}' | head -n1 | grep '^' || echo '')"
IPV4_ADDR="${IPV4_ADDR:-10.0.0.2}"
IPV4_ADDR_SUBNET="${IPV4_ADDR_SUBNET:-10.0.0.0}"
IPV4_ADDR_START="${IPV4_ADDR_START:-10.0.100.1}"
IPV4_ADDR_END="${IPV4_ADDR_END:-10.0.100.254}"
IPV4_ADDR_NETMASK="${IPV4_ADDR_NETMASK:-255.255.0.0}"
IPV4_ADDR_GATEWAY="${IPV4_ADDR_GATEWAY:-10.0.0.1}"
IPV6_ADDR="${IP6_ADDR:-2001:0db8:edfa:1234::2}"
IPV6_ADDR_SUBNET="${IPV6_ADDR_SUBNET:-2001:0db8:edfa:1234::}"
IPV6_ADDR_START="${IPV6_ADDR_START:-2001:0db8:edfa:1234:5678::1}"
IPV6_ADDR_END="${IPV6_ADDR_END:-2001:0db8:edfa:1234:5678::ffff}"
IPV6_ADDR_NETMASK="${IPV6_ADDR_NETMASK:-64}"
IPV6_ADDR_GATEWAY="${IPV6_ADDR_GATEWAY:-2001:0db8:edfa:1234::1}"
[ "$DOMAIN_NAME" == "local" ] && DOMAIN_NAME="test"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -f "/config/rndc.key" ] || rndc-confgen -a -c /etc/rndc.key &>>/data/logs/named.log
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RNDC_KEY="$(cat "/etc/rndc.key" | grep 'secret' | awk '{print $2}' | sed 's|;||g;s|"||g')"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -f "/config/rndc.key" ] || cp -Rf "/etc/rndc.key" "/config/rndc.key" &>>/data/logs/entrypoint.log
[ -f "/config/rndc.conf" ] || { [ -f "/etc/rndc.conf" ] && cp -Rf "/etc/rndc.conf" "/config/rndc.conf" &>>/data/logs/entrypoint.log; }
[ -d "/run/tor" ] || mkdir -p "/run/tor" &>>/data/logs/entrypoint.log
[ -d "/etc/dhcp" ] || mkdir -p "/etc/dhcp" &>>/data/logs/entrypoint.log
[ -d "/run/dhcp" ] || mkdir -p "/run/dhcp" &>>/data/logs/entrypoint.log
[ -d "/var/tftpboot" ] && [ ! -d "/data/tftp" ] && mv -f "/var/tftpboot" "/data/tftp" &>>/data/logs/entrypoint.log
[ -d "/var/lib/dhcp" ] || mkdir -p "/var/lib/dhcp" &>>/data/logs/entrypoint.log
[ -d "/data/tor" ] || cp -Rf "/var/lib/tor" "/data/tor" &>>/data/logs/entrypoint.log
[ -d "/data/htdocs/www" ] || cp -Rf "/var/lib/ddns/data/htdocs/www" "/data/htdocs/www" &>>/data/logs/entrypoint.log
[ -d "/data/named" ] || cp -Rf "/var/lib/ddns/data/named" "/data/named" &>>/data/logs/entrypoint.log
[ -d "/config/tor" ] || cp -Rf "/var/lib/ddns/config/tor" "/config/tor" &>>/data/logs/entrypoint.log
[ -d "/config/dhcp" ] || cp -Rf "/var/lib/ddns/config/dhcp" "/config/dhcp" &>>/data/logs/entrypoint.log
[ -d "/config/named" ] || cp -Rf "/var/lib/ddns/config/named" "/config/named" &>>/data/logs/entrypoint.log
[ -f "/config/radvd.conf" ] || cp -Rf "/var/lib/ddns/config/radvd.conf" "/config/radvd.conf" &>>/data/logs/entrypoint.log
[ -f "/config/named.conf" ] || cp -Rf "/var/lib/ddns/config/named.conf" "/config/named.conf" &>>/data/logs/entrypoint.log
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
find "/config" "/data" -type f -exec sed -i 's|'${OLD_DATE:-2018020901}'|'$DATE'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_DOMAIN|'$DOMAIN_NAME'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_WITH_RNDC_KEY|'$RNDC_KEY'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV4_ADDRESS|'$IPV4_ADDR'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV4_ADDR_START|'$IPV4_ADDR_START'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV4_ADDR_END|'$IPV4_ADDR_END'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV4_SUBNET|'$IPV4_ADDR_SUBNET'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV4_NETMASK|'$IPV4_ADDR_NETMASK'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV4_GATEWAY|'$IPV4_ADDR_GATEWAY'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV6_ADDRESS|'$IPV6_ADDR'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV6_ADDR_START|'$IPV6_ADDR_START'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV6_ADDR_END|'$IPV6_ADDR_END'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV6_SUBNET|'$IPV6_ADDR_SUBNET'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV6_NETMASK|'$IPV6_ADDR_NETMASK'|g' {} \;
find "/config" "/data" -type f -exec sed -i 's|REPLACE_IPV6_GATEWAY|'$IPV6_ADDR_GATEWAY'|g' {} \;
if [ -f "/config/named.conf" ]; then
echo "Initializing named" &>>/data/logs/entrypoint.log
rm -R /data/logs/dns/* &>>/data/logs/entrypoint.log
cp -Rf "/config/named.conf" "/etc/named.conf"
[ -d "/data/logs/dns" ] || mkdir -p "/data/logs/dns"
[ -d "/data/named" ] && cp -Rf "/data/named" "/var/named"
[ -d "/config/named" ] && cp -Rf "/config/named" "/etc/named"
[ -f "/config/rndc.key" ] && cp -Rf "/config/rndc.key" "/etc/rndc.key"
[ -f "/config/rndc.conf" ] && cp -Rf "/config/rndc.conf" "/etc/rndc.conf"
chmod -f 777 "/data/logs/dns"
__run_dns &>>/data/logs/named.log &
sleep .5
fi
if [ -n "$IP6_ADDR" ]; then
if [ -f "/config/dhcp/dhcpd6.conf" ]; then
echo "Initializing dhcpd6" &>>/data/logs/entrypoint.log
cp -Rf "/config/dhcp/dhcpd6.conf" "/etc/dhcp/dhcpd6.conf"
touch /var/lib/dhcp/dhcpd6.leases
dhcpd -6 -cf /etc/dhcp/dhcpd6.conf &>>/data/logs/dhcpd6.log &
sleep .5
fi
if [ -f "/config/radvd.conf" ]; then
echo "Initializing radvd" &>>/data/logs/entrypoint.log
cp -Rf "/config/radvd.conf" "/etc/radvd.conf"
radvd -C /etc/radvd.conf &>>/data/logs/radvd.log &
sleep .5
fi
fi
if [ -f "/config/dhcp/dhcpd4.conf" ]; then
echo "Initializing dhcpd4" &>>/data/logs/entrypoint.log
cp -Rf "/config/dhcp/dhcpd4.conf" "/etc/dhcp/dhcpd4.conf"
touch /var/lib/dhcp/dhcpd.leases
dhcpd -4 -cf /etc/dhcp/dhcpd4.conf &>>/data/logs/dhcpd4.log &
sleep .5
fi
if [ -d "/config/tor" ]; then
echo "Initializing tor" &>>/data/logs/entrypoint.log
[ -d "/config/tor" ] && cp -Rf "/config/tor" "/etc/tor"
chown -Rf root:root "/var/lib/tor"
chmod 700 "/run/tor"
tor -f "/etc/tor/torrc" &>>/data/logs/tor.log &
fi
if [ -d "/data/tftp" ]; then
echo "Initializing tftp" &>>/data/logs/entrypoint.log
rm -Rf "/var/tftpboot"
ln -sf "/data/tftp" "/var/tftpboot"
in.tftpd -vv -L "/var/tftpboot" &>/data/logs/tftpd.log &
fi
if [ -f "/data/htdocs/www/index.php" ]; then
echo "Initializing web on $IPV4_ADDR" &>>/data/logs/entrypoint.log
nginx -c "/etc/nginx/nginx.conf" &>>/data/logs/nginx.log &
sleep .5
fi
sleep 5
date +'%Y-%m-%d %H:%M' >/data/logs/entrypoint.log
echo "Initializing completed" &>>/data/logs/entrypoint.log
tail -n 80 -f /data/logs/*.log

105
init/bin/docker-buildx Normal file
View File

@@ -0,0 +1,105 @@
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202210141608-git
# @@Author : Jason Hempstead
# @@Contact : git-admin@casjaysdev.com
# @@License : LICENSE.md
# @@ReadME : buildx --help
# @@Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments
# @@Created : Friday, Oct 14, 2022 16:08 EDT
# @@File : buildx
# @@Description : Docker buildx wrapper
# @@Changelog : New script
# @@TODO : Refactor code
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : bash/system
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options
[ -n "$DEBUG" ] && set -x
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set functions
__image_exists() { docker ps -a 2>&1 | grep -q "$1" || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__buildx() {
local exitStatus=0 reg_tag="${1:-$TAG_NAME}" dir="${directory:-.}"
[ -n "$platforms" ] && build_platforms="--platform ${platforms/ /,}"
#[ -d "$PWD/.git" ] && git pull -q && echo "Updating git repo"
# Initialize
echo "Setting target platform to $platforms"
__image_exists "$qemu_imagename" || { echo "Initializing $qemu_imagename" && docker run -d --name "$qemu_imagename" --privileged multiarch/qemu-user-static --reset -p yes &>/dev/null; } #|| { echo "Failed to Initialize" && exit 1; }
__image_exists "$binfmt_imagename" || { echo "Initializing $binfmt_imagename" && docker run -d --name "$binfmt_imagename" --privileged tonistiigi/binfmt --install all &>/dev/null; } #|| { echo "Failed to Initialize" && exit 1; }
__image_exists "$buildername" || { echo "Setting the buildername to $buildername" && docker buildx create --driver docker-container --driver-opt network=host --driver-opt image=moby/buildkit:master --name "$buildername" --use &>/dev/null; } #|| { echo "Failed to Initialize" && exit 1; }
docker buildx use "$buildername" &>/dev/null #|| { echo "Failed to Initialize" && exit 1; }
docker buildx inspect --bootstrap &>/dev/null #|| { echo "Failed to Initialize" && exit 1; }
# Build
echo "Building $reg_tag"
eval docker buildx build --rm --pull \
--push --no-cache $build_platforms \
--progress auto --output=type=registry \
$reg_tag "$dir" || exitStatus=1
[ "$exitStatus" -eq 0 ] || echo "Failed to build $reg_tag"
# Cleanup
__image_exists "$buildername" && docker rm -f "$buildername" &>/dev/null
__image_exists "$qemu_imagename" && docker rm -f "$qemu_imagename" &>/dev/null
__image_exists "$binfmt_imagename" && docker rm -f "$binfmt_imagename" &>/dev/null
return $exitStatus
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -f "/root/.docker/config.json" ] || { echo "/root/.docker/config.json Does not exist did you mount it?" && exit 1; }
[ -d "/tmp/build" ] && cd "/tmp/build" || { echo "/tmp/build Does not exist did you mount your project?" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set additional variables
[ -f "$PWD/.env.sh" ] && . "$PWD/.env.sh"
[ -f "$1" ] && docker_file="$1" && shift 1 || docker_file="${FILE:-}"
[ -d "$1" ] && [ -f "$1/Dockerfile" ] && docker_file="$1/Dockerfile" && shift 1 || docker_file="${FILE:-}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TAG_NAME="${1:-$TAGS}"
REGISTRY="${REGISTRY:-}"
ORG="${ORG:-casjaysdevdocker}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exitCode=0
buildername="mybuilder"
qemu_imagename="buildx-qemu"
binfmt_imagename="buildx-binfmt"
platforms="${PLATFORMS:-linux/amd64,linux/arm64}"
docker_files="$(find "/tmp/build" -name 'Dockerfile*' 2>/dev/null | sort -u | grep '^' || false)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export DOCKER_CLI_EXPERIMENTAL="enabled"
echo "$TAG_NAME" | grep -q ':' || TAG_NAME="$TAG_NAME:latest"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -n "$docker_file" ] || [ -n "$docker_files" ] || { echo "USAGE: buildx [dir] [tagname]" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
clear
if [ -z "$(pgrep -x dockerd)" ]; then
echo "Starting dockerd"
start-docker.sh &>/dev/null &
sleep 10
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main application
if [ -n "$docker_file" ]; then
[ -n "$TAG_NAME" ] || { echo "USAGE: buildx [dir] [tagname]" && exit 1; }
directory="$(dirname "$docker_file")"
[ -n "$REGISTRY" ] && tag_name="$REGISTRY/$TAG_NAME" || tag_name="$TAG_NAME"
tag_name="$(echo "$REGISTRY/$TAG_NAME" | tr '[:upper:]' '[:lower:]')"
cd "$directory" && __buildx "$tag_name" || exitCode+="$((exitCode + 1))"
elif [ -n "$docker_files" ]; then
for file in $docker_files; do
directory="$(dirname "$file")"
image_name="$(echo $ORG/$(basename "$directory") | tr '[:upper:]' '[:lower:]')"
[ -n "$REGISTRY" ] && tag_name="$REGISTRY/$image_name:latest" || tag_name="$image_name:latest"
cd "$directory" && __buildx "$tag_name" || exitCode+="$((exitCode + 1))"
done
else
echo "Can not find a Dockerfile in /tmp/build"
exitCode=10
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit $exitCode
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# end