docker-finance | modern accounting for the power-user
Dedicated to Michael Morgan: a beautiful, beautiful soul.
---
Internal signing keys:
Aaron Fiore (sole author)
- 518A22F85BEFD32BCC99C48603F90C4F35E0213E
- 31ECA5C347A0CC0815EDE730A3EACCFCDA7E685E
- C8187C585CB07A4DA81CC0F37318B50EBE9C0DA8
Internal repositories (rebased from):
Staging:
$ git log -n1 --pretty=format:"%H"
c8e0cd66f6c89fa7b3c62f72fb524a4cc454b7b6
$ git rev-list --max-parents=0 HEAD
ac3863b8c234755855f1aea3a07a853122decdf2
Private:
$ git log -n1 --pretty=format:"%H"
69bb3591eaa2990a9637832bb484690e00c4f926
$ git rev-list --max-parents=0 HEAD
a5c1cc9fb593c4cf09bc0adfef6cb6d2964511ae
This commit is contained in:
312
client/src/docker/lib/lib_docker.bash
Normal file
312
client/src/docker/lib/lib_docker.bash
Normal file
@@ -0,0 +1,312 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# docker-finance | modern accounting for the power-user
|
||||
#
|
||||
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#
|
||||
# "Libraries"
|
||||
#
|
||||
|
||||
# Docker impl
|
||||
source "$(dirname "$(realpath -s $0)")/src/docker/lib/internal/lib_docker.bash" || exit 1
|
||||
|
||||
# Environment generation
|
||||
source "$(dirname "$(realpath -s $0)")/src/docker/lib/internal/lib_gen.bash" || exit 1
|
||||
|
||||
# Development tools
|
||||
source "$(dirname "$(realpath -s $0)")/src/docker/lib/internal/dev-tools/lib_doxygen.bash" || exit 1
|
||||
source "$(dirname "$(realpath -s $0)")/src/docker/lib/internal/dev-tools/lib_license.bash" || exit 1
|
||||
source "$(dirname "$(realpath -s $0)")/src/docker/lib/internal/dev-tools/lib_linter.bash" || exit 1
|
||||
|
||||
# Utilities (a container library (but container is never exposed to client code))
|
||||
source "$(dirname "$(realpath -s $0)")/../container/src/finance/lib/internal/lib_utils.bash" || exit 1
|
||||
|
||||
#
|
||||
# Implementation
|
||||
#
|
||||
|
||||
if [ $UID -lt 1000 ]; then
|
||||
lib_utils::die_fatal "Do not run as root or system user!"
|
||||
fi
|
||||
|
||||
# Dependencies
|
||||
deps=("sed")
|
||||
lib_utils::deps_check "${deps[@]}"
|
||||
|
||||
# Top-level caller
|
||||
global_basename="$(basename $0)"
|
||||
declare -rx global_basename
|
||||
|
||||
# Globals argument delimiters
|
||||
# NOTE: argument parsing will use this unified format
|
||||
[ -z "$global_arg_delim_1" ] && declare -rx global_arg_delim_1="/"
|
||||
[ -z "$global_arg_delim_2" ] && declare -rx global_arg_delim_2="="
|
||||
[ -z "$global_arg_delim_3" ] && declare -rx global_arg_delim_3=","
|
||||
|
||||
# "Constructor" for client environment
|
||||
function lib_docker::docker()
|
||||
{
|
||||
# Instance format:
|
||||
#
|
||||
# docker-finance/platform/user:tag
|
||||
#
|
||||
# Where user supplies:
|
||||
#
|
||||
# platform/user:tag
|
||||
|
||||
[[ -z "$1" || -z "$2" ]] && return 2
|
||||
[[ ! "$1" =~ $global_arg_delim_1 ]] && return 2
|
||||
|
||||
# Parse image
|
||||
IFS="/" read -ra _image <<<"$1"
|
||||
declare -g global_platform="${_image[0]}"
|
||||
local -r _user="${_image[1]}"
|
||||
lib_utils::print_debug "global_platform=${global_platform}"
|
||||
|
||||
if [[ ! "$global_platform" =~ ^archlinux$|^ubuntu$|^dev-tools$ ]]; then
|
||||
lib_utils::print_warning "unsupported platform '${global_platform}', defaulting to Arch Linux"
|
||||
global_platform="archlinux"
|
||||
fi
|
||||
|
||||
# Parse tag
|
||||
IFS=":" read -ra _tag <<<"$_user"
|
||||
declare -g global_user="${_tag[0]}"
|
||||
declare -g global_tag="${_tag[1]}"
|
||||
[ -z "$global_tag" ] && global_tag="latest" # TODO: needs to make sense, actually have version-related functionality with client conf
|
||||
lib_utils::print_debug "global_user=${global_user}"
|
||||
lib_utils::print_debug "global_tag=${global_tag}"
|
||||
|
||||
# Set instance name
|
||||
declare -gr global_image="docker-finance/${global_platform}/${global_user}"
|
||||
declare -gr global_container="docker-finance_${global_platform}_${global_user}"
|
||||
declare -gr global_network="docker-finance_${global_platform}"
|
||||
lib_utils::print_debug "global_image=${global_image}"
|
||||
lib_utils::print_debug "global_container=${global_container}"
|
||||
lib_utils::print_debug "global_network=${global_network}"
|
||||
|
||||
# Instance command
|
||||
declare -gr global_command="$2"
|
||||
lib_utils::print_debug "global_command=${global_command}"
|
||||
|
||||
# Convenience usage
|
||||
declare -gr global_usage="$global_basename ${global_platform}${global_arg_delim_1}${global_user}:${global_tag} $global_command"
|
||||
lib_utils::print_debug "global_usage=${global_usage}"
|
||||
|
||||
# Setup remaining client/container globals
|
||||
lib_gen::gen || return $?
|
||||
|
||||
[ -z "$global_repo_client" ] && lib_utils::die_fatal
|
||||
declare -g global_dockerfile_path="${global_repo_client}/Dockerfiles/"
|
||||
|
||||
case "$global_platform" in
|
||||
archlinux | ubuntu)
|
||||
global_dockerfile_path+="finance"
|
||||
;;
|
||||
dev-tools)
|
||||
global_dockerfile_path+="dev-tools"
|
||||
;;
|
||||
*)
|
||||
lib_utils::die_fatal "platform was not previously checked"
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# docker-compose
|
||||
#
|
||||
|
||||
[ -z "$global_env_file" ] && lib_utils::die_fatal
|
||||
[ -z "$global_shell_file" ] && lib_utils::die_fatal
|
||||
|
||||
local _path="${global_dockerfile_path}/docker-compose.yml"
|
||||
lib_utils::print_debug "Generating '${_path}'"
|
||||
|
||||
sed \
|
||||
-e "s|@DOCKER_FINANCE_IMAGE@|${global_image}:${global_tag}|g" \
|
||||
-e "s|@DOCKER_FINANCE_CONTAINER@|${global_container}|g" \
|
||||
-e "s|@DOCKER_FINANCE_NETWORK@|${global_network}|g" \
|
||||
"${_path}.${global_platform}.in" >"$_path" || return $?
|
||||
|
||||
#
|
||||
# Dockerfile
|
||||
#
|
||||
|
||||
[ -z "$DOCKER_FINANCE_UID" ] && lib_utils::die_fatal
|
||||
[ -z "$DOCKER_FINANCE_GID" ] && lib_utils::die_fatal
|
||||
[ -z "$DOCKER_FINANCE_USER" ] && lib_utils::die_fatal
|
||||
|
||||
local _path="${global_dockerfile_path}/Dockerfile"
|
||||
lib_utils::print_debug "Generating '${_path}'"
|
||||
|
||||
sed \
|
||||
-e "s:@DOCKER_FINANCE_UID@:${DOCKER_FINANCE_UID}:g" \
|
||||
-e "s:@DOCKER_FINANCE_GID@:${DOCKER_FINANCE_GID}:g" \
|
||||
-e "s:@DOCKER_FINANCE_USER@:${DOCKER_FINANCE_USER}:g" \
|
||||
"${_path}.${global_platform}.in" >"$_path" || return $?
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# Generate client/container environment
|
||||
#
|
||||
|
||||
function lib_docker::gen()
|
||||
{
|
||||
lib_gen::generate
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Build docker-finance image
|
||||
#
|
||||
|
||||
function lib_docker::build()
|
||||
{
|
||||
lib_docker::__build "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Bring up docker-finance services
|
||||
#
|
||||
|
||||
function lib_docker::up()
|
||||
{
|
||||
lib_docker::__up "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Bring down docker-finance services
|
||||
#
|
||||
|
||||
function lib_docker::down()
|
||||
{
|
||||
lib_docker::__down "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Start docker-finance services
|
||||
#
|
||||
|
||||
function lib_docker::start()
|
||||
{
|
||||
lib_docker::__start "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Stop docker-finance services
|
||||
#
|
||||
|
||||
function lib_docker::stop()
|
||||
{
|
||||
lib_docker::__stop "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Remove docker-finance image
|
||||
#
|
||||
|
||||
function lib_docker::rm()
|
||||
{
|
||||
lib_docker::__rm "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Spawn a docker-finance container with given command
|
||||
#
|
||||
|
||||
function lib_docker::run()
|
||||
{
|
||||
lib_docker::__run "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Open shell into docker-finance container
|
||||
#
|
||||
|
||||
function lib_docker::shell()
|
||||
{
|
||||
lib_docker::__shell "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Edit client configuration of given docker-finance instance
|
||||
#
|
||||
|
||||
function lib_docker::edit()
|
||||
{
|
||||
lib_docker::__edit "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Backup docker-finance image
|
||||
#
|
||||
|
||||
function lib_docker::backup()
|
||||
{
|
||||
lib_docker::__backup
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Generate docker-finance license for source file
|
||||
#
|
||||
|
||||
function lib_docker::license()
|
||||
{
|
||||
[[ "$global_platform" != "dev-tools" ]] \
|
||||
&& lib_utils::die_fatal "Invalid platform, use 'dev-tools'"
|
||||
|
||||
lib_license::license "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Lint docker-finance source files
|
||||
#
|
||||
|
||||
function lib_docker::linter()
|
||||
{
|
||||
[[ "$global_platform" != "dev-tools" ]] \
|
||||
&& lib_utils::die_fatal "Invalid platform, use 'dev-tools'"
|
||||
|
||||
lib_linter::linter "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
#
|
||||
# Generate Doxygen for docker-finance source files
|
||||
#
|
||||
|
||||
function lib_docker::doxygen()
|
||||
{
|
||||
[[ "$global_platform" != "dev-tools" ]] \
|
||||
&& lib_utils::die_fatal "Invalid platform, use 'dev-tools'"
|
||||
|
||||
lib_doxygen::doxygen "$@"
|
||||
lib_utils::catch $?
|
||||
}
|
||||
|
||||
# vim: sw=2 sts=2 si ai et
|
||||
Reference in New Issue
Block a user