client: add custom compose merge file functionality
Like custom build functionality (custom Dockerfile), adds support for custom docker-compose.yml functionality: * Adds default custom compose file * Adds to run-time environment * Adds to `gen` and `edit`
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
# docker-finance | modern accounting for the power-user
|
||||||
|
#
|
||||||
|
# Copyright (C) 2021-2024,2026 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/>.
|
||||||
|
|
||||||
|
# docker-finance @DOCKER_FINANCE_VERSION@
|
||||||
|
|
||||||
|
## This is a custom compose file that will be *merged* with the base compose file
|
||||||
|
## See https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/ for details
|
||||||
|
|
||||||
|
## An example of adding a custom volume and environment variables
|
||||||
|
## NOTE: *MUST* also add these variables to the env file (`edit type=env`)
|
||||||
|
#services:
|
||||||
|
# docker-finance:
|
||||||
|
# volumes:
|
||||||
|
# - ${DOCKER_FINANCE_CLIENT_TESTING}:${DOCKER_FINANCE_CONTAINER_TESTING}
|
||||||
|
# environment:
|
||||||
|
# - DOCKER_FINANCE_CONTAINER_TESTING=${DOCKER_FINANCE_CONTAINER_TESTING}
|
||||||
|
|
||||||
|
# vim: sw=2 sts=2 si ai et
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# docker-finance | modern accounting for the power-user
|
||||||
|
#
|
||||||
|
# Copyright (C) 2021-2024,2026 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/>.
|
||||||
|
|
||||||
|
# docker-finance @DOCKER_FINANCE_VERSION@
|
||||||
|
|
||||||
|
## This is a custom compose file that will be *merged* with the base compose file
|
||||||
|
## See https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/ for details
|
||||||
|
|
||||||
|
## An example of adding a custom volume and environment variables
|
||||||
|
## NOTE: *MUST* also add these variables to the env file (`edit type=env`)
|
||||||
|
#services:
|
||||||
|
# docker-finance:
|
||||||
|
# volumes:
|
||||||
|
# - ${DOCKER_FINANCE_CLIENT_TESTING}:${DOCKER_FINANCE_CONTAINER_TESTING}
|
||||||
|
# environment:
|
||||||
|
# - DOCKER_FINANCE_CONTAINER_TESTING=${DOCKER_FINANCE_CONTAINER_TESTING}
|
||||||
|
|
||||||
|
# vim: sw=2 sts=2 si ai et
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# docker-finance | modern accounting for the power-user
|
||||||
|
#
|
||||||
|
# Copyright (C) 2021-2024,2026 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/>.
|
||||||
|
|
||||||
|
# docker-finance @DOCKER_FINANCE_VERSION@
|
||||||
|
|
||||||
|
## This is a custom compose file that will be *merged* with the base compose file
|
||||||
|
## See https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/ for details
|
||||||
|
|
||||||
|
## An example of adding a custom volume and environment variables
|
||||||
|
## NOTE: *MUST* also add these variables to the env file (`edit type=env`)
|
||||||
|
#services:
|
||||||
|
# docker-finance:
|
||||||
|
# volumes:
|
||||||
|
# - ${DOCKER_FINANCE_CLIENT_TESTING}:${DOCKER_FINANCE_CONTAINER_TESTING}
|
||||||
|
# environment:
|
||||||
|
# - DOCKER_FINANCE_CONTAINER_TESTING=${DOCKER_FINANCE_CONTAINER_TESTING}
|
||||||
|
|
||||||
|
# vim: sw=2 sts=2 si ai et
|
||||||
@@ -66,6 +66,8 @@ function lib_docker::__docker()
|
|||||||
# Generate docker-compose.yml
|
# Generate docker-compose.yml
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# NOTE: custom compose file merging happens at runtime
|
||||||
|
|
||||||
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}'"
|
||||||
|
|
||||||
@@ -83,12 +85,16 @@ function lib_docker::__docker_compose()
|
|||||||
{
|
{
|
||||||
[ -z "$global_env_file" ] && lib_utils::die_fatal
|
[ -z "$global_env_file" ] && lib_utils::die_fatal
|
||||||
[ -z "$global_repo_dockerfiles" ] && lib_utils::die_fatal
|
[ -z "$global_repo_dockerfiles" ] && lib_utils::die_fatal
|
||||||
|
[ -z "$global_custom_composefile" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
[ ! -f "$global_env_file" ] \
|
[ ! -f "$global_env_file" ] \
|
||||||
&& lib_utils::die_fatal "$global_env_file not found! Run the gen command!"
|
&& lib_utils::die_fatal "$global_env_file not found! Run the \`gen\` command!"
|
||||||
|
|
||||||
|
[ ! -f "$global_custom_composefile" ] \
|
||||||
|
&& lib_utils::die_fatal "$global_custom_composefile not found! Run \`gen type${global_arg_delim_2}compose\`"
|
||||||
|
|
||||||
pushd "$global_repo_dockerfiles" 1>/dev/null || return $?
|
pushd "$global_repo_dockerfiles" 1>/dev/null || return $?
|
||||||
docker compose -f docker-compose.yml --env-file "$global_env_file" "$@" || return $?
|
docker compose -f docker-compose.yml -f "$global_custom_composefile" --env-file "$global_env_file" "$@" || return $?
|
||||||
popd 1>/dev/null || return $?
|
popd 1>/dev/null || return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,7 +552,7 @@ function lib_docker::__parse_args_edit()
|
|||||||
|
|
||||||
Configuration type:
|
Configuration type:
|
||||||
|
|
||||||
type${global_arg_delim_2}<env|{shell|superscript}|{build|dockerfile}>
|
type${global_arg_delim_2}<env | {shell | superscript} | {build | dockerfile} | compose>
|
||||||
|
|
||||||
\e[32mExamples:\e[0m
|
\e[32mExamples:\e[0m
|
||||||
|
|
||||||
@@ -556,11 +562,11 @@ function lib_docker::__parse_args_edit()
|
|||||||
\e[37;2m# Edit client/container shell (superscript) \e[0m
|
\e[37;2m# Edit client/container shell (superscript) \e[0m
|
||||||
$ $global_usage type${global_arg_delim_2}shell
|
$ $global_usage type${global_arg_delim_2}shell
|
||||||
|
|
||||||
\e[37;2m# Edit client's custom Dockerfile (appended to final Dockerfile) \e[0m
|
\e[37;2m# Edit client's custom Dockerfile (appended to final Dockerfile) and custom docker-compose.yml \e[0m
|
||||||
$ $global_usage type${global_arg_delim_2}build
|
$ $global_usage type${global_arg_delim_2}build${global_arg_delim_3}compose
|
||||||
|
|
||||||
\e[37;2m# Previous commands with alternate wordings\e[0m
|
\e[37;2m# Previous commands with alternate wordings\e[0m
|
||||||
$ $global_usage type${global_arg_delim_2}superscript${global_arg_delim_3}dockerfile${global_arg_delim_3}env
|
$ $global_usage type${global_arg_delim_2}superscript${global_arg_delim_3}dockerfile${global_arg_delim_3}env${global_arg_delim_3}compose
|
||||||
"
|
"
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
@@ -593,7 +599,7 @@ function lib_docker::__parse_args_edit()
|
|||||||
read -ra _read <<<"$_arg_type"
|
read -ra _read <<<"$_arg_type"
|
||||||
|
|
||||||
for _type in "${_read[@]}"; do
|
for _type in "${_read[@]}"; do
|
||||||
if [[ ! "$_type" =~ ^env$|^shell$|^superscript$|^build$|^dockerfile$ ]]; then
|
if [[ ! "$_type" =~ ^env$|^shell$|^superscript$|^build$|^dockerfile$|^compose$ ]]; then
|
||||||
lib_utils::die_usage "$_usage"
|
lib_utils::die_usage "$_usage"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -638,6 +644,11 @@ function lib_docker::__edit()
|
|||||||
|
|
||||||
_paths+=("$global_custom_dockerfile")
|
_paths+=("$global_custom_dockerfile")
|
||||||
;;
|
;;
|
||||||
|
compose)
|
||||||
|
[ -z "$global_custom_composefile" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
|
_paths+=("$global_custom_composefile")
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -208,6 +208,12 @@ function lib_env::__set_client_globals()
|
|||||||
&& lib_utils::die_fatal "Missing default custom Dockerfile '${global_repo_custom_dockerfile}'"
|
&& lib_utils::die_fatal "Missing default custom Dockerfile '${global_repo_custom_dockerfile}'"
|
||||||
lib_utils::print_debug "global_repo_custom_dockerfile=${global_repo_custom_dockerfile}"
|
lib_utils::print_debug "global_repo_custom_dockerfile=${global_repo_custom_dockerfile}"
|
||||||
|
|
||||||
|
# Base custom end-user .in docker-compose.yml
|
||||||
|
declare -g global_repo_custom_composefile="${global_repo_conf_dir}/client/Dockerfiles/${global_platform_image}/docker-compose.yml.${global_platform}.in"
|
||||||
|
[ ! -f "$global_repo_custom_composefile" ] \
|
||||||
|
&& lib_utils::die_fatal "Missing default custom docker-compose.yml '${global_repo_custom_composefile}'"
|
||||||
|
lib_utils::print_debug "global_repo_custom_composefile=${global_repo_custom_composefile}"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Client-side env
|
# Client-side env
|
||||||
#
|
#
|
||||||
@@ -226,12 +232,18 @@ function lib_env::__set_client_globals()
|
|||||||
global_env_file="${_client_env_dir}/${global_conf_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}"
|
||||||
|
|
||||||
# Custom Dockerfile (if available)
|
# Custom docker files (docker related) location
|
||||||
local _client_dockerfile_dir="${DOCKER_FINANCE_CLIENT_CONF}/${global_tag_dir}/Dockerfiles"
|
local _client_dockerfile_dir="${DOCKER_FINANCE_CLIENT_CONF}/${global_tag_dir}/Dockerfiles"
|
||||||
[ ! -d "$_client_dockerfile_dir" ] && mkdir -p "$_client_dockerfile_dir"
|
[ ! -d "$_client_dockerfile_dir" ] && mkdir -p "$_client_dockerfile_dir"
|
||||||
|
|
||||||
|
# Custom Dockerfile
|
||||||
global_custom_dockerfile="${_client_dockerfile_dir}/${global_conf_filename}"
|
global_custom_dockerfile="${_client_dockerfile_dir}/${global_conf_filename}"
|
||||||
lib_utils::print_debug "global_custom_dockerfile=${global_custom_dockerfile}"
|
lib_utils::print_debug "global_custom_dockerfile=${global_custom_dockerfile}"
|
||||||
|
|
||||||
|
# Custom docker-compose.yml
|
||||||
|
global_custom_composefile="${_client_dockerfile_dir}/${global_conf_filename}.yml"
|
||||||
|
lib_utils::print_debug "global_custom_composefile=${global_custom_composefile}"
|
||||||
|
|
||||||
# NOTE:
|
# NOTE:
|
||||||
#
|
#
|
||||||
# Client env tag format is avoided because:
|
# Client env tag format is avoided because:
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function lib_gen::__parse_args()
|
|||||||
|
|
||||||
Category type:
|
Category type:
|
||||||
|
|
||||||
type${global_arg_delim_2}<env | build | flow | superscript>
|
type${global_arg_delim_2}<env | build | compose | flow | superscript>
|
||||||
|
|
||||||
Flow (only):
|
Flow (only):
|
||||||
|
|
||||||
@@ -111,11 +111,11 @@ function lib_gen::__parse_args()
|
|||||||
\e[37;2m# Generate only the Docker environment\e[0m
|
\e[37;2m# Generate only the Docker environment\e[0m
|
||||||
$ $global_usage type${global_arg_delim_2}env
|
$ $global_usage type${global_arg_delim_2}env
|
||||||
|
|
||||||
\e[37;2m# Generate custom Dockerfile and joint client/container superscript\e[0m
|
\e[37;2m# Generate custom Dockerfile, docker-compose.yml and joint client/container superscript\e[0m
|
||||||
$ $global_usage type${global_arg_delim_2}build${global_arg_delim_3}superscript
|
$ $global_usage type${global_arg_delim_2}build${global_arg_delim_3}compose${global_arg_delim_3}superscript
|
||||||
|
|
||||||
\e[37;2m# Generate all client related data\e[0m
|
\e[37;2m# Generate all client related data\e[0m
|
||||||
$ $global_usage type${global_arg_delim_2}env${global_arg_delim_3}build${global_arg_delim_3}superscript
|
$ $global_usage type${global_arg_delim_2}env${global_arg_delim_3}build${global_arg_delim_3}compose${global_arg_delim_3}superscript
|
||||||
|
|
||||||
\e[37;2m#\e[0m
|
\e[37;2m#\e[0m
|
||||||
\e[37;2m# Flow: Profile -> Configs / Accounts\e[0m
|
\e[37;2m# Flow: Profile -> Configs / Accounts\e[0m
|
||||||
@@ -279,7 +279,7 @@ function lib_gen::__parse_args()
|
|||||||
if [ ! -z "$_arg_type" ]; then
|
if [ ! -z "$_arg_type" ]; then
|
||||||
read -ra _read <<<"$_arg_type"
|
read -ra _read <<<"$_arg_type"
|
||||||
for _arg in "${_read[@]}"; do
|
for _arg in "${_read[@]}"; do
|
||||||
if [[ ! "$_arg" =~ ^env$|^build$|^flow$|^superscript$ ]]; then
|
if [[ ! "$_arg" =~ ^env$|^build$|^compose$|^flow$|^superscript$ ]]; then
|
||||||
lib_utils::die_usage "$_usage"
|
lib_utils::die_usage "$_usage"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -440,6 +440,9 @@ function lib_gen::__gen_client()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Filter to de-clutter output file (license cleanup)
|
||||||
|
local -r _filter="1,17d"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Custom (optional) Dockerfile
|
# Custom (optional) Dockerfile
|
||||||
#
|
#
|
||||||
@@ -467,9 +470,6 @@ function lib_gen::__gen_client()
|
|||||||
lib_utils::print_debug "$global_custom_dockerfile"
|
lib_utils::print_debug "$global_custom_dockerfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Filter to de-clutter output file (license cleanup)
|
|
||||||
local -r _filter="1,17d"
|
|
||||||
|
|
||||||
sed \
|
sed \
|
||||||
-e "$_filter" \
|
-e "$_filter" \
|
||||||
-e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
|
-e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
|
||||||
@@ -479,6 +479,42 @@ function lib_gen::__gen_client()
|
|||||||
lib_gen::__gen_edit "$global_custom_dockerfile"
|
lib_gen::__gen_edit "$global_custom_dockerfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Custom (optional) docker-compose.yml
|
||||||
|
#
|
||||||
|
|
||||||
|
if [[ -z "${global_arg_type[*]}" || "${global_arg_type[*]}" =~ compose ]]; then
|
||||||
|
|
||||||
|
[ -z "$global_custom_composefile" ] && lib_utils::die_fatal
|
||||||
|
[ -z "$global_repo_custom_composefile" ] && lib_utils::die_fatal
|
||||||
|
|
||||||
|
# Backup existing custom compose file
|
||||||
|
if [ -f "$global_custom_composefile" ]; then
|
||||||
|
lib_utils::print_custom " \e[32m│\e[0m\n"
|
||||||
|
lib_utils::print_custom " \e[32m├─\e[34;1m Custom docker-compose.yml found, backup then generate new one? [Y/n] \e[0m"
|
||||||
|
|
||||||
|
[ -z "$global_arg_confirm" ] && lib_utils::print_custom "\n" || read -p "" _read
|
||||||
|
local _confirm="${_read:-y}"
|
||||||
|
if [[ "$_confirm" == [yY] || -z "$global_arg_confirm" ]]; then
|
||||||
|
cp -a "$global_custom_composefile" "${global_custom_composefile}_${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 docker-compose.yml\e[0m\n"
|
||||||
|
|
||||||
|
lib_utils::print_debug "$global_repo_custom_composefile"
|
||||||
|
lib_utils::print_debug "$global_custom_composefile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed \
|
||||||
|
-e "$_filter" \
|
||||||
|
-e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
|
||||||
|
"$global_repo_custom_composefile" >"$global_custom_composefile" || lib_utils::die_fatal
|
||||||
|
|
||||||
|
lib_utils::print_custom " \e[32m│ └─\e[34m Edit file now? [Y/n] \e[0m"
|
||||||
|
lib_gen::__gen_edit "$global_custom_composefile"
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate client-side `plugins` layout (custom)
|
# Generate client-side `plugins` layout (custom)
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user