feat: Improve profile listing by adding a desc and add a task to display profiles
This commit is contained in:
1 parent
19b6b16ea8
commit
1930cc67e0
16 files changed
+98
-43
No files matched your search
+26
-8
@@ -5,28 +5,46 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
source "$MISE_PROJECT_ROOT/.mise/lib.sh"
|
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
|
declare -A used lxd_desc
|
||||||
while IFS=, read -r n u; do used[$n]=$u; done <<<"$installed"
|
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
|
declare -A seen
|
||||||
same=0; changed=0; absent=0
|
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
|
while IFS=$'\t' read -r name file; do
|
||||||
|
desc=$(short "$(yq -r '.description // ""' "$MISE_PROJECT_ROOT/$file")")
|
||||||
extra=""
|
extra=""
|
||||||
if [ -n "${seen[$name]:-}" ]; then
|
if [ -n "${seen[$name]:-}" ]; then
|
||||||
extra=" ${RED}(nom en double : ${seen[$name]})${R}"
|
extra=" ${RED}(nom en double : ${seen[$name]})${R}"
|
||||||
fi
|
fi
|
||||||
seen[$name]=$file
|
seen[$name]=$file
|
||||||
if [ -z "${used[$name]+x}" ]; then
|
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))
|
absent=$((absent + 1))
|
||||||
elif is_same "$file" "$name"; then
|
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))
|
same=$((same + 1))
|
||||||
else
|
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))
|
changed=$((changed + 1))
|
||||||
fi
|
fi
|
||||||
done < <(repo_index)
|
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
|
if [ "${usage_all:-false}" = "true" ] && [ "${#others[@]}" -gt 0 ]; then
|
||||||
printf "\n ${B}Hors dépôt${R} ${D}(mise run import <profil>)${R}\n"
|
printf "\n ${B}Hors dépôt${R} ${D}(mise run import <profil>)${R}\n"
|
||||||
while IFS= read -r n; do
|
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)
|
done < <(printf '%s\n' "${others[@]}" | sort)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Executable
+29
@@ -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
|
||||||
@@ -12,7 +12,7 @@ This repository contains a collection of LXD profiles and network configurations
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Prerequisites: [mise](https://mise.jdx.dev) and the `lxc` client. mise installs the
|
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),
|
A short help message is displayed when entering the directory (mise `enter` hook),
|
||||||
and `mise tasks` lists all available tasks.
|
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 |
|
| 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 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 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 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>.profile.yaml`. Review with `git diff` before committing |
|
| `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>.profile.yaml`. Review with `git diff` before committing |
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Create the container with required profiles:
|
|||||||
lxc init ubuntu:lts -p default -p traefik traefik-container
|
lxc init ubuntu:lts -p default -p traefik traefik-container
|
||||||
|
|
||||||
# Or with additional profiles for production use:
|
# 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)
|
### Fix IP Address (Optional)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ cat <<MSG
|
|||||||
|
|
||||||
🗂️ ${b}Profils${r}
|
🗂️ ${b}Profils${r}
|
||||||
▸ mise run list [--all] ${d}profils du dépôt et état dans LXD (✅ ⚠️ ⬜ 🔹)${r}
|
▸ mise run list [--all] ${d}profils du dépôt et état dans LXD (✅ ⚠️ ⬜ 🔹)${r}
|
||||||
|
▸ mise run show [profil] [--lxd] ${d}contenu d'un profil (dépôt ou LXD)${r}
|
||||||
▸ mise run diff [profil...] ${d}diff installé (LXD) → dépôt${r}
|
▸ mise run diff [profil...] ${d}diff installé (LXD) → dépôt${r}
|
||||||
▸ mise run install [profil...] ${d}crée / met à jour (diff + confirmation, --all, --yes)${r}
|
▸ mise run install [profil...] ${d}crée / met à jour (diff + confirmation, --all, --yes)${r}
|
||||||
▸ mise run import [profil] [f] ${d}exporte un profil LXD vers le dépôt (puis git diff)${r}
|
▸ mise run import [profil] [f] ${d}exporte un profil LXD vers le dépôt (puis git diff)${r}
|
||||||
@@ -30,6 +31,7 @@ MSG
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
[tools]
|
[tools]
|
||||||
|
bat = "latest"
|
||||||
delta = "latest"
|
delta = "latest"
|
||||||
gum = "latest"
|
gum = "latest"
|
||||||
yq = "latest"
|
yq = "latest"
|
||||||
+7
-2
@@ -1,4 +1,4 @@
|
|||||||
name: gitea
|
name: app-gitea
|
||||||
description: Install gitea
|
description: Install gitea
|
||||||
config:
|
config:
|
||||||
cloud-init.vendor-data: |
|
cloud-init.vendor-data: |
|
||||||
@@ -23,4 +23,9 @@ config:
|
|||||||
runcmd:
|
runcmd:
|
||||||
# Install gitea
|
# Install gitea
|
||||||
- [ snap, install, gitea ]
|
- [ snap, install, gitea ]
|
||||||
|
devices:
|
||||||
|
data:
|
||||||
|
path: /var/snap/gitea/common
|
||||||
|
pool: zfs
|
||||||
|
source: gitea-data
|
||||||
|
type: disk
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
name: mariadb
|
name: app-mariadb
|
||||||
description: Install mariadb
|
description: Install mariadb
|
||||||
config:
|
config:
|
||||||
cloud-init.vendor-data: |
|
cloud-init.vendor-data: |
|
||||||
+3
-4
@@ -1,4 +1,4 @@
|
|||||||
name: nextcloud
|
name: app-nextcloud
|
||||||
description: Install Nextcloud
|
description: Install Nextcloud
|
||||||
config:
|
config:
|
||||||
cloud-init.vendor-data: |
|
cloud-init.vendor-data: |
|
||||||
@@ -24,10 +24,9 @@ config:
|
|||||||
runcmd:
|
runcmd:
|
||||||
# Install Nextcloud
|
# Install Nextcloud
|
||||||
- [ snap, install, nextcloud ]
|
- [ snap, install, nextcloud ]
|
||||||
|
|
||||||
devices:
|
devices:
|
||||||
nextcloud-data:
|
nextcloud-data:
|
||||||
type: disk
|
path: /var/snap/nextcloud
|
||||||
pool: zfs
|
pool: zfs
|
||||||
source: nextcloud-data
|
source: nextcloud-data
|
||||||
path: /var/snap/nextcloud
|
type: disk
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
name: ollama
|
name: app-ollama
|
||||||
description: LXD Profile to launch a private ollama instance
|
description: LXD Profile to launch a private ollama instance
|
||||||
config:
|
config:
|
||||||
linux.kernel_modules: overlay
|
linux.kernel_modules: overlay
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
name: streamrip
|
name: app-streamrip
|
||||||
description: Install streamrip (https://github.com/nathom/streamrip)
|
description: Install streamrip (https://github.com/nathom/streamrip)
|
||||||
config:
|
config:
|
||||||
cloud-init.vendor-data: |
|
cloud-init.vendor-data: |
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
name: traefik-config
|
name: traefik-volume-config
|
||||||
description: "Volume to mount traefik config dir from host"
|
description: Volume to mount traefik config dir from host
|
||||||
devices:
|
devices:
|
||||||
config:
|
config:
|
||||||
type: disk
|
|
||||||
source: /home/ubuntu/infra/new/traefik/config
|
|
||||||
path: /etc/traefik
|
path: /etc/traefik
|
||||||
shift: "true"
|
shift: "true"
|
||||||
|
source: /home/ubuntu/infra/new/traefik/config
|
||||||
|
type: disk
|
||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
name: proxy-docker-tcp
|
name: proxy-docker
|
||||||
description: Expose private docker sock via tcp on the host
|
description: Expose private docker sock via tcp on the host
|
||||||
devices:
|
devices:
|
||||||
docker:
|
dockersock:
|
||||||
type: proxy
|
|
||||||
listen: tcp:0.0.0.0:2375
|
|
||||||
connect: unix:/run/docker.sock
|
connect: unix:/run/docker.sock
|
||||||
|
listen: tcp:10.112.16.1:2375
|
||||||
|
type: proxy
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
name: btrfs
|
name: storage-btrfs
|
||||||
description: "root device on btrfs pool"
|
description: root device on btrfs pool
|
||||||
devices:
|
devices:
|
||||||
root:
|
root:
|
||||||
type: disk
|
|
||||||
pool: btrfs
|
|
||||||
path: /
|
path: /
|
||||||
|
pool: btrfs
|
||||||
|
type: disk
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
name: zfs
|
name: storage-zfs
|
||||||
description: "root device on zfs pool"
|
description: root device on zfs pool
|
||||||
devices:
|
devices:
|
||||||
root:
|
root:
|
||||||
type: disk
|
|
||||||
pool: zfs
|
|
||||||
path: /
|
path: /
|
||||||
|
pool: zfs
|
||||||
|
type: disk
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
name: certificates
|
|
||||||
description: "Volume to mount letsencrypt certificates from host"
|
|
||||||
devices:
|
|
||||||
certificates:
|
|
||||||
path: /certificates
|
|
||||||
shift: "true"
|
|
||||||
source: /etc/letsencrypt/live
|
|
||||||
type: disk
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
name: volume-letsencrypt
|
||||||
|
description: Volume contenant les certificats letsencrypt du host
|
||||||
|
devices:
|
||||||
|
certificates:
|
||||||
|
path: /etc/letsencrypt
|
||||||
|
readonly: "true"
|
||||||
|
shift: "true"
|
||||||
|
source: /etc/letsencrypt
|
||||||
|
type: disk
|
||||||
Reference in new issue
Block a user