diff --git a/.mise/tasks/list b/.mise/tasks/list index 3b2dc6f..fea9f82 100755 --- a/.mise/tasks/list +++ b/.mise/tasks/list @@ -44,7 +44,7 @@ while IFS=$'\t' read -r name file; do row "โœ…" "$GREEN" "$name" "$desc" "${used[$name]}" "$file" "$extra" same=$((same + 1)) else - row "โš ๏ธ" "$YELLOW" "$name" "$desc" "${used[$name]}" "$file" "$extra" + row "๐Ÿ“" "$YELLOW" "$name" "$desc" "${used[$name]}" "$file" "$extra" changed=$((changed + 1)) fi done < <(repo_index) @@ -59,4 +59,4 @@ if [ "${usage_all:-false}" = "true" ] && [ "${#others[@]}" -gt 0 ]; then fi echo -echo " โœ… ${same} ร  jour โš ๏ธ ${changed} diffรฉrent(s) ${D}(mise run diff)${R} โฌœ ${absent} non installรฉ(s) ๐Ÿ”น ${#others[@]} hors dรฉpรดt${D}$([ "${usage_all:-false}" = "true" ] || echo ' (--all)')${R}" +echo " โœ… ${same} ร  jour ๐Ÿ“ ${changed} diffรฉrent(s) ${D}(mise run diff)${R} โฌœ ${absent} non installรฉ(s) ๐Ÿ”น ${#others[@]} hors dรฉpรดt${D}$([ "${usage_all:-false}" = "true" ] || echo ' (--all)')${R}" diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..4e368b1 --- /dev/null +++ b/README.en.md @@ -0,0 +1,102 @@ +# LXD Profiles + +๐Ÿ‡ซ๐Ÿ‡ท [Lire en franรงais](README.md) + +This repository contains a collection of LXD profiles and network configurations designed to streamline the deployment and management of LXD containers. + +## Directory Structure + +- `profiles/`: Contains various LXD profile definitions categorized by their purpose (e.g., applications, networking, storage). +- `network/`: Defines LXD network configurations. +- `docs/`: Additional documentation and helper scripts. +- `demo/`: Animated demos of the mise tasks ([how they are made](demo/README.md)). +- `mise.toml`, `.mise/`: optional [mise](https://mise.jdx.dev) tasks to manage LXD profiles (`mise.demo.toml`: demo recording tools). + +## Demo + +### Plain `lxc`, without mise + +![Create a profile from its YAML file with lxc](demo/lxc.gif) + +### Tour of the mise tasks + +Welcome message when entering the directory, profile list with their state in +LXD, profile content and diff between LXD and the repository. + +![Welcome message, profile list, profile content and diff](demo/tour.gif) + +### Install, update and import a profile + +A profile is installed, then changed directly in LXD: installing it again shows +the diff and asks for confirmation; `import` brings the change back into the +repository instead. + +![Install a profile, update it after a change in LXD, import it back](demo/install.gif) + +## Usage + +Profiles can be used with the `lxc` client alone; [mise](https://mise.jdx.dev) +is optional and only adds comfort on top of it. + +| Use case | Prerequisites | +|---|---| +| Plain `lxc` | LXD and the `lxc` client | +| With mise | LXD, the `lxc` client and [mise](https://mise.jdx.dev) (it installs `yq`, `gum`, `delta` and `bat` with `mise install`) | + +### Plain `lxc`, without mise + +Each `*.profile.yaml` file is a regular LXD profile, as printed by +`lxc profile show`: it can be applied as is. + +```bash +# Create (or update) a profile from its file +lxc profile create docker +lxc profile edit docker < profiles/containerization/docker.profile.yaml + +# Use it when launching an instance +lxc launch ubuntu:24.04 web -p default -p docker + +# Compare the installed profile with the repository +# (raw diff: field order, quoting and used_by also show up) +diff <(lxc profile show docker) profiles/containerization/docker.profile.yaml + +# Save a profile changed in LXD back into the repository +# (then remove the read-only used_by and project fields) +lxc profile show docker > profiles/containerization/docker.profile.yaml +``` + +### With mise + +The mise tasks wrap the same `lxc` commands and add: + +- a short help displayed when entering the directory (mise `enter` hook), and + `mise tasks` to list every task; +- a profile list showing each one's state in LXD (up to date, different, not + installed); +- colored diffs (`delta`) computed on a normalized form, so formatting or + quoting alone never shows up as a change; +- interactivity: profile selection and yes/no confirmation before overwriting + a profile that differs (`gum`), YAML highlighting (`bat`); +- a clean import of LXD profiles into the repository. + +A profile can be designated by its name (`docker`) or its file +(`profiles/containerization/docker.profile.yaml`). + +| 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 | + +Differences are computed on a normalized form (keys sorted, values as strings, +read-only fields dropped). Top-level keys unknown to LXD (silently ignored by `lxc profile edit`) +are reported, and `install` refuses such files. + +```bash +mise run list --all +mise run diff docker +mise run install docker profiles/applications/traefik.profile.yaml +mise run import s3 profiles/applications/s3.profile.yaml && git diff +``` diff --git a/README.md b/README.md index 4f3d388..2633ca1 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,100 @@ -# LXD Profiles +# Profils LXD -This repository contains a collection of LXD profiles and network configurations designed to streamline the deployment and management of LXD containers. +๐Ÿ‡ฌ๐Ÿ‡ง [Read in English](README.en.md) -## Directory Structure +Ce dรฉpรดt rassemble des profils et des configurations rรฉseau LXD, pour simplifier +le dรฉploiement et la gestion de conteneurs LXD. -- `profiles/`: Contains various LXD profile definitions categorized by their purpose (e.g., applications, networking, storage). -- `network/`: Defines LXD network configurations. -- `docs/`: Additional documentation and helper scripts. -- `demo/`: Animated demos of the mise tasks ([how they are made](demo/README.md)). -- `mise.toml`, `.mise/`: [mise](https://mise.jdx.dev) tasks to manage LXD profiles. +## Organisation du dรฉpรดt -## Demo +- `profiles/` : les profils LXD, classรฉs par usage (applications, rรฉseau, stockageโ€ฆ). +- `network/` : les configurations rรฉseau LXD. +- `docs/` : documentation complรฉmentaire et scripts d'aide. +- `demo/` : les dรฉmos animรฉes ([comment elles sont produites](demo/README.md)). +- `mise.toml`, `.mise/` : tรขches [mise](https://mise.jdx.dev), optionnelles, pour gรฉrer les profils LXD (`mise.demo.toml` : outils d'enregistrement des dรฉmos). -![Welcome message, profile list, profile content and diff](demo/tour.gif) +## Dรฉmo -![Install a profile, update it after a change in LXD, import it back](demo/install.gif) +### Avec `lxc` seul, sans mise -## Usage +![Crรฉation d'un profil ร  partir de son fichier YAML avec lxc](demo/lxc.gif) -Prerequisites: [mise](https://mise.jdx.dev) and the `lxc` client. mise installs the -other tools declared in `mise.toml` (`yq`, `gum`, `delta`, `bat`) with `mise install`. +### Tour des tรขches mise -A short help message is displayed when entering the directory (mise `enter` hook), -and `mise tasks` lists all available tasks. +Message d'accueil ร  l'entrรฉe dans le dossier, liste des profils avec leur รฉtat +dans LXD, contenu d'un profil et diffรฉrences entre LXD et le dรฉpรดt. -A profile can be designated by its name (`docker`) or its file +![Message d'accueil, liste des profils, contenu d'un profil et diff](demo/tour.gif) + +### Installer, mettre ร  jour et importer un profil + +Un profil est installรฉ, puis modifiรฉ directement dans LXD : le rรฉinstaller +affiche le diff et demande une confirmation ; `import` rapatrie au contraire +la modification dans le dรฉpรดt. + +![Installation d'un profil, mise ร  jour aprรจs une modification dans LXD, puis import](demo/install.gif) + +## Utilisation + +Les profils s'utilisent avec le seul client `lxc` ; [mise](https://mise.jdx.dev) +est optionnel et n'apporte que du confort en plus. + +| Cas d'usage | Prรฉrequis | +|---|---| +| `lxc` seul | LXD et le client `lxc` | +| Avec mise | LXD, le client `lxc` et [mise](https://mise.jdx.dev) (qui installe `yq`, `gum`, `delta` et `bat` avec `mise install`) | + +### Avec `lxc` seul, sans mise + +Chaque fichier `*.profile.yaml` est un profil LXD ordinaire, au format de +`lxc profile show` : il s'applique tel quel. + +```bash +# Crรฉer (ou mettre ร  jour) un profil ร  partir de son fichier +lxc profile create docker +lxc profile edit docker < profiles/containerization/docker.profile.yaml + +# L'utiliser au lancement d'une instance +lxc launch ubuntu:24.04 web -p default -p docker + +# Comparer le profil installรฉ avec le dรฉpรดt +# (diff brut : l'ordre des champs, les guillemets et used_by apparaissent aussi) +diff <(lxc profile show docker) profiles/containerization/docker.profile.yaml + +# Enregistrer dans le dรฉpรดt un profil modifiรฉ dans LXD +# (puis retirer les champs en lecture seule used_by et project) +lxc profile show docker > profiles/containerization/docker.profile.yaml +``` + +### Avec mise + +Les tรขches mise s'appuient sur les mรชmes commandes `lxc` et ajoutent : + +- une aide courte affichรฉe ร  l'entrรฉe dans le dossier (hook `enter` de mise), + et `mise tasks` pour lister toutes les tรขches ; +- une liste des profils avec l'รฉtat de chacun dans LXD (ร  jour, diffรฉrent, + non installรฉ) ; +- des diff colorรฉs (`delta`), calculรฉs sur une forme normalisรฉe : une simple + diffรฉrence de mise en forme ou de guillemets n'apparaรฎt jamais ; +- de l'interactivitรฉ : sรฉlection des profils et confirmation oui/non avant + d'รฉcraser un profil qui diffรจre (`gum`), coloration du YAML (`bat`) ; +- un import propre des profils LXD dans le dรฉpรดt. + +Un profil se dรฉsigne par son nom (`docker`) ou par son fichier (`profiles/containerization/docker.profile.yaml`). -| Task | Description | +| Tรขche | 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 | +| `mise run list [--all]` | Profils du dรฉpรดt et leur รฉtat dans LXD : โœ… ร  jour, ๐Ÿ“ installรฉ mais diffรฉrent, โฌœ non installรฉ. `--all` affiche aussi ๐Ÿ”น les profils installรฉs dans LXD mais absents du dรฉpรดt | +| `mise run show [profil] [--lxd]` | Affiche un profil du dรฉpรดt (YAML colorรฉ par `bat`), ou avec `--lxd` la version installรฉe dans LXD | +| `mise run diff [profil...]` | Diff entre le profil installรฉ (LXD) et le fichier du dรฉpรดt. Sans argument, tous les profils installรฉs qui diffรจrent. `--exit-code` renvoie 1 s'il y a des diffรฉrences | +| `mise run install [profil...]` | Crรฉe ou met ร  jour des profils. Un profil existant qui diffรจre affiche son diff et demande confirmation (`--yes` pour passer outre). Sans argument, sรฉlection interactive ; `--all` pour tous les profils | +| `mise run import [profil] [fichier]` | ร‰crit un profil installรฉ dans LXD vers le dรฉpรดt (sans `used_by`, `project`, ni `config`/`devices` vides). Par dรฉfaut, le fichier du dรฉpรดt qui dรฉclare ce nom, sinon `profiles/.profile.yaml`. ร€ relire avec `git diff` avant de commiter | -Differences are computed on a normalized form (keys sorted, values as strings, -read-only fields dropped), so formatting or quoting alone never shows up as a -change. Top-level keys unknown to LXD (silently ignored by `lxc profile edit`) -are reported, and `install` refuses such files. +Les diffรฉrences sont calculรฉes sur une forme normalisรฉe (clรฉs triรฉes, valeurs +converties en chaรฎnes, champs en lecture seule รฉcartรฉs). Les clรฉs de premier +niveau inconnues de LXD (ignorรฉes sans avertissement par `lxc profile edit`) +sont signalรฉes, et `install` refuse ces fichiers. ```bash mise run list --all diff --git a/demo/README.md b/demo/README.md index b3cf247..bdb5cec 100644 --- a/demo/README.md +++ b/demo/README.md @@ -12,6 +12,7 @@ The `.cast` files can be played in Gitea's file view (asciinema player). | Scenario | Demo | Prerequisites | |---|---|---| | `tour.yaml` | welcome message, `list`, `show`, `diff` (read only) | LXD | +| `lxc.yaml` | plain `lxc`, without mise: create a profile from its YAML file | LXD, profile `unattended-upgrades` not installed | | `install.yaml` | `install`, diff and confirmation after a change in LXD, `import` | LXD, profile `unattended-upgrades` not installed | ## Recording a demo @@ -24,10 +25,11 @@ MISE_ENV=demo mise run demo # demo/.cast and demo/