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
|
# Remaining "constructor" implementation
|
||||||
function lib_docker::__docker()
|
function lib_docker::__docker()
|
||||||
{
|
{
|
||||||
# TODO: refactor into lib_gen
|
# Inherited from caller
|
||||||
# Docker-related files
|
[ -z "$global_container" ] && lib_utils::die_fatal
|
||||||
[ -z "$DOCKER_FINANCE_CLIENT_REPO" ] && lib_utils::die_fatal
|
[ -z "$global_image" ] && lib_utils::die_fatal
|
||||||
declare -g global_repo_dockerfiles="${DOCKER_FINANCE_CLIENT_REPO}/client/Dockerfiles/"
|
[ -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
|
# Inherited from caller (via lib_gen)
|
||||||
archlinux | ubuntu)
|
[ -z "$global_client_version" ] && lib_utils::die_fatal
|
||||||
global_repo_dockerfiles+="finance"
|
[ -z "$global_repo_dockerfiles" ] && lib_utils::die_fatal
|
||||||
;;
|
|
||||||
dev-tools)
|
|
||||||
global_repo_dockerfiles+="dev-tools"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
lib_utils::die_fatal "platform was not previously checked"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate docker-compose.yml
|
# 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"
|
local _path="${global_repo_dockerfiles}/docker-compose.yml"
|
||||||
lib_utils::print_debug "Generating '${_path}'"
|
lib_utils::print_debug "Generating '${_path}'"
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ fi
|
|||||||
#
|
#
|
||||||
# Sets client-side environment with defaults or use existing environment
|
# 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()
|
function lib_gen::gen()
|
||||||
{
|
{
|
||||||
lib_utils::print_debug "Constructing environment"
|
lib_utils::print_debug "Constructing environment"
|
||||||
@@ -75,22 +78,34 @@ function lib_gen::gen()
|
|||||||
[ ! -f "$global_repo_env_file" ] \
|
[ ! -f "$global_repo_env_file" ] \
|
||||||
&& lib_utils::die_fatal "Missing environment defaults! ($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
|
case "$global_platform" in
|
||||||
archlinux | ubuntu)
|
archlinux | ubuntu)
|
||||||
_image+="finance"
|
global_platform_image="finance"
|
||||||
;;
|
;;
|
||||||
dev-tools)
|
dev-tools)
|
||||||
_image+="dev-tools"
|
global_platform_image="dev-tools"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
lib_utils::die_fatal "unsupported platform"
|
lib_utils::die_fatal "unsupported platform"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
declare -gr global_repo_dockerfile="${global_repo_conf_dir}/client/Dockerfiles/${_image}/Dockerfile.${global_platform}.in"
|
declare -gr global_platform_image
|
||||||
[ ! -f "$global_repo_dockerfile" ] \
|
|
||||||
&& lib_utils::die_fatal "Missing environment defaults! ($global_repo_dockerfile)"
|
# 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
|
# 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)
|
# 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
|
[ -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_dir="${DOCKER_FINANCE_CLIENT_CONF}/client/$(uname -s)-$(uname -m)/${global_platform}/${global_tag}/env"
|
||||||
local -r _env_file="${_env_dir}/${global_conf_filename}"
|
local -r _env_file="${_env_dir}/${global_conf_filename}"
|
||||||
|
|
||||||
@@ -132,6 +145,7 @@ function lib_gen::gen()
|
|||||||
lib_gen::__write_env "$_env_file"
|
lib_gen::__write_env "$_env_file"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
[ -z "$global_command" ] && lib_utils::die_fatal
|
||||||
[ -z "$global_basename" ] && lib_utils::die_fatal
|
[ -z "$global_basename" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
if [[ -z "$global_command" || "$global_command" != "gen" ]]; then
|
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[0m\n"
|
||||||
lib_utils::print_custom " \e[32m├─\e[34;1m Generating new custom (optional) Dockerfile\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_custom_dockerfile"
|
||||||
lib_utils::print_debug "$global_repo_dockerfile"
|
|
||||||
lib_utils::print_debug "$global_custom_dockerfile"
|
lib_utils::print_debug "$global_custom_dockerfile"
|
||||||
|
|
||||||
cp -a "$global_repo_dockerfile" "$global_custom_dockerfile"
|
cp -a "$global_repo_custom_dockerfile" "$global_custom_dockerfile"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
lib_utils::print_custom " \e[32m│ └─\e[34m Edit (new) custom Dockerfile now? [Y/n] \e[0m"
|
lib_utils::print_custom " \e[32m│ └─\e[34m Edit (new) custom Dockerfile now? [Y/n] \e[0m"
|
||||||
|
|||||||
Reference in New Issue
Block a user