client: lib_gen: generate custom Dockerfile
This commit is contained in:
@@ -62,10 +62,28 @@ function lib_gen::gen()
|
|||||||
global_repo_conf_dir="$(dirname "$(realpath -s $0)")/docker-finance.d"
|
global_repo_conf_dir="$(dirname "$(realpath -s $0)")/docker-finance.d"
|
||||||
declare -gr global_repo_conf_dir
|
declare -gr global_repo_conf_dir
|
||||||
|
|
||||||
|
# Environment
|
||||||
declare -gr global_repo_env_file="${global_repo_conf_dir}/client/env/gen.bash"
|
declare -gr global_repo_env_file="${global_repo_conf_dir}/client/env/gen.bash"
|
||||||
[ ! -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
|
||||||
|
case "$global_platform" in
|
||||||
|
archlinux | ubuntu)
|
||||||
|
_image+="finance"
|
||||||
|
;;
|
||||||
|
dev-tools)
|
||||||
|
_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)"
|
||||||
|
|
||||||
#
|
#
|
||||||
# If empty environment, bootstrap with defaults
|
# If empty environment, bootstrap with defaults
|
||||||
#
|
#
|
||||||
@@ -79,8 +97,8 @@ function lib_gen::gen()
|
|||||||
&& lib_utils::die_fatal "Defaults not generated! (${global_repo_env_file})"
|
&& lib_utils::die_fatal "Defaults not generated! (${global_repo_env_file})"
|
||||||
|
|
||||||
[ -z "$DOCKER_FINANCE_USER" ] && lib_utils::die_fatal
|
[ -z "$DOCKER_FINANCE_USER" ] && lib_utils::die_fatal
|
||||||
global_env_filename="${DOCKER_FINANCE_USER}@$(uname -n)"
|
global_conf_filename="${DOCKER_FINANCE_USER}@$(uname -n)"
|
||||||
declare -gr global_env_filename
|
declare -gr global_conf_filename
|
||||||
|
|
||||||
lib_gen::__set_client_globals
|
lib_gen::__set_client_globals
|
||||||
|
|
||||||
@@ -91,8 +109,8 @@ function lib_gen::gen()
|
|||||||
[ -z "$global_platform" ] && lib_utils::die_fatal
|
[ -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/env/$(uname -s)-$(uname -m)/${global_platform}/${global_tag}"
|
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_env_filename}"
|
local -r _env_file="${_env_dir}/${global_conf_filename}"
|
||||||
|
|
||||||
if [ -f "$_env_file" ]; then
|
if [ -f "$_env_file" ]; then
|
||||||
if [ -s "$_env_file" ]; then
|
if [ -s "$_env_file" ]; then
|
||||||
@@ -128,16 +146,21 @@ function lib_gen::__set_client_globals()
|
|||||||
lib_utils::print_debug "Setting client globals"
|
lib_utils::print_debug "Setting client globals"
|
||||||
|
|
||||||
# Appending all client-side conf paths
|
# Appending all client-side conf paths
|
||||||
local _client_path_tag
|
local _client_tag_path
|
||||||
_client_path_tag="$(uname -s)-$(uname -m)/${global_platform}/${global_tag}"
|
_client_tag_path="${DOCKER_FINANCE_CLIENT_CONF}/client/$(uname -s)-$(uname -m)/${global_platform}/${global_tag}"
|
||||||
|
|
||||||
# Client-side environment file (if available)
|
# Client-side environment file (if available)
|
||||||
local _client_env_dir="${DOCKER_FINANCE_CLIENT_CONF}/client/env/${_client_path_tag}"
|
local _client_env_dir="${_client_tag_path}/env"
|
||||||
|
|
||||||
[ ! -d "$_client_env_dir" ] && mkdir -p "$_client_env_dir"
|
[ ! -d "$_client_env_dir" ] && mkdir -p "$_client_env_dir"
|
||||||
global_env_file="${_client_env_dir}/${global_env_filename}"
|
global_env_file="${_client_env_dir}/${global_conf_filename}"
|
||||||
lib_utils::print_debug "global_env_file=${global_env_file}"
|
lib_utils::print_debug "global_env_file=${global_env_file}"
|
||||||
|
|
||||||
|
# Client-side custom Dockerfile (if available)
|
||||||
|
local _client_dockerfile_dir="${_client_tag_path}/Dockerfiles"
|
||||||
|
[ ! -d "$_client_dockerfile_dir" ] && mkdir -p "$_client_dockerfile_dir"
|
||||||
|
global_custom_dockerfile="${_client_dockerfile_dir}/${global_conf_filename}"
|
||||||
|
lib_utils::print_debug "global_custom_dockerfile=${global_custom_dockerfile}"
|
||||||
|
|
||||||
# NOTE:
|
# NOTE:
|
||||||
#
|
#
|
||||||
# Client env tag format is avoided because:
|
# Client env tag format is avoided because:
|
||||||
@@ -230,7 +253,11 @@ function lib_gen::__gen_client()
|
|||||||
{
|
{
|
||||||
lib_utils::print_debug "Generating client"
|
lib_utils::print_debug "Generating client"
|
||||||
|
|
||||||
# Backup existing client-side environment file
|
#
|
||||||
|
# Client-side environment file
|
||||||
|
#
|
||||||
|
|
||||||
|
# Backup existing file
|
||||||
if [ -f "$global_env_file" ]; then
|
if [ -f "$global_env_file" ]; then
|
||||||
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 Client-side environment found, backup then generate new one? [Y/n] \e[0m"
|
lib_utils::print_custom " \e[32m├─\e[34;1m Client-side environment found, backup then generate new one? [Y/n] \e[0m"
|
||||||
@@ -256,6 +283,38 @@ function lib_gen::__gen_client()
|
|||||||
# Get/Set new (edited) environment variables
|
# Get/Set new (edited) environment variables
|
||||||
lib_gen::__read_env "$global_env_file"
|
lib_gen::__read_env "$global_env_file"
|
||||||
lib_gen::__set_client_globals
|
lib_gen::__set_client_globals
|
||||||
|
|
||||||
|
#
|
||||||
|
# Custom (optional) Dockerfile
|
||||||
|
#
|
||||||
|
|
||||||
|
# Backup existing custom Dockerfile
|
||||||
|
if [ -f "$global_custom_dockerfile" ]; then
|
||||||
|
lib_utils::print_custom " \e[32m│\e[0m\n"
|
||||||
|
lib_utils::print_custom " \e[32m├─\e[34;1m Custom (optional) Dockerfile found, backup then generate new one? [Y/n] \e[0m"
|
||||||
|
|
||||||
|
read -p "" _read
|
||||||
|
local _confirm="${_read:-y}"
|
||||||
|
if [[ "$_confirm" == [yY] ]]; then
|
||||||
|
cp -a "$global_custom_dockerfile" "${global_custom_dockerfile}_${global_suffix}" \
|
||||||
|
|| lib_utils::die_fatal
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
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"
|
||||||
|
|
||||||
|
cp -a "$global_repo_dockerfile" "$global_custom_dockerfile"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
lib_utils::print_custom " \e[32m│ └─\e[34m Edit (new) custom Dockerfile now? [Y/n] \e[0m"
|
||||||
|
read -p "" _read
|
||||||
|
local _confirm="${_read:-y}"
|
||||||
|
[[ "$_confirm" == [yY] ]] && $EDITOR "$global_custom_dockerfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
function lib_gen::__gen_container()
|
function lib_gen::__gen_container()
|
||||||
|
|||||||
Reference in New Issue
Block a user