Merge pull request #83 into master

f53bd60 repo: gitea: template: update `version` command (Aaron Fiore)
b00f464 client: lib_docker: add build platform to `version type=short` (Aaron Fiore)
85a9cd8 client: lib_docker: add 'type' arg to `version` (Aaron Fiore)
This commit is contained in:
2024-07-12 21:23:22 -07:00
2 changed files with 161 additions and 80 deletions

View File

@@ -29,8 +29,8 @@ body:
- type: textarea
id: version_output
attributes:
label: "Output of your client (host) `docker-finance version` command"
placeholder: "$ docker-finance version"
label: "Output of client (host) `version` command"
placeholder: "$ docker-finance version type=all"
render: shell
validations:
required: true

View File

@@ -563,94 +563,175 @@ function lib_docker::__edit()
$EDITOR "${_paths[@]}"
}
function lib_docker::__parse_args_version()
{
[ -z "$global_usage" ] && lib_utils::die_fatal
[ -z "$global_arg_delim_1" ] && lib_utils::die_fatal
[ -z "$global_arg_delim_2" ] && lib_utils::die_fatal
[ -z "$global_arg_delim_3" ] && lib_utils::die_fatal
local -r _usage="
\e[32mDescription:\e[0m
Print version information
\e[32mUsage:\e[0m
$ $global_usage type${global_arg_delim_2}<type>
\e[32mArguments:\e[0m
Version type:
type${global_arg_delim_2}<client|container|short|all>
\e[32mExamples:\e[0m
\e[37;2m# Print docker-finance client dependency versions\e[0m
$ $global_usage type${global_arg_delim_2}client
\e[37;2m# Print docker-finance container dependency versions\e[0m
$ $global_usage type${global_arg_delim_2}container
\e[37;2m# Print only docker-finance version\e[0m
$ $global_usage type${global_arg_delim_2}short
\e[37;2m# Print both docker-finance and client dependency versions\e[0m
$ $global_usage type${global_arg_delim_2}client${global_arg_delim_3}short
\e[37;2m# Print docker-finance version and all client/container dependency versions\e[0m
$ $global_usage type${global_arg_delim_2}all
"
[ $# -eq 0 ] && lib_utils::die_usage "$_usage"
for _arg in "$@"; do
[[ ! "$_arg" =~ ^type[s]?${global_arg_delim_2} ]] \
&& lib_utils::die_usage "$_usage"
done
# Parse key for value
for _arg in "$@"; do
local _key="${_arg%${global_arg_delim_2}*}"
local _len="$((${#_key} + 1))"
if [[ "$_key" =~ ^type[s]?$ ]]; then
local _arg_type="${_arg:${_len}}"
[ -z "$_arg_type" ] && lib_utils::die_usage "$_usage"
fi
done
IFS="$global_arg_delim_3"
# Arg: type
read -ra _read <<<"$_arg_type"
for _arg in "${_read[@]}"; do
if [[ ! "$_arg" =~ ^client$|^container$|^short$|^all$ ]]; then
lib_utils::die_usage "$_usage"
fi
done
if [[ "${_read[*]}" =~ all ]]; then # Note: not anchored
declare -gr global_arg_type=("client" "container" "short")
else
declare -gr global_arg_type=("${_read[@]}")
fi
}
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
#
# `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
[ -z "${global_arg_type[*]}" ] && 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)"
for _type in "${global_arg_type[@]}"; do
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
case "$_type" in
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"
client)
echo
echo "client.system:"
return $?
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)
# Feed dependency manifest (client is not bind-mounted for security reasons)
local _manifest
_manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)"
# NOTE: uses variable "callback"
case "$global_platform" in
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"
;;
short)
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
# TODO: add build type
echo
echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash | build: $global_platform"
;;
*)
lib_utils::die_fatal "unsupported type"
;;
esac
done
}
# vim: sw=2 sts=2 si ai et