Skip to content

Feat/improve bootstraping - #2

Merged
bartrosa merged 23 commits into
mainfrom
feat/improve-bootstraping
Jul 15, 2026
Merged

bartrosa merged 23 commits into
mainfrom
feat/improve-bootstraping

Conversation

@bartrosa

Copy link
Copy Markdown
Owner

Summary

This PR turns homelab-cli from a scaffold into a usable provisioning toolchain. Users can install lab from GitHub releases, keep it up to date in place, prepare bootable USB drives, and bootstrap a fresh OS with idempotent essentials.

What's new

A. Release plumbing

  • Extended .goreleaser.yaml:
    • linux/amd64, linux/arm64, darwin/amd64, darwin/arm64
    • Artifacts: .tar.gz, .deb, .rpm
    • checksums.txt (SHA256)
    • nfpms: maintainer/description/license, bindir: /usr/bin, recommends: mise, podman, distrobox
    • Changelog filters (docs:, chore:, test:, ci: excluded), sort asc
    • Release: draft: false, prerelease: auto, mode: replace
  • .github/workflows/release.yml unchanged in behavior (tag v*, fetch-depth: 0, Go cache, goreleaser release --clean)

B. Install scripts

  • scripts/install.sh (POSIX sh):
    • OS/arch detection (linux/darwin, amd64/arm64)
    • Default prefix /usr/local, fallback to $HOME/.local when not writable
    • Flags: --version, --prefix, --force, --check
    • Downloads .tar.gz, verifies SHA256 from checksums.txt, installs lab
  • scripts/uninstall.sh: removes binary from prefix (default /usr/local/bin/lab)

C. lab self-update

  • New command: lab self-update
  • Flags: --check (exit 0 up to date / 3 update available), --version, --pre-release, --yes
  • Package internal/updater/: GitHub releases, semver compare, checksum verify, atomic binary replace
  • Sudo escalation not performed — clear message when install path is not writable
  • clierrors.ExitError + main.go support for exit code 3 on --check

D. lab iso — bootable USB

Command Description
lab iso list Supported distros and resolved versions
lab iso download <distro> Download + SHA256 verify (+ optional GPG via system gpg)
lab iso disks Block devices, USB vs SYSTEM (Linux, lsblk -J)
lab iso write <iso> --to <device> Safe dd with confirmation and system-disk guards
  • internal/iso/: catalog, Ubuntu/Fedora resolvers, download, verify, write, disk classification
  • MVP resolvers: Ubuntu Desktop LTS, Fedora Silverblue
  • Stubs (ErrNotImplemented): ubuntu-server, fedora-workstation, debian, arch, opensuse-tumbleweed, nixos
  • Linux-only for disks/write; macOS stubs return not implemented yet
  • Safety: refuse system disks, mounted partitions (unless --force), devices < 4 GiB, require exact device path confirmation

E. lab bootstrap essentials

  • New subcommand: lab bootstrap essentials
  • Targets: --target ubuntu|silverblue|auto (from /etc/os-release)
  • Flags: --yes, --skip, --only, --dry-run
  • Idempotent sections:
    • system-update, cli-basics, shell-tools, build, container-runtime, mise, distrobox, flatpak-flathub
  • internal/pkgmgr/: apt, rpm-ostree, detect
  • internal/bootstrap/: essentials runner, package map, Docker (Ubuntu), mise, distrobox, Flathub
  • internal/exec/: testable Runner interface (all external commands mockable in tests)
  • Silverblue: rpm-ostree install --idempotent, reboot notice after layering (no auto-reboot)

Other changes

  • internal/cli/root.go: register self-update, iso, bootstrap essentials
  • README.md: one-liner install, upgrade, provisioning walkthrough
  • docs/commands.md: mark new commands as ✅ ready
  • CHANGELOG.md: [0.2.0] section
  • .gitignore: release artifacts (.deb, .rpm, tarballs, checksums), .tools/, lab binary

Tests

Unit tests (mock HTTP / mock runner, no real apt/dd/rpm-ostree):

  • internal/updater/github_test.go, semver_test.go
  • internal/iso/catalog_test.go (lsblk JSON classification)
  • internal/pkgmgr/detect_test.go, apt_test.go
  • internal/bootstrap/essentials_test.go
  • internal/exec/runner_test.go

Manual test plan

  • Tag v0.2.0 → GH Actions publishes .deb, .rpm, .tar.gz, checksums.txt
  • curl -sSL .../install.sh | bashlab in PATH, lab version shows release
  • lab self-update --check → exit 0 when on latest
  • lab iso list → catalog with Ubuntu Desktop + Silverblue
  • lab iso download ubuntu-desktop → verified ISO in cache
  • lab iso download fedora-silverblue → verified ISO in cache
  • lab iso disks → USB vs SYSTEM labels
  • lab iso write on system disk → refused
  • lab iso write on USB → confirmation prompt, then burn
  • lab bootstrap essentials --dry-run → Ubuntu plan (auto-detect)
  • lab bootstrap essentials --dry-run --target silverblue → Silverblue plan
  • lab bootstrap essentials --only cli-basics --yes → installs on Ubuntu

Notes / follow-ups

  • GitHub repo hardcoded as bartrosa/homelab-cli (matches go.mod)
  • lab system usb (v0.1) remains alongside lab iso; new provisioning flow uses iso
  • Fedora Silverblue version: Bodhi API with fallback pin 41
  • lab iso list resolves versions via network (Ubuntu index + Fedora API)
  • GoReleaser maintainer / homepage placeholders — update before public release if needed
  • CHANGELOG date: replace YYYY-MM-DD at tag time

Breaking changes

None. Existing v0.1 commands and tests remain compatible.

bartrosa added 23 commits July 15, 2026 09:36
… and download capabilities

Added a comprehensive set of features for managing ISO downloads and disk operations. Introduced functions for classifying block devices, downloading ISOs with verification, and handling various Linux distributions including Ubuntu and Fedora. Implemented disk listing and inspection functionalities, along with utilities for parsing size and checksum data. Enhanced testing with new unit tests for ISO parsing and disk classification, improving overall reliability and usability of the ISO management tools.
Added new functionalities for setting up essential tools in a homelab environment, including Docker, Distrobox, and Mise. Implemented package management for various distributions, ensuring installation and configuration of necessary packages. Introduced helper functions for managing Flathub remote and streamlined the process of running essential scripts. Enhanced testing coverage for the bootstrap process, improving reliability and usability.
Removed duplicate import statements in cli_test.go for clarity. In root.go, added new commands for self-update and ISO management, improving the CLI's functionality and organization. This refactor streamlines the codebase and enhances command handling.
Introduced new commands for bootstrapping essential packages for Ubuntu and Fedora Silverblue, enhancing the CLI's setup capabilities. Added comprehensive ISO management functionalities, including downloading ISOs, listing supported distributions, and writing ISOs to USB drives. This update improves the overall usability and functionality of the CLI for managing homelab environments.
Adjusted the formatting of the Session struct fields in appctx.go for improved readability and consistency. This change enhances code clarity without altering functionality.
Added a new ExitError struct to encapsulate exit codes and messages, improving error reporting in CLI applications. This enhancement allows for more informative error messages and better control over process exit codes.
Introduced a new exec package that provides a testable interface for executing external commands. Implemented the Runner interface with OSRunner for running commands and capturing output. Added unit tests for the mockRunner and OSRunner to ensure functionality and reliability.
Adjusted the formatting of the Runner struct fields in run.go for improved readability and consistency. This change enhances code clarity without altering functionality.
… testing

Added APT and RPMOstree package managers to handle package installations for Debian/Ubuntu and Fedora Silverblue respectively. Implemented detection logic for identifying the OS and corresponding package manager from /etc/os-release. Included unit tests for APT installation and OS detection to ensure functionality and reliability. This update enhances the CLI's capability to manage packages across different Linux distributions.
Refactored the package detection logic in the Detect function to use a switch statement for better readability and maintainability. Added a helper function call in the test for improved test clarity. This change enhances the overall structure of the code without altering its functionality.
Updated the resource cleanup in the applyInstance, ensureDatabase, and grantConnect functions to use deferred anonymous functions for better error handling during connection closure. This change enhances code robustness without altering existing functionality.
Updated variable names for clarity in the discover.go and meta.go files, changing 'max' to 'highest' for better readability. Enhanced resource cleanup in usb.go by using a deferred function for closing the response body, improving error handling without altering existing functionality.
Introduced a new updater package that handles self-updates from GitHub releases. This includes functionality for fetching release metadata, downloading assets, verifying checksums, and performing updates. Added unit tests to ensure reliability and correctness of the update process. This enhancement significantly improves the CLI's ability to manage its own updates.
Adjusted the formatting of the knownLangs map for improved readability and consistency. This change enhances code clarity without altering functionality.
…rrors

Updated the main function to check for custom exit errors and print relevant messages before exiting. This change improves error reporting and ensures that specific exit codes are handled appropriately, enhancing the overall robustness of the CLI application.
Added a new install script that allows users to download and install the homelab-cli binary from GitHub releases, including version detection and checksum verification. Introduced an uninstall script to remove the installed binary, enhancing user experience and management of the CLI tool. This implementation provides a complete installation and uninstallation process for the application.
…ings

Modified the .golangci.yml file to exclude specific functions from errcheck and added additional exclusions for gosec. Updated the .goreleaser.yaml file to simplify the checksum name template, added nfpms configuration for packaging, and refined changelog filters. These changes improve linting configurations and streamline release management for the homelab-cli project.
Added version 0.2.0 to the changelog, introducing several new features including GoReleaser support for various package formats, installation and uninstallation scripts with SHA256 verification, and new commands for ISO management and bootstrapping essentials for Ubuntu and Fedora Silverblue. Updated the README to reflect these changes and provide clearer installation instructions, including a one-liner install command and self-update functionality. Enhanced command documentation to include new ISO-related commands.
Expanded the .gitignore file to exclude new build artifacts, local development files, and OS-specific files. Added entries for GoReleaser output, including package formats and checksums, to streamline the development process and prevent unnecessary files from being tracked.
@bartrosa
bartrosa merged commit c047d58 into main Jul 15, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant