client: lib_docker: add CLI version for all platforms

Prints meaningful output of all dependencies and their respective versions.
This commit is contained in:
2024-06-19 16:16:39 -07:00
parent 00d4a8fa77
commit dddd8a90a2
4 changed files with 248 additions and 0 deletions

View File

@@ -71,6 +71,8 @@ function main()
run \e[34;3mSpawn a container with given command (container removed on exit)\e[0m
shell \e[34;3mOpen shell into running container\e[0m
version \e[34;3mPrint current version of 'docker-finance' and its dependencies\e[0m
Dev-tools platform:
license \e[34;3mAdd a license to a docker-finance file\e[0m
@@ -112,6 +114,9 @@ function main()
\e[37;2m# Backup image, delete old image, build new image\e[0m
$ docker-finance backup && docker-finance rm && docker-finance build
\e[37;2m# Print current version of 'docker-finance' and client/container ('finance') dependencies\e[0m
$ docker-finance version
\e[37;2m#\e[0m
\e[37;2m# Dev-tools platform\e[0m
\e[37;2m#\e[0m
@@ -130,6 +135,9 @@ function main()
\e[37;2m# Generate Doxygen for docker-finance source\e[0m
$ docker-finance_dev-tools doxygen gen
\e[37;2m# Print current version of 'docker-finance' and client/container ('dev-tools') dependencies\e[0m
$ docker-finance_dev-tools version
"
#
@@ -186,6 +194,9 @@ function main()
doxygen)
lib_docker::doxygen "${@:3}"
;;
version)
lib_docker::version "${@:3}"
;;
*)
lib_utils::die_usage "$_usage"
;;

View File

@@ -320,4 +320,94 @@ function lib_docker::__edit()
$EDITOR "${_paths[@]}"
}
function lib_docker::__version()
{
[ -z "${DOCKER_FINANCE_VERSION}" ] && lib_utils::die_fatal
[ -z "${DOCKER_FINANCE_CLIENT_REPO}" ] && lib_utils::die_fatal
#
# `docker-finance` version
#
local _hash
if pushd "$DOCKER_FINANCE_CLIENT_REPO" 1>/dev/null; then
_hash="$(git log --pretty='format:%h' -n 1)"
popd 1>/dev/null || lib_utils::die_fatal
else
lib_utils::die_fatal
fi
echo
echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash"
echo -e "───────────────────────────────────────"
#
# Client dependencies
#
echo
echo "client.system:"
echo -e \\t"$(uname -rmo)"
echo -e \\t"$(bash --version | head -n1)"
echo -e \\t"$(sed --version | head -n1)"
echo
echo "client.docker:"
echo -e \\t"$(docker compose version)"
docker version \
| while read _line; do
echo -e \\t"${_line}"
done
#
# Container dependencies
#
[ -z "$global_platform" ] && lib_utils::die_fatal
# Feed dependency manifest (client is not bind-mounted for security reasons)
local _manifest
_manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)"
case "$global_platform" in
# NOTE: uses variable "callback"
archlinux)
_platform="$global_platform"
_image="finance"
_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
_pkg="dpkg -s \$_package | grep -E \"(^Package:|^Version:)\" | cut -d' ' -f2 | paste -s | awk '{print \$1 \" \" \$2}'"
;;
*)
lib_utils::die_fatal "unsupported platform"
;;
esac
lib_docker::__run "
echo '${_manifest}' \\
| shyaml keys container.${_platform}.${_image} \\
| while read _key; do
echo -e \\\ncontainer.${_platform}.${_image}.\${_key}:
echo '${_manifest}' | shyaml get-values container.${_platform}.${_image}.\${_key}.packages 2>/dev/null \\
| while read _package; do
echo -e \\\t\$($_pkg)
done
echo '${_manifest}' | shyaml get-values container.${_platform}.${_image}.\${_key}.commands 2>/dev/null \\
| while read _command; do
echo -e \\\t\$(\$_command)
done
done
echo"
return $?
}
# vim: sw=2 sts=2 si ai et

View File

@@ -309,4 +309,14 @@ function lib_docker::doxygen()
lib_utils::catch $?
}
#
# Prints `docker-finance` version (and dependencies' version)
#
function lib_docker::version()
{
lib_docker::__version "$@"
lib_utils::catch $?
}
# vim: sw=2 sts=2 si ai et