From dddd8a90a286da34c200d4843be71820c959ffaf Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 19 Jun 2024 16:16:39 -0700 Subject: [PATCH 1/2] client: lib_docker: add CLI `version` for all platforms Prints meaningful output of all dependencies and their respective versions. --- client/docker-finance.yaml | 137 ++++++++++++++++++ client/src/docker/docker.bash | 11 ++ .../src/docker/lib/internal/lib_docker.bash | 90 ++++++++++++ client/src/docker/lib/lib_docker.bash | 10 ++ 4 files changed, 248 insertions(+) create mode 100644 client/docker-finance.yaml diff --git a/client/docker-finance.yaml b/client/docker-finance.yaml new file mode 100644 index 0000000..ee929f5 --- /dev/null +++ b/client/docker-finance.yaml @@ -0,0 +1,137 @@ +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 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 . + +# +# docker-finance client/container manifest +# + +# `docker-finance` release version +# TODO: internal refactor to pull from here +version: "1.0.0" + +# Container dependencies (used by `version` command) +# NOTE: this must stay inline with Dockerfiles +container: + archlinux: + finance: + system: + packages: + - "coreutils" + - "bash" + - "gawk" + - "sed" + commands: + base: + packages: + - "bc" + - "composer" + - "ghc" + - "git" + - "hledger-iadd" + - "hledger-ui" + - "hledger-web" + - "hledger" + - "python-pipx" + - "stack" + - "vim" + - "visidata" + - "xsv" + commands: + - "csvstat --version" + - "hledger-flow --version" + - "shyaml --version" + fetch: + packages: + commands: + - "php --version | head -n1" + - "cat /usr/local/lib/php/composer.json" + root: + packages: + - "benchmark" + - "botan2" + - "crypto++" + - "gtest" + - "libsodium" + - "root" + commands: + ubuntu: + finance: + system: + packages: + - "coreutils" + - "bash" + - "gawk" + - "sed" + commands: + base: + packages: + - "bc" + - "cargo" + - "composer" + - "ghc" + - "git" + - "haskell-stack" + - "hledger-ui" + - "hledger-web" + - "hledger" + - "pipx" + - "vim" + - "visidata" + - "zlib1g-dev" + commands: + - "xsv --version" + - "csvstat --version" + - "hledger-flow --version" + - "shyaml --version" + fetch: + packages: + commands: + - "php --version | head -n1" + - "cat /usr/local/lib/php/composer.json" + dev-tools: + system: + packages: + - "coreutils" + - "bash" + commands: + linters: + packages: + # Bash + - "bash" + - "shfmt" + - "shellcheck" + # C++ + - "clang-format" + - "cppcheck" + - "cpplint" + # PHP + - "composer" + commands: + - "php-cs-fixer --version --no-ansi" + - "phpstan --version --no-ansi" + fetch: + packages: + commands: + - "php --version | head -n1" + - "cat /usr/local/lib/php/composer.json" + misc: + packages: + - "doxygen" + - "graphviz" + commands: + +# vim: sw=2 sts=2 si ai et diff --git a/client/src/docker/docker.bash b/client/src/docker/docker.bash index 7b0abad..aa32242 100755 --- a/client/src/docker/docker.bash +++ b/client/src/docker/docker.bash @@ -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" ;; diff --git a/client/src/docker/lib/internal/lib_docker.bash b/client/src/docker/lib/internal/lib_docker.bash index e5ed157..2bdee08 100644 --- a/client/src/docker/lib/internal/lib_docker.bash +++ b/client/src/docker/lib/internal/lib_docker.bash @@ -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 diff --git a/client/src/docker/lib/lib_docker.bash b/client/src/docker/lib/lib_docker.bash index b9ed20e..08dfc1a 100644 --- a/client/src/docker/lib/lib_docker.bash +++ b/client/src/docker/lib/lib_docker.bash @@ -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 From 51ef36b2bb444ee311b6d9a596fcb5cad8f603fc Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Fri, 21 Jun 2024 06:38:18 -0700 Subject: [PATCH 2/2] client: Dockerfiles: dev-tools: add `version` dependency Already present in the 'finance' images. --- .../Dockerfiles/dev-tools/Dockerfile.dev-tools.in | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/Dockerfiles/dev-tools/Dockerfile.dev-tools.in b/client/Dockerfiles/dev-tools/Dockerfile.dev-tools.in index 55885e1..e61405f 100644 --- a/client/Dockerfiles/dev-tools/Dockerfile.dev-tools.in +++ b/client/Dockerfiles/dev-tools/Dockerfile.dev-tools.in @@ -82,6 +82,20 @@ RUN chown -R :wheel /usr/local/lib/php && chmod g+rwx /usr/local/lib/php # Doxygen RUN apt install -y doxygen graphviz +# +# Client-side `version` command +# + +RUN apt install -y pipx + +USER @DOCKER_FINANCE_USER@ +WORKDIR /home/@DOCKER_FINANCE_USER@ + +RUN pipx install shyaml +RUN echo "export PATH=\"\$PATH:\${HOME}/.local/bin\"" | tee -a ~/.bash_aliases + +USER root + # # Entrypoint #