forked from EvergreenCrypto/docker-finance
client: lib_docker: factor env gen into lib_gen
- Related environment refactoring
This commit is contained in:
@@ -49,31 +49,21 @@ fi
|
||||
# Remaining "constructor" implementation
|
||||
function lib_docker::__docker()
|
||||
{
|
||||
# TODO: refactor into lib_gen
|
||||
# Docker-related files
|
||||
[ -z "$DOCKER_FINANCE_CLIENT_REPO" ] && lib_utils::die_fatal
|
||||
declare -g global_repo_dockerfiles="${DOCKER_FINANCE_CLIENT_REPO}/client/Dockerfiles/"
|
||||
# Inherited from caller
|
||||
[ -z "$global_container" ] && lib_utils::die_fatal
|
||||
[ -z "$global_image" ] && lib_utils::die_fatal
|
||||
[ -z "$global_network" ] && lib_utils::die_fatal
|
||||
[ -z "$global_platform" ] && lib_utils::die_fatal
|
||||
[ -z "$global_tag" ] && lib_utils::die_fatal
|
||||
|
||||
case "$global_platform" in
|
||||
archlinux | ubuntu)
|
||||
global_repo_dockerfiles+="finance"
|
||||
;;
|
||||
dev-tools)
|
||||
global_repo_dockerfiles+="dev-tools"
|
||||
;;
|
||||
*)
|
||||
lib_utils::die_fatal "platform was not previously checked"
|
||||
;;
|
||||
esac
|
||||
# Inherited from caller (via lib_gen)
|
||||
[ -z "$global_client_version" ] && lib_utils::die_fatal
|
||||
[ -z "$global_repo_dockerfiles" ] && lib_utils::die_fatal
|
||||
|
||||
#
|
||||
# Generate docker-compose.yml
|
||||
#
|
||||
|
||||
[ -z "$global_env_file" ] && lib_utils::die_fatal
|
||||
[ -z "$global_shell_file" ] && lib_utils::die_fatal
|
||||
[ -z "$global_repo_dockerfiles" ] && lib_utils::die_fatal
|
||||
|
||||
local _path="${global_repo_dockerfiles}/docker-compose.yml"
|
||||
lib_utils::print_debug "Generating '${_path}'"
|
||||
|
||||
|
||||
@@ -53,7 +53,10 @@ fi
|
||||
#
|
||||
# Sets client-side environment with defaults or use existing environment
|
||||
#
|
||||
# NOTE: some bootstrapped defaults are ignored by environment file (as seen below)
|
||||
#
|
||||
|
||||
# TODO: further refactoring; make clearer transient env vars versus persistent env vars
|
||||
function lib_gen::gen()
|
||||
{
|
||||
lib_utils::print_debug "Constructing environment"
|
||||
@@ -75,22 +78,34 @@ function lib_gen::gen()
|
||||
[ ! -f "$global_repo_env_file" ] \
|
||||
&& lib_utils::die_fatal "Missing environment defaults! ($global_repo_env_file)"
|
||||
|
||||
# Custom Dockerfile (to be appended to final Dockerfile)
|
||||
local _image
|
||||
#
|
||||
# Dockerfiles
|
||||
#
|
||||
|
||||
# Set image type
|
||||
[ -z "$global_platform" ] && lib_utils::die_fatal
|
||||
case "$global_platform" in
|
||||
archlinux | ubuntu)
|
||||
_image+="finance"
|
||||
global_platform_image="finance"
|
||||
;;
|
||||
dev-tools)
|
||||
_image+="dev-tools"
|
||||
global_platform_image="dev-tools"
|
||||
;;
|
||||
*)
|
||||
lib_utils::die_fatal "unsupported platform"
|
||||
;;
|
||||
esac
|
||||
declare -gr global_repo_dockerfile="${global_repo_conf_dir}/client/Dockerfiles/${_image}/Dockerfile.${global_platform}.in"
|
||||
[ ! -f "$global_repo_dockerfile" ] \
|
||||
&& lib_utils::die_fatal "Missing environment defaults! ($global_repo_dockerfile)"
|
||||
declare -gr global_platform_image
|
||||
|
||||
# Base location of Docker-related files (.in and final out files)
|
||||
global_repo_dockerfiles="$(dirname "$(realpath -s $0)")/Dockerfiles/${global_platform_image}"
|
||||
# shellcheck disable=SC2034 # used in lib_docker
|
||||
declare -gr global_repo_dockerfiles
|
||||
|
||||
# Base custom end-user .in Dockerfile (to be appended to final Dockerfile after installation)
|
||||
declare -gr global_repo_custom_dockerfile="${global_repo_conf_dir}/client/Dockerfiles/${global_platform_image}/Dockerfile.${global_platform}.in"
|
||||
[ ! -f "$global_repo_custom_dockerfile" ] \
|
||||
&& lib_utils::die_fatal "Missing default custom Dockerfile '${global_repo_custom_dockerfile}'"
|
||||
|
||||
#
|
||||
# If empty environment, bootstrap with defaults
|
||||
@@ -114,9 +129,7 @@ function lib_gen::gen()
|
||||
# Reset environment with user-provided (user-defined) existing file (if available)
|
||||
#
|
||||
|
||||
[ -z "$global_platform" ] && lib_utils::die_fatal
|
||||
[ -z "$global_tag" ] && lib_utils::die_fatal
|
||||
|
||||
local -r _env_dir="${DOCKER_FINANCE_CLIENT_CONF}/client/$(uname -s)-$(uname -m)/${global_platform}/${global_tag}/env"
|
||||
local -r _env_file="${_env_dir}/${global_conf_filename}"
|
||||
|
||||
@@ -132,6 +145,7 @@ function lib_gen::gen()
|
||||
lib_gen::__write_env "$_env_file"
|
||||
fi
|
||||
else
|
||||
[ -z "$global_command" ] && lib_utils::die_fatal
|
||||
[ -z "$global_basename" ] && lib_utils::die_fatal
|
||||
|
||||
if [[ -z "$global_command" || "$global_command" != "gen" ]]; then
|
||||
@@ -318,12 +332,10 @@ function lib_gen::__gen_client()
|
||||
lib_utils::print_custom " \e[32m│\e[0m\n"
|
||||
lib_utils::print_custom " \e[32m├─\e[34;1m Generating new custom (optional) Dockerfile\e[0m\n"
|
||||
|
||||
if [ ! -f "$global_custom_dockerfile" ]; then
|
||||
lib_utils::print_debug "$global_repo_dockerfile"
|
||||
lib_utils::print_debug "$global_custom_dockerfile"
|
||||
lib_utils::print_debug "$global_repo_custom_dockerfile"
|
||||
lib_utils::print_debug "$global_custom_dockerfile"
|
||||
|
||||
cp -a "$global_repo_dockerfile" "$global_custom_dockerfile"
|
||||
fi
|
||||
cp -a "$global_repo_custom_dockerfile" "$global_custom_dockerfile"
|
||||
fi
|
||||
|
||||
lib_utils::print_custom " \e[32m│ └─\e[34m Edit (new) custom Dockerfile now? [Y/n] \e[0m"
|
||||
|
||||
Reference in New Issue
Block a user