diff --git a/client/Dockerfiles/dev-tools/docker-compose.yml.dev-tools.in b/client/Dockerfiles/dev-tools/docker-compose.yml.dev-tools.in
index 74ef847..7199bfd 100644
--- a/client/Dockerfiles/dev-tools/docker-compose.yml.dev-tools.in
+++ b/client/Dockerfiles/dev-tools/docker-compose.yml.dev-tools.in
@@ -32,8 +32,8 @@ services:
- ${DOCKER_FINANCE_CLIENT_REPO}/container:${DOCKER_FINANCE_CLIENT_REPO}/container
- /etc/localtime:/etc/localtime:ro
environment:
+ - DOCKER_FINANCE_VERSION=@DOCKER_FINANCE_VERSION@
- DOCKER_FINANCE_CLIENT_REPO=${DOCKER_FINANCE_CLIENT_REPO}
- - DOCKER_FINANCE_VERSION=${DOCKER_FINANCE_VERSION}
- GID=${DOCKER_FINANCE_GID}
- UID=${DOCKER_FINANCE_UID}
deploy:
diff --git a/client/Dockerfiles/finance/docker-compose.yml.archlinux.in b/client/Dockerfiles/finance/docker-compose.yml.archlinux.in
index ef70c86..7049de7 100644
--- a/client/Dockerfiles/finance/docker-compose.yml.archlinux.in
+++ b/client/Dockerfiles/finance/docker-compose.yml.archlinux.in
@@ -33,6 +33,7 @@ services:
# NOTE: although TZ can be used within the container, this *should* be more dynamic
- /etc/localtime:/etc/localtime:ro
environment:
+ - DOCKER_FINANCE_VERSION=@DOCKER_FINANCE_VERSION@
- DOCKER_FINANCE_CONTAINER_CMD=${DOCKER_FINANCE_CONTAINER_CMD}
- DOCKER_FINANCE_CONTAINER_CONF=${DOCKER_FINANCE_CONTAINER_CONF}
- DOCKER_FINANCE_CONTAINER_EDITOR=${DOCKER_FINANCE_CONTAINER_EDITOR}
diff --git a/client/Dockerfiles/finance/docker-compose.yml.ubuntu.in b/client/Dockerfiles/finance/docker-compose.yml.ubuntu.in
index 572ffea..0c41df8 100644
--- a/client/Dockerfiles/finance/docker-compose.yml.ubuntu.in
+++ b/client/Dockerfiles/finance/docker-compose.yml.ubuntu.in
@@ -33,6 +33,7 @@ services:
# NOTE: although TZ can be used within the container, this should be more dynamic
- /etc/localtime:/etc/localtime:ro
environment:
+ - DOCKER_FINANCE_VERSION=@DOCKER_FINANCE_VERSION@
- DOCKER_FINANCE_CONTAINER_CMD=${DOCKER_FINANCE_CONTAINER_CMD}
- DOCKER_FINANCE_CONTAINER_CONF=${DOCKER_FINANCE_CONTAINER_CONF}
- DOCKER_FINANCE_CONTAINER_EDITOR=${DOCKER_FINANCE_CONTAINER_EDITOR}
diff --git a/client/docker-finance.d/client/env/gen.bash b/client/docker-finance.d/client/env/gen.bash
index 7c7abfc..a54f16d 100644
--- a/client/docker-finance.d/client/env/gen.bash
+++ b/client/docker-finance.d/client/env/gen.bash
@@ -24,16 +24,17 @@
# Different platforms require slightly different environment
[ -z "$global_platform" ] && exit 1
+# Version is internally set on-the-fly
+[ -z "$global_client_version" ] && exit 1
+
+export DOCKER_FINANCE_VERSION="$global_client_version"
+
# Developer related
if [ -z "$DOCKER_FINANCE_DEBUG" ]; then
export DOCKER_FINANCE_DEBUG=false
fi
-if [ -z "$DOCKER_FINANCE_VERSION" ]; then
- export DOCKER_FINANCE_VERSION="1.0.0"
-fi
-
# Allows transparent r/w of mounted volumes
if [ -z "$DOCKER_FINANCE_UID" ]; then
diff --git a/client/docker-finance.d/container/fetch/fetch.yaml.in b/client/docker-finance.d/container/fetch/fetch.yaml.in
index 69562d3..1844361 100644
--- a/client/docker-finance.d/container/fetch/fetch.yaml.in
+++ b/client/docker-finance.d/container/fetch/fetch.yaml.in
@@ -15,7 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-# docker-finance @DOCKER_FINANCE_VERSION@
+#
+# Configuration for `fetch` command
+#
# Documentation:
#
diff --git a/client/docker-finance.yaml b/client/docker-finance.yaml
index 051f22d..411e2de 100644
--- a/client/docker-finance.yaml
+++ b/client/docker-finance.yaml
@@ -16,12 +16,11 @@
# along with this program. If not, see .
#
-# docker-finance client/container manifest
+# `docker-finance` manifest
#
-# `docker-finance` release version
-# TODO: internal refactor to pull from here
-version: "1.0.0"
+# Release version (tag format)
+version: "v1.0.0-beta"
# Container dependencies (used by `version` command)
# NOTE: this must stay inline with Dockerfiles
diff --git a/client/src/docker/lib/internal/lib_docker.bash b/client/src/docker/lib/internal/lib_docker.bash
index 6ec1559..e852fa0 100644
--- a/client/src/docker/lib/internal/lib_docker.bash
+++ b/client/src/docker/lib/internal/lib_docker.bash
@@ -49,34 +49,26 @@ fi
# Remaining "constructor" implementation
function lib_docker::__docker()
{
- # 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}'"
sed \
+ -e "s|@DOCKER_FINANCE_VERSION@|${global_client_version}|g" \
-e "s|@DOCKER_FINANCE_IMAGE@|${global_image}:${global_tag}|g" \
-e "s|@DOCKER_FINANCE_CONTAINER@|${global_container}|g" \
-e "s|@DOCKER_FINANCE_NETWORK@|${global_network}|g" \
@@ -643,10 +635,9 @@ function lib_docker::__version()
{
lib_docker::__parse_args_version "$@"
- [ -z "${DOCKER_FINANCE_VERSION}" ] && lib_utils::die_fatal
- [ -z "${DOCKER_FINANCE_CLIENT_REPO}" ] && lib_utils::die_fatal
-
[ -z "$global_platform" ] && lib_utils::die_fatal
+ [ -z "$global_platform_image" ] && lib_utils::die_fatal
+
[ -z "${global_arg_type[*]}" ] && lib_utils::die_fatal
for _type in "${global_arg_type[@]}"; do
@@ -673,22 +664,20 @@ function lib_docker::__version()
container)
# Feed dependency manifest (client is not bind-mounted for security reasons)
+ [ -z "$global_repo_manifest" ] && lib_utils::die_fatal
local _manifest
- _manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)"
+ _manifest="$(<$global_repo_manifest)"
# NOTE: uses variable "callback"
case "$global_platform" in
archlinux)
_platform="$global_platform"
- _image="finance"
+ _image="$global_platform_image"
_pkg="pacman -Q \$_package"
;;
ubuntu | dev-tools)
- if [[ "$global_platform" =~ ^ubuntu$|^dev-tools$ ]]; then
- _platform="ubuntu"
- _image="finance"
- [[ "$global_platform" == "dev-tools" ]] && _image="dev-tools"
- fi
+ _platform="ubuntu" # NOTE: current dev-tools is treated as an ubuntu-based image
+ _image="$global_platform_image"
_pkg="dpkg -s \$_package | grep -E \"(^Package:|^Version:)\" | cut -d' ' -f2 | paste -s | awk '{print \$1 \" \" \$2}'"
;;
*)
@@ -714,6 +703,9 @@ function lib_docker::__version()
;;
short)
+ [ -z "$DOCKER_FINANCE_CLIENT_REPO" ] && lib_utils::die_fatal
+ [ -z "$DOCKER_FINANCE_VERSION" ] && lib_utils::die_fatal
+
local _hash
if pushd "$DOCKER_FINANCE_CLIENT_REPO" 1>/dev/null; then
_hash="$(git log --pretty='format:%h' -n 1)"
@@ -724,7 +716,7 @@ function lib_docker::__version()
# TODO: add build type
echo
- echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash | build: $global_platform"
+ echo -e "docker-finance $DOCKER_FINANCE_VERSION | commit: $_hash | platform: $global_platform | image: $global_platform_image"
;;
*)
diff --git a/client/src/docker/lib/internal/lib_gen.bash b/client/src/docker/lib/internal/lib_gen.bash
index aedb759..a09b969 100644
--- a/client/src/docker/lib/internal/lib_gen.bash
+++ b/client/src/docker/lib/internal/lib_gen.bash
@@ -53,11 +53,22 @@ 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"
+ # Generate `docker-finance` version
+ global_repo_manifest="$(dirname "$(realpath -s $0)")/docker-finance.yaml"
+ declare -gr global_repo_manifest
+
+ global_client_version="$(grep '^version: ' $global_repo_manifest | sed -e 's/version: "//' -e 's/"//g')"
+ # shellcheck disable=SC2034 # used during env gen
+ declare -gr global_client_version
+
# Repository-provided (not user-defined) default environment
global_repo_conf_dir="$(dirname "$(realpath -s $0)")/docker-finance.d"
declare -gr global_repo_conf_dir
@@ -67,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
@@ -106,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}"
@@ -124,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
@@ -193,9 +215,7 @@ function lib_gen::__set_client_globals()
function lib_gen::__read_env()
{
- lib_utils::print_debug "Get/Set environment"
-
- # Unset
+ # Reset environment
unset "$(printenv | grep -Eo "^DOCKER_FINANCE[^=]+")"
# Set, if a script that generates env
@@ -207,8 +227,16 @@ function lib_gen::__read_env()
# Set, if env file format (docker / bash)
while read _line; do
- export "${_line?}" # SC2163
- lib_utils::print_debug "$_line"
+ # Ignore comments
+ if [[ ! "$_line" =~ ^# ]]; then
+ # Don't allow manipulating version via file
+ if [[ "$_line" =~ ^DOCKER_FINANCE_VERSION ]]; then
+ continue
+ fi
+ # Export valid line
+ export "${_line?}" # SC2163
+ lib_utils::print_debug "$_line"
+ fi
done <"$1"
}
@@ -220,7 +248,8 @@ function lib_gen::__write_env()
{
lib_utils::print_debug "Writing environment"
- printenv | grep "DOCKER_FINANCE" | sort >"$1"
+ unset DOCKER_FINANCE_VERSION # Must be generated internally
+ printenv | grep -E "DOCKER_FINANCE" | sort >"$1"
}
#
@@ -303,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"
@@ -477,14 +504,14 @@ function lib_gen::__gen_shell()
function lib_gen::__gen_shell_write()
{
[ -z "$global_repo_conf_dir" ] && lib_utils::die_fatal
- [ -z "$DOCKER_FINANCE_VERSION" ] && lib_utils::die_fatal
-
lib_utils::print_debug "global_repo_conf_dir=${global_repo_conf_dir}"
- lib_utils::print_debug "DOCKER_FINANCE_VERSION=${DOCKER_FINANCE_VERSION}"
+
+ [ -z "$global_client_version" ] && lib_utils::die_fatal
+ lib_utils::print_debug "global_client_version=${global_client_version}"
sed \
-e "s:@DOCKER_FINANCE_SUBPROFILE_SOURCE@:${_source}:g" \
- -e "s:@DOCKER_FINANCE_VERSION@:${DOCKER_FINANCE_VERSION}:g" \
+ -e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
"${global_repo_conf_dir}/container/shell/superscript.bash.in" >"$_file"
}
@@ -528,10 +555,14 @@ function lib_gen::__gen_hledger_write()
local _file="$1"
[ -z "$_file" ] && lib_utils::die_fatal
- [ -z "$DOCKER_FINANCE_VERSION" ] && lib_utils::die_fatal
[ -z "$global_repo_conf_dir" ] && lib_utils::die_fatal
+ lib_utils::print_debug "global_repo_conf_dir=${global_repo_conf_dir}"
+
+ [ -z "$global_client_version" ] && lib_utils::die_fatal
+ lib_utils::print_debug "global_client_version=${global_client_version}"
+
sed \
- -e "s:@DOCKER_FINANCE_VERSION@:${DOCKER_FINANCE_VERSION}:g" \
+ -e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
"${global_repo_conf_dir}/container/hledger/hledger.conf.in" >"$_file"
}
@@ -618,7 +649,7 @@ function lib_gen::__gen_flow_shell_write()
sed \
-e "s:@DOCKER_FINANCE_CONTAINER_CMD@:${DOCKER_FINANCE_CONTAINER_CMD}:g" \
-e "s:@DOCKER_FINANCE_CONTAINER_REPO@:${DOCKER_FINANCE_CONTAINER_REPO}:g" \
- -e "s:@DOCKER_FINANCE_VERSION@:${DOCKER_FINANCE_VERSION}:g" \
+ -e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
-e "s:@DOCKER_FINANCE_PROFILE@:${_profile}:g" \
-e "s:@DOCKER_FINANCE_SUBPROFILE@:${_subprofile}:g" \
"${global_repo_conf_dir}/container/shell/subprofile.bash.in" >"$_file"
@@ -659,16 +690,16 @@ function lib_gen::__gen_flow_fetch()
function lib_gen::__gen_flow_fetch_write()
{
- [ -z "$DOCKER_FINANCE_VERSION" ] && lib_utils::die_fatal
-
[ -z "$_profile" ] && lib_utils::die_fatal
[ -z "$_subprofile" ] && lib_utils::die_fatal
[ -z "$global_repo_conf_dir" ] && lib_utils::die_fatal
[ -z "$_file" ] && lib_utils::die_fatal
+ [ -z "$global_client_version" ] && lib_utils::die_fatal
+
sed \
- -e "s:@DOCKER_FINANCE_VERSION@:${DOCKER_FINANCE_VERSION}:g" \
+ -e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
-e "s:@DOCKER_FINANCE_PROFILE@:${_profile}:g" \
-e "s:@DOCKER_FINANCE_SUBPROFILE@:${_subprofile}:g" \
"${global_repo_conf_dir}/container/fetch/fetch.yaml.in" >"$_file"
@@ -712,7 +743,7 @@ function lib_gen::__gen_flow_meta_write()
# Deletes default comments or else ROOT meta sample won't work out-of-the-box
sed \
-e "/\/\/\\!/d" \
- -e "s:@DOCKER_FINANCE_VERSION@:${DOCKER_FINANCE_VERSION}:g" \
+ -e "s:@DOCKER_FINANCE_VERSION@:${global_client_version}:g" \
"${global_repo_conf_dir}/container/meta/meta.csv.in" >"$_file"
}