Skip to content

Deployment tool for Torrust Tracker - automated infrastructure provisioning and configuration with Rust, OpenTofu, and Ansible

License

Notifications You must be signed in to change notification settings

torrust/torrust-tracker-deployer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Linting Testing E2E Provision Tests E2E Config Tests Test LXD Container Provisioning

Torrust Tracker Deployer

โš ๏ธ DEVELOPMENT STATUS: Not Production-Ready

This project is currently in active development and is not production-ready. It currently only supports local deployment using LXD virtualization for development and testing purposes.

Current Scope:

  • โœ… Local LXD virtual machine provisioning
  • โœ… Development and testing workflows
  • โŒ No real cloud provider support (AWS, GCP, Azure, Hetzner, etc.)
  • โŒ No production deployment capabilities

๐Ÿ“‹ MVP Goal: After completing the roadmap, we will have a Minimum Viable Product (MVP) that supports real cloud providers and production deployments.

This Rust application provides automated deployment infrastructure for Torrust tracker projects. Currently focused on local development and testing, it manages VM provisioning and cloud-init execution using LXD virtual machines. The goal is to establish the foundational deployment patterns that will later support real cloud providers.

๐ŸŽฏ Project Goals

Current Development Phase:

  • โœ… Create local VMs supporting cloud-init for development and CI testing
  • โœ… Test cloud-init execution and verification in controlled environments
  • โœ… Support Docker Compose inside VMs for application stacks
  • โœ… Fast, easy to install and use local development solution
  • โœ… No nested virtualization dependency (CI compatibility)

Future MVP Goals: (See roadmap)

  • ๐Ÿ”„ Real cloud provider support (Hetzner, AWS, GCP, Azure)
  • ๐Ÿ”„ Production deployment capabilities
  • ๐Ÿ”„ Multi-environment management

๐Ÿ”ง Local Development Approach

This repository uses LXD virtual machines for local virtualization and development:

โ˜๏ธ LXD Virtual Machines (templates/tofu/lxd/) - LOCAL DEVELOPMENT

  • Technology: Virtual machines with cloud-init support
  • Status: โœ… Production-ready for local development and CI testing
  • Best for: Local development, CI/CD environments, fast iteration
  • Requirements: No special virtualization needed

๐Ÿ“– See detailed documentation โ†’

๐Ÿ“Š LXD Benefits

๐Ÿ“– See detailed comparison โ†’

Feature LXD Virtual Machines
GitHub Actions Support โœ… Guaranteed
Nested Virtualization โŒ Not needed
Boot Time โœ… Fast (~5-10s)
Resource Usage โœ… Efficient
Installation โœ… Simple setup

๐Ÿš€ Quick Start

๐Ÿ“‹ Prerequisites

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

Install the required tools:

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

Missing tools? See detailed installation guides:

Quick install:

# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install LXD
sudo snap install lxd && sudo lxd init --auto && sudo usermod -a -G lxd $USER && newgrp lxd

# Install OpenTofu
curl -fsSL https://get.opentofu.org/install-opentofu.sh | sudo bash

# Install Ansible
sudo apt install ansible

๐Ÿ’ป Usage

๐Ÿš€ Main Application

The main application provides usage instructions:

# Build and run the application
cargo run

# Or install and run directly
cargo install --path .
torrust-tracker-deployer

๐Ÿ”ง Development Tasks

This project includes convenient scripts for common development tasks:

# Run all linters (markdown, YAML, TOML, shell scripts, Rust)
cargo run --bin linter all

Or run individual linters:

cargo run --bin linter markdown    # Markdown linting
cargo run --bin linter yaml        # YAML linting
cargo run --bin linter toml        # TOML linting
cargo run --bin linter cspell      # Spell checking
cargo run --bin linter clippy      # Rust code analysis
cargo run --bin linter rustfmt     # Rust formatting check
cargo run --bin linter shellcheck  # Shell script linting

๐Ÿ“– See linting documentation โ†’

๐Ÿงช Running E2E Tests

Use the E2E test binaries to run automated infrastructure tests with hardcoded environments:

# Run comprehensive E2E tests (LOCAL ONLY - connectivity issues in GitHub runners)
cargo run --bin e2e-tests-full

# Run individual E2E test suites
cargo run --bin e2e-config-tests      # Configuration generation and validation tests
cargo run --bin e2e-provision-tests   # Infrastructure provisioning tests

