client: lib_docker: refactor for library support (plugins)
- Exports globals to caller for "library" support (export to `plugins`, etc.) - Removes enforcement of initializing "constructor" with 2nd arg (`command`) * Arg not needed since external/internal checks already in place * Context specific: if needed, caller should always check if set * Removal needed so library can be used within a library context - `basename` fix to allow for bash completion
This commit is contained in:
@@ -53,7 +53,7 @@ deps=("sed")
|
|||||||
lib_utils::deps_check "${deps[@]}"
|
lib_utils::deps_check "${deps[@]}"
|
||||||
|
|
||||||
# Top-level caller
|
# Top-level caller
|
||||||
global_basename="$(basename $0)"
|
global_basename="$(basename -- $0)"
|
||||||
declare -rx global_basename
|
declare -rx global_basename
|
||||||
|
|
||||||
# Globals argument delimiters
|
# Globals argument delimiters
|
||||||
@@ -67,18 +67,21 @@ function lib_docker::docker()
|
|||||||
{
|
{
|
||||||
# Instance format:
|
# Instance format:
|
||||||
#
|
#
|
||||||
# docker-finance/platform/user:tag
|
# docker-finance/platform/user:tag [command]
|
||||||
#
|
#
|
||||||
# Where user supplies:
|
# Where user supplies:
|
||||||
#
|
#
|
||||||
# platform/user:tag
|
# platform/user:tag [command]
|
||||||
|
#
|
||||||
|
# Where [command] is optional if only instantiating library
|
||||||
|
|
||||||
[[ -z "$1" || -z "$2" ]] && return 2
|
[ -z "$1" ] && return 2
|
||||||
[[ ! "$1" =~ $global_arg_delim_1 ]] && return 2
|
[[ ! "$1" =~ $global_arg_delim_1 ]] && return 2
|
||||||
|
[ -z "$2" ] && lib_utils::print_debug "command not given, assuming unused"
|
||||||
|
|
||||||
# Parse image
|
# Parse image
|
||||||
IFS="/" read -ra _image <<<"$1"
|
IFS="/" read -ra _image <<<"$1"
|
||||||
declare -g global_platform="${_image[0]}"
|
declare -gx global_platform="${_image[0]}"
|
||||||
local -r _user="${_image[1]}"
|
local -r _user="${_image[1]}"
|
||||||
lib_utils::print_debug "global_platform=${global_platform}"
|
lib_utils::print_debug "global_platform=${global_platform}"
|
||||||
|
|
||||||
@@ -89,26 +92,26 @@ function lib_docker::docker()
|
|||||||
|
|
||||||
# Parse tag
|
# Parse tag
|
||||||
IFS=":" read -ra _tag <<<"$_user"
|
IFS=":" read -ra _tag <<<"$_user"
|
||||||
declare -g global_user="${_tag[0]}"
|
declare -gx global_user="${_tag[0]}"
|
||||||
declare -g global_tag="${_tag[1]}"
|
declare -gx global_tag="${_tag[1]}"
|
||||||
[ -z "$global_tag" ] && global_tag="latest" # TODO: needs to make sense, actually have version-related functionality with client conf
|
[ -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_user=${global_user}"
|
||||||
lib_utils::print_debug "global_tag=${global_tag}"
|
lib_utils::print_debug "global_tag=${global_tag}"
|
||||||
|
|
||||||
# Set instance name
|
# Set instance name
|
||||||
declare -gr global_image="docker-finance/${global_platform}/${global_user}"
|
declare -gxr global_image="docker-finance/${global_platform}/${global_user}"
|
||||||
declare -gr global_container="docker-finance_${global_platform}_${global_user}"
|
declare -gxr global_container="docker-finance_${global_platform}_${global_user}"
|
||||||
declare -gr global_network="docker-finance_${global_platform}"
|
declare -gxr global_network="docker-finance_${global_platform}"
|
||||||
lib_utils::print_debug "global_image=${global_image}"
|
lib_utils::print_debug "global_image=${global_image}"
|
||||||
lib_utils::print_debug "global_container=${global_container}"
|
lib_utils::print_debug "global_container=${global_container}"
|
||||||
lib_utils::print_debug "global_network=${global_network}"
|
lib_utils::print_debug "global_network=${global_network}"
|
||||||
|
|
||||||
# Instance command
|
# Instance command
|
||||||
declare -gr global_command="$2"
|
declare -gxr global_command="$2"
|
||||||
lib_utils::print_debug "global_command=${global_command}"
|
lib_utils::print_debug "global_command=${global_command}"
|
||||||
|
|
||||||
# Convenience usage
|
# Convenience usage
|
||||||
declare -gr global_usage="$global_basename ${global_platform}${global_arg_delim_1}${global_user}:${global_tag} $global_command"
|
declare -gxr global_usage="$global_basename ${global_platform}${global_arg_delim_1}${global_user}:${global_tag} $global_command"
|
||||||
lib_utils::print_debug "global_usage=${global_usage}"
|
lib_utils::print_debug "global_usage=${global_usage}"
|
||||||
|
|
||||||
# Setup remaining client/container globals
|
# Setup remaining client/container globals
|
||||||
|
|||||||
Reference in New Issue
Block a user