From 1930cc67e0959173c48fe1415b6cf749b8a83954 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sat, 21 Nov 2026 00:02:54 +0100 Subject: [PATCH] feat: Improve profile listing by adding a desc and add a task to display profiles --- .mise/tasks/list | 34 ++++++++++++++----- .mise/tasks/show | 29 ++++++++++++++++ README.md | 3 +- docs/create-traefik-container.md | 2 +- mise.toml | 2 ++ ...ea.profile.yaml => app-gitea.profile.yaml} | 9 +++-- ....profile.yaml => app-mariadb.profile.yaml} | 2 +- ...rofile.yaml => app-nextcloud.profile.yaml} | 7 ++-- ...d.profile.yaml => app-ollama.profile.yaml} | 2 +- ...rofile.yaml => app-streamrip.profile.yaml} | 2 +- .../traefik-volume-config.profile.yaml | 8 ++--- ...profile.yaml => proxy-docker.profile.yaml} | 8 ++--- ...rofile.yaml => storage-btrfs.profile.yaml} | 8 ++--- ....profile.yaml => storage-zfs.profile.yaml} | 8 ++--- profiles/volumes/certificates.profile.yaml | 8 ----- .../volumes/volume-letsencrypt.profile.yaml | 9 +++++ 16 files changed, 98 insertions(+), 43 deletions(-) create mode 100755 .mise/tasks/show rename profiles/applications/{gitea.profile.yaml => app-gitea.profile.yaml} (78%) rename profiles/applications/{mariadb.profile.yaml => app-mariadb.profile.yaml} (96%) rename profiles/applications/{nextcloud.profile.yaml => app-nextcloud.profile.yaml} (96%) rename profiles/applications/{ollama.lxd.profile.yaml => app-ollama.profile.yaml} (98%) rename profiles/applications/{streamrip.profile.yaml => app-streamrip.profile.yaml} (98%) rename profiles/proxy/{proxy-docker-tcp.profile.yaml => proxy-docker.profile.yaml} (64%) rename profiles/storage/{btrfs.profile.yaml => storage-btrfs.profile.yaml} (50%) rename profiles/storage/{zfs.profile.yaml => storage-zfs.profile.yaml} (51%) delete mode 100644 profiles/volumes/certificates.profile.yaml create mode 100644 profiles/volumes/volume-letsencrypt.profile.yaml diff --git a/.mise/tasks/list b/.mise/tasks/list index bfce20e..3b2dc6f 100755 --- a/.mise/tasks/list +++ b/.mise/tasks/list @@ -5,28 +5,46 @@ set -euo pipefail source "$MISE_PROJECT_ROOT/.mise/lib.sh" -installed=$(lxc profile list --format csv --columns n,u 2>/dev/null) || die "Impossible d'interroger LXD (lxc profile list)" +installed=$(lxc profile list --format yaml 2>/dev/null) || die "Impossible d'interroger LXD (lxc profile list)" -declare -A used -while IFS=, read -r n u; do used[$n]=$u; done <<<"$installed" +declare -A used lxd_desc +while IFS=$'\t' read -r n u d; do + used[$n]=$u + lxd_desc[$n]=$d +done < <(yq -r '.[] | [.name, (.used_by | length), (.description // "")] | @tsv' <<<"$installed") + +# Description tronquée pour tenir dans sa colonne. +DESC_WIDTH=50 +short() { + local d="${1//$'\n'/ }" + if [ "${#d}" -gt "$DESC_WIDTH" ]; then d="${d:0:$((DESC_WIDTH - 1))}…"; fi + printf '%s' "$d" +} + +# Ligne : icône, couleur du nom, nom, description, utilisé, fichier, suffixe. +row() { + printf " %s %s%-24s${R} ${D}%s${R}%*s %-7s ${D}%s${R}%s\n" \ + "$1" "$2" "$3" "$4" $((DESC_WIDTH - ${#4})) "" "$5" "$6" "${7:-}" +} declare -A seen same=0; changed=0; absent=0 -printf " ${B}%-2s %-26s %-8s %s${R}\n" "" "PROFIL" "UTILISÉ" "FICHIER" +printf " ${B} %-24s %-${DESC_WIDTH}s %-7s %s${R}\n" "PROFIL" "DESCRIPTION" "UTILISÉ" "FICHIER" while IFS=$'\t' read -r name file; do + desc=$(short "$(yq -r '.description // ""' "$MISE_PROJECT_ROOT/$file")") extra="" if [ -n "${seen[$name]:-}" ]; then extra=" ${RED}(nom en double : ${seen[$name]})${R}" fi seen[$name]=$file if [ -z "${used[$name]+x}" ]; then - printf " %-2s ${D}%-26s %-8s %s${R}%s\n" "⬜" "$name" "-" "$file" "$extra" + row "⬜" "$D" "$name" "$desc" "-" "$file" "$extra" absent=$((absent + 1)) elif is_same "$file" "$name"; then - printf " %-2s ${GREEN}%-26s${R} %-8s %s%s\n" "✅" "$name" "${used[$name]}" "$file" "$extra" + row "✅" "$GREEN" "$name" "$desc" "${used[$name]}" "$file" "$extra" same=$((same + 1)) else - printf " %-2s ${YELLOW}%-26s${R} %-8s %s%s\n" "⚠️" "$name" "${used[$name]}" "$file" "$extra" + row "⚠️" "$YELLOW" "$name" "$desc" "${used[$name]}" "$file" "$extra" changed=$((changed + 1)) fi done < <(repo_index) @@ -36,7 +54,7 @@ for n in "${!used[@]}"; do [ -n "${seen[$n]:-}" ] || others+=("$n"); done if [ "${usage_all:-false}" = "true" ] && [ "${#others[@]}" -gt 0 ]; then printf "\n ${B}Hors dépôt${R} ${D}(mise run import )${R}\n" while IFS= read -r n; do - printf " %-2s ${CYAN}%-26s${R} %-8s\n" "🔹" "$n" "${used[$n]}" + row "🔹" "$CYAN" "$n" "$(short "${lxd_desc[$n]}")" "${used[$n]}" "" done < <(printf '%s\n' "${others[@]}" | sort) fi diff --git a/.mise/tasks/show b/.mise/tasks/show new file mode 100755 index 0000000..37d7a0f --- /dev/null +++ b/.mise/tasks/show @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +#MISE description="Affiche le contenu d'un profil du dépôt (ou sa version installée dans LXD)" +#MISE quiet=true +#USAGE arg "[profile]" help="Nom de profil ou fichier du dépôt (défaut : sélection interactive)" +#USAGE flag "-l --lxd" help="Affiche la version installée dans LXD plutôt que le fichier du dépôt" +#USAGE complete "profile" run="mise run --quiet _names" +set -euo pipefail +source "$MISE_PROJECT_ROOT/.mise/lib.sh" + +arg="${usage_profile:-}" +[ -n "$arg" ] || arg=$(repo_index | cut -f2 | pick "Profil à afficher") +file=$(resolve_file "$arg") + +# Coloration YAML avec bat dans un terminal, sortie brute sinon. +render() { + if [ -t 1 ] && command -v bat >/dev/null 2>&1; then + bat --language yaml --paging never --style header,grid,numbers --file-name "$1" + else + cat + fi +} + +if [ "${usage_lxd:-false}" = "true" ]; then + name=$(profile_name "$file") + is_installed "$name" || die "Profil '$name' absent de LXD" + lxc profile show "$name" | render "lxd:$name" +else + render "$file" <"$MISE_PROJECT_ROOT/$file" +fi diff --git a/README.md b/README.md index 4080f0a..bc03a13 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This repository contains a collection of LXD profiles and network configurations ## Usage Prerequisites: [mise](https://mise.jdx.dev) and the `lxc` client. mise installs the -other tools declared in `mise.toml` (`yq`, `gum`, `delta`) with `mise install`. +other tools declared in `mise.toml` (`yq`, `gum`, `delta`, `bat`) with `mise install`. A short help message is displayed when entering the directory (mise `enter` hook), and `mise tasks` lists all available tasks. @@ -23,6 +23,7 @@ A profile can be designated by its name (`docker`) or its file | Task | Description | |---|---| | `mise run list [--all]` | Repository profiles and their state in LXD: ✅ up to date, ⚠️ installed but different, ⬜ not installed. `--all` also shows 🔹 profiles installed in LXD but missing from the repository | +| `mise run show [profile] [--lxd]` | Displays a repository profile (YAML highlighted with `bat`), or with `--lxd` the version installed in LXD | | `mise run diff [profile...]` | Diff between the installed profile (LXD) and the repository file. Without argument, every installed profile that differs. `--exit-code` returns 1 when there are differences | | `mise run install [profile...]` | Creates or updates profiles. An existing profile that differs shows its diff and asks for confirmation (`--yes` to skip). Without argument, interactive selection; `--all` for every profile | | `mise run import [profile] [file]` | Writes an installed LXD profile to the repository (without `used_by`, `project`, empty `config`/`devices`). Defaults to the repository file declaring that name, or `profiles/.profile.yaml`. Review with `git diff` before committing | diff --git a/docs/create-traefik-container.md b/docs/create-traefik-container.md index a3400b2..af4acd9 100644 --- a/docs/create-traefik-container.md +++ b/docs/create-traefik-container.md @@ -24,7 +24,7 @@ Create the container with required profiles: lxc init ubuntu:lts -p default -p traefik traefik-container # Or with additional profiles for production use: -# lxc init ubuntu:lts -p default -p zfs -p net-front -p traefik -p traefik-volume-config traefik-container +# lxc init ubuntu:lts -p default -p storage-zfs -p net-front -p traefik -p traefik-volume-config traefik-container ``` ### Fix IP Address (Optional) diff --git a/mise.toml b/mise.toml index 741c66e..7122bd0 100644 --- a/mise.toml +++ b/mise.toml @@ -19,6 +19,7 @@ cat <