# Keep the test environment after completion for inspection
cargo run --bin e2e-tests-full -- --keep
cargo run --bin e2e-provision-tests -- --keep

# Use custom templates directory
cargo run --bin e2e-tests-full -- --templates-dir ./custom/templates

# See all available options
cargo run --bin e2e-tests-full -- --help

โš ๏ธ Important Notes:

  • E2E tests create hardcoded environments with predefined configurations
  • Use --keep flag to inspect generated data/ and build/ directories after tests
  • e2e-tests-full can only run locally due to connectivity issues in GitHub runners
  • To see final OpenTofu and Ansible templates, check build/ directories after running with --keep

๐Ÿ“– Manual Deployment Steps (Not Currently Supported)

โš ๏ธ Manual deployment is not currently possible. The application only supports E2E tests with hardcoded environments.

To explore the deployment process:

  1. Run E2E tests with --keep flag: cargo run --bin e2e-tests-full -- --keep
  2. Inspect generated templates in build/ directories
  3. Review environment data in data/ directories

Manual deployment commands will be available after completing the roadmap.

๐Ÿ“‹ Reference: Experimenting with OpenTofu and Ansible manually

If you want to experiment with OpenTofu and Ansible commands directly using the generated templates:

1๏ธโƒฃ Generate Resolved Templates

# Run E2E tests but keep the infrastructure for manual experimentation
cargo run --bin e2e-tests-full -- --keep

# This creates resolved templates (no variables) in build/ directories
# โœ… Verified: Creates build/e2e-full/tofu/lxd/ and build/e2e-full/ansible/

2๏ธโƒฃ Navigate to Generated Templates

# Navigate to the specific environment's resolved OpenTofu templates
cd build/e2e-full/tofu/lxd/

# Or navigate to resolved Ansible templates
cd build/e2e-full/ansible/

# Other available environments:
# cd build/e2e-provision/tofu/lxd/
# cd build/e2e-provision/ansible/
# cd build/e2e-config/ansible/   # (config tests don't create tofu resources)

3๏ธโƒฃ Execute Commands Manually

# From build/e2e-full/tofu/lxd/ - Execute OpenTofu commands
tofu plan -var-file=variables.tfvars    # โœ… Verified: Works with resolved templates
tofu validate                           # Validate configuration
tofu output -json                       # View current outputs
# Note: tofu apply already executed during E2E test

# From build/e2e-full/ansible/ - Execute Ansible commands
ansible-playbook --list-hosts -i inventory.yml wait-cloud-init.yml  # โœ… Verified: Works
ansible-playbook -i inventory.yml wait-cloud-init.yml              # Run playbook
ansible-playbook -i inventory.yml install-docker.yml               # Install Docker

4๏ธโƒฃ Connect to the Instance

# Connect to the running LXD instance directly
lxc exec torrust-tracker-vm-e2e-full -- /bin/bash

# Or via SSH (IP may vary, check tofu output)
ssh -i fixtures/testing_rsa torrust@$(cd build/e2e-full/tofu/lxd && tofu output -json | jq -r '.instance_info.value.ip_address')

5๏ธโƒฃ Destroy Infrastructure

# โœ… Verified: Destroy the infrastructure when done experimenting
cd build/e2e-full/tofu/lxd/
tofu destroy -var-file=variables.tfvars -auto-approve

# โœ… Verified: This removes both the VM instance and the LXD profile
# Alternative: Use LXD commands directly
# lxc delete torrust-tracker-vm-e2e-full --force
# lxc profile delete torrust-profile-e2e-full

โš ๏ธ Important: Currently there's no application command to destroy infrastructure manually. You must use either:

  1. OpenTofu destroy (recommended) - Uses resolved templates in build/ directories
  2. LXD commands - Direct LXD resource management
  3. Re-run E2E tests - Automatically destroys and recreates infrastructure

๐Ÿ“– For comprehensive LXD commands and examples, see LXD documentation

๐ŸŽญ Infrastructure Workflow

  1. Provision: OpenTofu creates and configures VMs with cloud-init
  2. Configure: Ansible connects to VMs and executes management tasks
  3. Verify: Automated checks ensure proper setup and functionality
Phase Tool Purpose
Infrastructure OpenTofu VM provisioning and cloud-init setup
Configuration Ansible Task execution and configuration management
Verification Ansible Playbooks System checks and validation

๐Ÿ“– See detailed Ansible documentation โ†’

๐Ÿงช Testing in GitHub Actions

The repository includes comprehensive GitHub Actions workflows for CI testing:

  • .github/workflows/linting.yml - Code Quality - Runs all linters (markdown, YAML, TOML, Rust, shell scripts)
  • .github/workflows/testing.yml - Unit Tests - Runs Rust unit tests and basic validation
  • .github/workflows/test-e2e-config.yml - E2E Config Tests - Tests configuration generation and validation
  • .github/workflows/test-e2e-provision.yml - E2E Provision Tests - Tests infrastructure provisioning workflows
  • .github/workflows/test-lxd-provision.yml - LXD Provisioning - Tests LXD VM provisioning specifically

Note: The full E2E tests (e2e-tests-full) can only be executed locally due to connectivity issues documented in docs/github-actions-issues/.

๏ฟฝ Roadmap

This project follows a structured development roadmap to evolve from the current local development focus to a production-ready deployment solution.

Current Development Status:

  • โœ… Local LXD Infrastructure: VM provisioning, cloud-init, E2E testing
  • โœ… Development Workflows: Linting, testing, CI/CD automation
  • โœ… Foundation Layer: OpenTofu + Ansible + Docker integration

Next Major Milestones:

  • ๐Ÿ”„ Main Application Commands: create, deploy, destroy, status
  • ๏ฟฝ Real Cloud Providers: Starting with Hetzner, expanding to AWS/GCP/Azure
  • ๐Ÿ”„ Production Features: HTTPS, backups, monitoring stack

๐Ÿ“– See complete roadmap โ†’

๐Ÿ“ Repository Structure

โ”œโ”€โ”€ .github/                  # CI/CD workflows and GitHub configuration
โ”‚   โ””โ”€โ”€ workflows/           # GitHub Actions workflow files
โ”œโ”€โ”€ build/                   # ๐Ÿ“ Generated runtime configs (git-ignored)
โ”‚   โ”œโ”€โ”€ e2e-config/          # E2E config test runtime files
โ”‚   โ”œโ”€โ”€ e2e-full/            # E2E full test runtime files
โ”‚   โ””โ”€โ”€ e2e-provision/       # E2E provision test runtime files
โ”œโ”€โ”€ data/                    # Environment-specific data and configurations
โ”‚   โ”œโ”€โ”€ e2e-config/          # E2E config test environment data
โ”‚   โ”œโ”€โ”€ e2e-full/            # E2E full test environment data
โ”‚   โ”œโ”€โ”€ e2e-provision/       # E2E provision test environment data
โ”‚   โ””โ”€โ”€ logs/                # Application logs
โ”œโ”€โ”€ docker/                  # Docker-related configurations
โ”‚   โ””โ”€โ”€ provisioned-instance/ # Docker setup for provisioned instances
โ”œโ”€โ”€ docs/                    # ๐Ÿ“– Detailed documentation
โ”‚   โ”œโ”€โ”€ tech-stack/          # Technology-specific documentation
โ”‚   โ”‚   โ”œโ”€โ”€ opentofu.md      # OpenTofu installation and usage
โ”‚   โ”‚   โ”œโ”€โ”€ ansible.md       # Ansible installation and usage
โ”‚   โ”‚   โ””โ”€โ”€ lxd.md          # LXD virtual machines
โ”‚   โ”œโ”€โ”€ decisions/           # Architecture Decision Records (ADRs)
โ”‚   โ”œโ”€โ”€ contributing/        # Contributing guidelines and conventions
โ”‚   โ”‚   โ”œโ”€โ”€ README.md        # Main contributing guide
โ”‚   โ”‚   โ”œโ”€โ”€ branching.md     # Git branching conventions
โ”‚   โ”‚   โ”œโ”€โ”€ commit-process.md # Commit process and pre-commit checks
โ”‚   โ”‚   โ”œโ”€โ”€ error-handling.md # Error handling principles
โ”‚   โ”‚   โ”œโ”€โ”€ module-organization.md # Module organization conventions
โ”‚   โ”‚   โ””โ”€โ”€ testing.md       # Testing conventions
โ”‚   โ”œโ”€โ”€ features/            # Feature specifications and documentation
โ”‚   โ”œโ”€โ”€ research/            # Research and analysis documents
โ”‚   โ””โ”€โ”€ *.md                 # Various documentation files
โ”œโ”€โ”€ examples/                # Example configurations and usage
โ”œโ”€โ”€ fixtures/                # Test fixtures and sample data
โ”‚   โ”œโ”€โ”€ testing_rsa*         # SSH key pair for testing
โ”‚   โ””โ”€โ”€ tofu/               # OpenTofu test fixtures
โ”œโ”€โ”€ packages/                # Rust workspace packages
โ”‚   โ””โ”€โ”€ linting/            # Linting utilities package
โ”‚       โ””โ”€โ”€ src/            # Linting implementation source code
โ”œโ”€โ”€ scripts/                 # Development and utility scripts
โ”‚   โ””โ”€โ”€ setup/              # Installation scripts for dependencies
โ”œโ”€โ”€ src/                     # ๐Ÿฆ€ Main Rust application source code (DDD Architecture)
โ”‚   โ”œโ”€โ”€ main.rs             # Main application binary entry point
โ”‚   โ”œโ”€โ”€ lib.rs              # Library root module
โ”‚   โ”œโ”€โ”€ container.rs        # Dependency injection container
โ”‚   โ”œโ”€โ”€ logging.rs          # Logging configuration
โ”‚   โ”œโ”€โ”€ bin/                # Binary executables
โ”‚   โ”‚   โ”œโ”€โ”€ linter.rs       # Unified linting command interface
โ”‚   โ”‚   โ””โ”€โ”€ e2e*.rs         # End-to-end testing binaries
โ”‚   โ”œโ”€โ”€ application/        # Application layer (use cases, commands)
โ”‚   โ”œโ”€โ”€ domain/             # Domain layer (business logic, entities)
โ”‚   โ”œโ”€โ”€ infrastructure/     # Infrastructure layer (external systems)
โ”‚   โ”œโ”€โ”€ shared/             # Shared utilities and common code
โ”‚   โ”œโ”€โ”€ testing/            # Testing utilities and mocks
โ”‚   โ”œโ”€โ”€ config/             # Configuration handling
โ”‚   โ””โ”€โ”€ e2e/                # End-to-end testing infrastructure
โ”œโ”€โ”€ templates/               # ๐Ÿ“ Template configurations (git-tracked)
โ”‚   โ”œโ”€โ”€ tofu/               # ๐Ÿ—๏ธ OpenTofu/Terraform templates
โ”‚   โ”‚   โ””โ”€โ”€ lxd/            # LXD VM template configuration
โ”‚   โ””โ”€โ”€ ansible/            # ๐Ÿค– Ansible playbook templates
โ”œโ”€โ”€ tests/                  # Integration and system tests
โ”œโ”€โ”€ target/                 # ๐Ÿฆ€ Rust build artifacts (git-ignored)
โ”œโ”€โ”€ Cargo.toml             # Rust workspace configuration
โ”œโ”€โ”€ Cargo.lock             # Rust dependency lock file
โ”œโ”€โ”€ cspell.json            # Spell checking configuration
โ”œโ”€โ”€ project-words.txt      # Custom dictionary for spell checking
โ”œโ”€โ”€ .markdownlint.json     # Markdown linting configuration
โ”œโ”€โ”€ .taplo.toml            # TOML formatting configuration
โ”œโ”€โ”€ .yamllint-ci.yml       # YAML linting configuration for CI
โ”œโ”€โ”€ README.md              # This file - project overview
โ”œโ”€โ”€ LICENSE                # Project license
โ””โ”€โ”€ .gitignore             # Git ignore rules

๐Ÿ“š Documentation

๐Ÿ”ฎ Next Steps

This project is currently focused on local development. The path to production-ready deployment is outlined in our ๐Ÿ“‹ Roadmap.

Key upcoming milestones:

  • Real Cloud Provider Support: Starting with Hetzner, then expanding to AWS, GCP, and Azure
  • Production Commands: create, deploy, destroy, and status commands for production environments
  • Application Stack Management: Complete Docker Compose stacks with Torrust Tracker, MySQL, Prometheus, and Grafana
  • HTTPS Support: SSL/TLS configuration for all services
  • Backup & Recovery: Database backups and disaster recovery procedures

๐Ÿ“– See full roadmap โ†’

About

Deployment tool for Torrust Tracker - automated infrastructure provisioning and configuration with Rust, OpenTofu, and Ansible

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages