From 85a9cd801877ac16b197ec7b00209b3750af5169 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 11 Jul 2024 18:23:03 -0700 Subject: [PATCH 1/3] client: lib_docker: add 'type' arg to `version` - Add `version` types (client | container | short | all) - Related refactoring --- .../src/docker/lib/internal/lib_docker.bash | 221 ++++++++++++------ 1 file changed, 151 insertions(+), 70 deletions(-) diff --git a/client/src/docker/lib/internal/lib_docker.bash b/client/src/docker/lib/internal/lib_docker.bash index 4c962c2..a868b75 100644 --- a/client/src/docker/lib/internal/lib_docker.bash +++ b/client/src/docker/lib/internal/lib_docker.bash @@ -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} + +\e[32mArguments:\e[0m + + Version type: + + type${global_arg_delim_2} + +\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 - # + [ -z "${global_arg_type[*]}" ] && lib_utils::die_fatal - 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 + for _type in "${global_arg_type[@]}"; do - echo - echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash" - echo -e "───────────────────────────────────────" + case "$_type" in - # - # Client dependencies - # + client) + echo + echo "client.system:" - echo - echo "client.system:" + echo -e \\t"$(uname -rmo)" + echo -e \\t"$(bash --version | head -n1)" + echo -e \\t"$(sed --version | head -n1)" - echo -e \\t"$(uname -rmo)" - echo -e \\t"$(bash --version | head -n1)" - echo -e \\t"$(sed --version | head -n1)" + echo + echo "client.docker:" - echo - echo "client.docker:" + echo -e \\t"$(docker compose version)" + docker version \ + | while read _line; do + echo -e \\t"${_line}" + done + ;; - echo -e \\t"$(docker compose version)" - docker version \ - | while read _line; do - echo -e \\t"${_line}" - done + container) + [ -z "$global_platform" ] && lib_utils::die_fatal - # - # Container dependencies - # + # Feed dependency manifest (client is not bind-mounted for security reasons) + local _manifest + _manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)" - [ -z "$global_platform" ] && lib_utils::die_fatal + # 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 - # Feed dependency manifest (client is not bind-mounted for security reasons) - local _manifest - _manifest="$(<${DOCKER_FINANCE_CLIENT_REPO}/client/docker-finance.yaml)" + 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" + ;; - 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 + 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 - 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" + echo + echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash" + ;; - return $? + *) + lib_utils::die_fatal "unsupported type" + ;; + esac + done } # vim: sw=2 sts=2 si ai et From b00f4640df97728cbf446539ad570575084bbe6d Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 11 Jul 2024 19:11:35 -0700 Subject: [PATCH 2/3] client: lib_docker: add build platform to `version type=short` --- client/src/docker/lib/internal/lib_docker.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/docker/lib/internal/lib_docker.bash b/client/src/docker/lib/internal/lib_docker.bash index a868b75..6ec1559 100644 --- a/client/src/docker/lib/internal/lib_docker.bash +++ b/client/src/docker/lib/internal/lib_docker.bash @@ -646,6 +646,7 @@ function lib_docker::__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_arg_type[*]}" ] && lib_utils::die_fatal for _type in "${global_arg_type[@]}"; do @@ -671,8 +672,6 @@ function lib_docker::__version() ;; container) - [ -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)" @@ -723,8 +722,9 @@ function lib_docker::__version() lib_utils::die_fatal fi + # TODO: add build type echo - echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash" + echo -e "docker-finance v${DOCKER_FINANCE_VERSION} | commit: $_hash | build: $global_platform" ;; *) From f53bd6080bb0237ac39471b669bc30b58f770de9 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 11 Jul 2024 22:44:31 -0700 Subject: [PATCH 3/3] repo: gitea: template: update `version` command --- .gitea/ISSUE_TEMPLATE/bug.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/ISSUE_TEMPLATE/bug.yaml b/.gitea/ISSUE_TEMPLATE/bug.yaml index fcdbb29..e4ffc08 100644 --- a/.gitea/ISSUE_TEMPLATE/bug.yaml +++ b/.gitea/ISSUE_TEMPLATE/bug.yaml @@ -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