Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f3f8feb
Initial plan
Copilot Nov 4, 2025
39f4f98
feat: add installer trait and implementations with install command
Copilot Nov 4, 2025
8ce6ca9
test: add Docker tests for install command
Copilot Nov 4, 2025
1706359
fix: format code and fix detector test imports
Copilot Nov 4, 2025
edbfde5
docs: update README with install command and fix clippy warnings
Copilot Nov 4, 2025
2cd4101
fix: address code review feedback - async sleep and cross-platform co…
Copilot Nov 4, 2025
1ebd884
fix: resolve Windows compilation errors in OpenTofu installer
Copilot Nov 4, 2025
65cc194
fix: conditionally import unused modules on Windows
Copilot Nov 4, 2025
c2df939
perf: [#117] optimize Docker tests by pre-building container image wi…
josecelano Nov 5, 2025
a453356
perf: [#117] optimize Ansible installer by removing apt-get update
josecelano Nov 5, 2025
92dc7a1
feat: [#117] add ImageBuilder to auto-build Docker images for package…
josecelano Nov 5, 2025
9b5767a
feat: [#117] optimize OpenTofu installer tests by moving dependencies…
josecelano Nov 5, 2025
c6f7898
feat: [#117] add snapd to Dockerfile and document LXD test limitations
josecelano Nov 5, 2025
04c9381
refactor: [#117] simplify error handling with automatic conversions
josecelano Nov 5, 2025
4f25a43
test: [#117] use exit codes instead of parsing output in dependency-i…
josecelano Nov 5, 2025
d9db859
refactor: [#117] rename integration test files for clarity
josecelano Nov 5, 2025
1e1ee7d
docs: [#117] integrate dependency-installer package into global docum…
josecelano Nov 5, 2025
a0d9276
fix: [#117] correct test file paths in dependency-installer Cargo.toml
josecelano Nov 5, 2025
6e0b214
test: [#117] suppress stderr in error exit code test for clean output
josecelano Nov 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This is a deployment infrastructure proof-of-concept for the Torrust ecosystem.
## 📁 Key Directories

- `src/` - Rust source code organized by DDD layers (`domain/`, `application/`, `infrastructure/`, `shared/`)
- `src/bin/` - Binary executables (linter, E2E tests)
- `src/bin/` - Binary executables (linter, E2E tests, dependency installer)
- `data/` - Environment-specific data and source templates
- `templates/` - Generated template examples and test fixtures
- `build/` - Generated runtime configurations (git-ignored)
Expand All @@ -29,7 +29,9 @@ This is a deployment infrastructure proof-of-concept for the Torrust ecosystem.
- `docs/decisions/` - Architectural Decision Records (ADRs)
- `scripts/` - Shell scripts for development tasks
- `fixtures/` - Test data and keys for development
- `packages/` - Rust workspace packages (linting tools)
- `packages/` - Rust workspace packages (see `packages/README.md` for details)
- `dependency-installer/` - Dependency detection and installation for development setup
- `linting/` - Unified linting framework

## 📄 Key Configuration Files

Expand Down Expand Up @@ -103,15 +105,22 @@ These principles should guide all development decisions, code reviews, and featu

## 🧪 Build & Test

- **Setup Dependencies**: `cargo run --bin dependency-installer install` (sets up required development tools)
- **Check dependencies**: `cargo run --bin dependency-installer check` (verifies installation)
- **List dependencies**: `cargo run --bin dependency-installer list` (shows all dependencies with status)
- Required tools: OpenTofu, Ansible, LXD, cargo-machete
- See [`packages/dependency-installer/README.md`](../packages/dependency-installer/README.md) for details
- **Lint**: `cargo run --bin linter all` (comprehensive - tests stable & nightly toolchains)
- Individual linters: `cargo run --bin linter {markdown|yaml|toml|cspell|clippy|rustfmt|shellcheck}`
- Alternative: `./scripts/lint.sh` (wrapper that calls the Rust binary)
- **Dependencies**: `cargo machete` (mandatory before commits - no unused dependencies)
- **Build**: `cargo build`
- **Test**: `cargo test`
- **Unit Tests**: When writing unit tests, follow conventions described in [`docs/contributing/testing/`](../docs/contributing/testing/)
- **E2E Tests**: `cargo run --bin e2e-tests-full` (comprehensive - all tests) or individual tests:
- **E2E Tests**:
- `cargo run --bin e2e-tests-full` - Comprehensive tests (⚠️ **LOCAL ONLY** - cannot run on GitHub Actions due to network connectivity issues)
- `cargo run --bin e2e-provision-tests` - Infrastructure provisioning tests
- `cargo run --bin e2e-config-tests` - Configuration validation tests
- See [`docs/e2e-testing.md`](../docs/e2e-testing.md) for detailed information about CI limitations

Follow the project conventions and ensure all checks pass.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,32 @@ This repository uses LXD virtual machines for local virtualization and developme

This is a Rust application that automates deployment infrastructure using OpenTofu and Ansible.

Install the required tools:
#### Automated Setup (Recommended)

The project provides a dependency installer tool that automatically detects and installs required dependencies:

```bash
# Install all required dependencies
cargo run --bin dependency-installer install

# Check which dependencies are installed
cargo run --bin dependency-installer check

# List all dependencies with status
cargo run --bin dependency-installer list
```

The installer supports: **OpenTofu**, **Ansible**, **LXD**, and **cargo-machete**.

For detailed information, see **[📖 Dependency Installer →](packages/dependency-installer/README.md)**.

#### Manual Setup

If you prefer manual installation or need to troubleshoot:

**Check installations:**

```bash
# Check installations
lxd version && tofu version && ansible --version && cargo --version
```

Expand All @@ -76,7 +98,7 @@ lxd version && tofu version && ansible --version && cargo --version
- **[📖 OpenTofu Setup Guide →](docs/tech-stack/opentofu.md)**
- **[📖 Ansible Setup Guide →](docs/tech-stack/ansible.md)**

**Quick install:**
**Quick manual install:**

```bash
# Install Rust (if not already installed)
Expand Down
9 changes: 8 additions & 1 deletion docs/contributing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ This guide will help you understand our development practices and contribution w
## 🚀 Getting Started

1. **Fork and clone** the repository
2. **Set up your development environment** following the main [README](../../README.md)
2. **Install dependencies** using the automated installer:

```bash
cargo run --bin dependency-installer install
```

See [Dependency Installer](../../packages/dependency-installer/README.md) for details.

3. **Read the branching** guidelines in [branching.md](./branching.md)
4. **Install and run linters** as described in [linting.md](./linting.md)
5. **Follow the commit process** outlined in [commit-process.md](./commit-process.md)
Expand Down
46 changes: 43 additions & 3 deletions docs/e2e-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,35 @@ Combines both provision and configuration phases in a single LXD VM for comprehe

## 🛠️ Prerequisites

### For E2E Provision Tests
### Automated Setup (Recommended)

The project provides a dependency installer tool that automatically detects and installs required dependencies:

```bash
# Install all required dependencies
cargo run --bin dependency-installer install

# Check which dependencies are installed
cargo run --bin dependency-installer check

# List all dependencies with status
cargo run --bin dependency-installer list
```

The installer supports:

- **cargo-machete** - Detects unused Rust dependencies
- **OpenTofu** - Infrastructure provisioning tool
- **Ansible** - Configuration management tool
- **LXD** - VM-based testing infrastructure

For detailed information, see [`packages/dependency-installer/README.md`](../packages/dependency-installer/README.md).

### Manual Setup

If you prefer manual installation or need to troubleshoot:

#### For E2E Provision Tests

1. **LXD installed and configured**

Expand All @@ -195,7 +223,7 @@ Combines both provision and configuration phases in a single LXD VM for comprehe
# Installation instructions in docs/tech-stack/opentofu.md
```

### For E2E Configuration Tests
#### For E2E Configuration Tests

1. **Docker installed**

Expand All @@ -210,10 +238,22 @@ Combines both provision and configuration phases in a single LXD VM for comprehe
# Installation instructions in docs/tech-stack/ansible.md
```

### For Full Local Tests (`e2e-tests-full`)
#### For Full Local Tests (`e2e-tests-full`)

Requires **all** of the above: LXD, OpenTofu, Docker, and Ansible.

### Verification

After setup (automated or manual), verify all dependencies are available:

```bash
# Quick check (exit code indicates success/failure)
cargo run --bin dependency-installer check

# Detailed check with logging
cargo run --bin dependency-installer check --verbose
```

## 🐛 Troubleshooting

### Test Environment Cleanup
Expand Down
151 changes: 151 additions & 0 deletions packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Torrust Tracker Deployer - Packages

This directory contains reusable Rust workspace packages that support the Torrust Tracker Deployer project. These packages are designed to be modular, maintainable, and potentially reusable across other Torrust projects.

## 📦 Available Packages

### [`dependency-installer/`](./dependency-installer/)

**Purpose**: Dependency detection and installation utilities for development environments

**Key Features**:

- Detects if required development tools are installed (OpenTofu, Ansible, LXD, cargo-machete)
- Installs missing dependencies automatically
- Provides CLI for manual and automated use
- Designed for CI/CD pipelines and automated workflows
- Uses structured logging (tracing) for observability
- Exit-code based success/failure indication for automation

**Use Cases**:

- Setting up development environments for humans and AI agents
- Pre-flight checks in E2E test suites
- CI/CD pipeline dependency validation
- Automated development environment provisioning

**Documentation**: See [packages/dependency-installer/README.md](./dependency-installer/README.md)

### [`linting/`](./linting/)

**Purpose**: Unified linting framework for Rust projects

**Key Features**:

- Supports multiple linters: markdown, YAML, TOML, Rust (clippy + rustfmt), shellcheck
- Pre-built CLI components for easy binary creation
- Extensible architecture for adding new linters
- Uses existing configuration files (`.taplo.toml`, `.yamllint.yml`, etc.)

**Use Cases**:

- Enforcing code quality standards
- Pre-commit validation
- CI/CD linting pipelines
- Standardizing linting across multiple projects

**Documentation**: See [packages/linting/README.md](./linting/README.md)

## 🏗️ Package Architecture

All packages in this directory:

- Are part of a Cargo workspace (defined in root `Cargo.toml`)
- Can be used independently or as library crates
- Follow the project's development principles (observability, testability, user-friendliness)
- Provide both CLI binaries and programmatic APIs
- Use structured logging via the `tracing` crate
- Follow consistent error handling patterns

## 🚀 Using Packages

### As Library Crates

```rust
// Add to your Cargo.toml
[dependencies]
torrust-linting = { path = "packages/linting" }
torrust-dependency-installer = { path = "packages/dependency-installer" }
```

### As CLI Binaries

```bash
# Run the linter
cargo run --bin linter all

# Run the dependency installer
cargo run --bin dependency-installer check
cargo run --bin dependency-installer install
```

## 🎯 Package Design Principles

### Automation-First Design

Packages prioritize **automation and CI/CD workflows**:

- **Exit codes** indicate success/failure (0 = success, non-zero = failure)
- **Structured logging** provides rich context without parsing output
- **Flags for verbosity** (`--verbose`, `--log-level`) control output detail
- **Minimal output** by default, detailed only when needed

### Type Safety

- Use strongly-typed enums and structs
- Leverage Rust's type system for compile-time guarantees
- Avoid stringly-typed APIs

### Error Handling

- Clear, actionable error messages
- Preserve error context with source chains
- Use thiserror for structured error types

### Extensibility

- Easy to add new functionality (linters, dependencies)
- Plugin-like architecture where appropriate
- Trait-based abstractions for flexibility

## 📋 Adding New Packages

When creating new packages:

1. **Create package directory** under `packages/`
2. **Add to workspace** in root `Cargo.toml`:

```toml
[workspace]
members = [
"packages/your-new-package",
# ...
]
```

3. **Create package README** documenting purpose and usage
4. **Update this file** to include the new package in the list above
5. **Follow conventions**:
- Use `tracing` for logging
- Provide both CLI and library interfaces
- Follow project development principles
- Add comprehensive tests

## 🔗 Related Documentation

- [Development Principles](../docs/development-principles.md) - Core principles guiding all packages
- [Error Handling Guide](../docs/contributing/error-handling.md) - Error handling patterns
- [Testing Conventions](../docs/contributing/testing/) - Testing standards
- [E2E Testing Guide](../docs/e2e-testing.md) - How packages integrate with E2E tests

## 💡 Future Packages

Potential future packages that could be added:

- **Configuration Management**: Reusable config loading and validation
- **Template Engine**: Tera template rendering utilities
- **SSH Client**: SSH operations and connectivity checking
- **Infrastructure Clients**: OpenTofu, Ansible, LXD client abstractions
- **Test Utilities**: Common test helpers and fixtures

These packages would further modularize the codebase and improve reusability across the Torrust ecosystem.
11 changes: 8 additions & 3 deletions packages/dependency-installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ name = "dependency-installer"
path = "src/bin/dependency-installer.rs"

[dependencies]
async-trait = "0.1"
clap = { version = "4.0", features = [ "derive" ] }
thiserror = "1.0"
tokio = { version = "1.0", features = [ "full" ] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [ "env-filter" ] }

[dev-dependencies]
testcontainers = "0.25"
tokio = { version = "1.0", features = [ "full" ] }

[[test]]
name = "docker_check_command"
path = "tests/docker_check_command.rs"
name = "check_command_docker_integration"
path = "tests/check_command_docker_integration.rs"

[[test]]
name = "install_command_docker_integration"
path = "tests/install_command_docker_integration.rs"
Loading
Loading