From 976ab1607aa506c19950f25fbd19c9c25759e242 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 19:23:56 +0000 Subject: [PATCH 1/2] Initial plan From 6986a722ad90ce5cc433fd42418cb089ccf212af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 19:47:58 +0000 Subject: [PATCH 2/2] feat: [#119] Update CI workflows to use dependency-installer and remove bash scripts Co-authored-by: josecelano <58816+josecelano@users.noreply.github.com> --- .github/workflows/test-e2e-config.yml | 6 +- .github/workflows/test-e2e-provision.yml | 9 +- .github/workflows/test-lxd-provision.yml | 11 +- scripts/setup/README.md | 143 ++++++++++------------- scripts/setup/install-ansible.sh | 15 --- scripts/setup/install-lxd-ci.sh | 33 ------ scripts/setup/install-opentofu.sh | 16 --- 7 files changed, 77 insertions(+), 156 deletions(-) delete mode 100755 scripts/setup/install-ansible.sh delete mode 100755 scripts/setup/install-lxd-ci.sh delete mode 100755 scripts/setup/install-opentofu.sh diff --git a/.github/workflows/test-e2e-config.yml b/.github/workflows/test-e2e-config.yml index eac6a22d..7330ffcb 100644 --- a/.github/workflows/test-e2e-config.yml +++ b/.github/workflows/test-e2e-config.yml @@ -41,8 +41,10 @@ jobs: - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - - name: Install Ansible - run: ./scripts/setup/install-ansible.sh + - name: Install dependencies + run: | + cargo build -p torrust-dependency-installer --bin dependency-installer + cargo run -p torrust-dependency-installer --bin dependency-installer -- install - name: Setup Docker uses: docker/setup-buildx-action@v3 diff --git a/.github/workflows/test-e2e-provision.yml b/.github/workflows/test-e2e-provision.yml index e451fbf5..635f670d 100644 --- a/.github/workflows/test-e2e-provision.yml +++ b/.github/workflows/test-e2e-provision.yml @@ -37,11 +37,10 @@ jobs: - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - - name: Install and configure LXD - run: ./scripts/setup/install-lxd-ci.sh - - - name: Install OpenTofu - run: ./scripts/setup/install-opentofu.sh + - name: Install dependencies + run: | + cargo build -p torrust-dependency-installer --bin dependency-installer + cargo run -p torrust-dependency-installer --bin dependency-installer -- install - name: Verify installations run: | diff --git a/.github/workflows/test-lxd-provision.yml b/.github/workflows/test-lxd-provision.yml index 02a93451..9b201246 100644 --- a/.github/workflows/test-lxd-provision.yml +++ b/.github/workflows/test-lxd-provision.yml @@ -44,12 +44,6 @@ jobs: - name: Tune GitHub-hosted runner network uses: smorimoto/tune-github-hosted-runner-network@v1 - - name: Install and configure LXD - run: ./scripts/setup/install-lxd-ci.sh - - - name: Install OpenTofu - run: ./scripts/setup/install-opentofu.sh - - name: Setup Rust toolchain and build template system uses: dtolnay/rust-toolchain@stable with: @@ -58,6 +52,11 @@ jobs: - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 + - name: Install dependencies + run: | + cargo build -p torrust-dependency-installer --bin dependency-installer + cargo run -p torrust-dependency-installer --bin dependency-installer -- install + - name: Render template configurations run: | # Build the template system and render the static templates diff --git a/scripts/setup/README.md b/scripts/setup/README.md index 65d7e03f..e142aa1d 100644 --- a/scripts/setup/README.md +++ b/scripts/setup/README.md @@ -1,115 +1,100 @@ -# Setup Scripts +# Setup Scripts - MIGRATION NOTICE -This directory contains installation and configuration scripts for the tools required by the Torrust Tracker Deployer project. +**⚠️ This directory has been migrated to the Rust-based dependency installer.** -## Available Scripts +## Migration Notice -### Core Infrastructure Tools +The bash installation scripts (`install-opentofu.sh`, `install-ansible.sh`, `install-lxd-ci.sh`) have been **removed** and replaced with the Rust-based `dependency-installer` binary. -- **`install-opentofu.sh`** - Install OpenTofu (Terraform alternative) -- **`install-ansible.sh`** - Install Ansible automation platform +### New Installation Method -### Container/VM Providers - -- **`install-lxd-ci.sh`** - Install and configure LXD (CI-optimized) - -## Usage - -### Individual Installation +For dependency installation, use the `dependency-installer` binary: ```bash -# Install OpenTofu -./scripts/setup/install-opentofu.sh - -# Install Ansible -./scripts/setup/install-ansible.sh +# Install all dependencies +cargo run -p torrust-dependency-installer --bin dependency-installer -- install -# Install LXD (CI environment) -./scripts/setup/install-lxd-ci.sh -``` +# Check which dependencies are installed +cargo run -p torrust-dependency-installer --bin dependency-installer -- check -### Batch Installation +# List all available dependencies +cargo run -p torrust-dependency-installer --bin dependency-installer -- list -```bash -# Install all core tools -./scripts/setup/install-opentofu.sh -./scripts/setup/install-ansible.sh +# Install specific dependency +cargo run -p torrust-dependency-installer --bin dependency-installer -- install --dependency opentofu -# Install container provider -./scripts/setup/install-lxd-ci.sh +# See all options +cargo run -p torrust-dependency-installer --bin dependency-installer -- --help ``` -## CI vs Local Development - -### CI Environment Detection - -The scripts automatically detect CI environments and apply appropriate configurations: +### Benefits of the New Approach -- **CI Detection**: Checks for `CI=true`, `GITHUB_ACTIONS=true`, or `RUNNER_USER` environment variables -- **CI Optimizations**: Uses `sudo` commands and socket permission fixes -- **Logging**: Provides clear feedback about environment detection +- **Type-safe**: Rust's type system catches errors at compile time +- **Better error handling**: Clear, actionable error messages +- **Consistent logging**: Structured logging via `tracing` crate +- **Testable**: Unit and integration tests ensure reliability +- **Maintainable**: Single codebase for all dependency management +- **Cross-platform ready**: Foundation for supporting multiple platforms -### Local Development - -For local development, see the dedicated documentation: - -- **LXD**: [templates/tofu/lxd/README.md](../../templates/tofu/lxd/README.md) -- **LXD Tech Stack**: [docs/tech-stack/lxd.md](../../docs/tech-stack/lxd.md) +### Supported Dependencies -**Important**: The CI scripts use `sudo` commands and socket permission modifications that are **NOT recommended** for local development. Use proper group membership for local setups. +The dependency installer supports: -## Script Features +- **cargo-machete** - Detects unused Rust dependencies +- **OpenTofu** - Infrastructure provisioning tool (Terraform alternative) +- **Ansible** - Configuration management and automation platform +- **LXD** - Lightweight VM manager for container-based testing -### Common Features +### Documentation -- **Idempotent**: Safe to run multiple times -- **Verbose Logging**: Clear progress indicators with colored output -- **Error Handling**: Proper error checking and meaningful messages -- **Version Detection**: Skips installation if tool is already installed +For complete documentation on the dependency installer, see: -### Error Handling - -All scripts use `set -euo pipefail` for strict error handling: +- **Package README**: [packages/dependency-installer/README.md](../../packages/dependency-installer/README.md) +- **LXD Setup**: [templates/tofu/lxd/README.md](../../templates/tofu/lxd/README.md) +- **LXD Tech Stack**: [docs/tech-stack/lxd.md](../../docs/tech-stack/lxd.md) -- **`-e`**: Exit on any command failure -- **`-u`**: Exit on undefined variable usage -- **`-o pipefail`**: Exit on pipe command failures +### CI/CD Integration -### Logging Levels +GitHub Actions workflows now use the dependency installer: -- **🟢 INFO**: Normal progress messages -- **🟡 WARN**: Important notices or CI-specific actions -- **🔴 ERROR**: Failure messages +- **`.github/workflows/test-e2e-provision.yml`** - E2E provision and destroy tests +- **`.github/workflows/test-e2e-config.yml`** - E2E configuration tests +- **`.github/workflows/test-lxd-provision.yml`** - LXD provisioning tests -## Integration with Workflows +Example workflow step: -These scripts replace duplicated installation code in GitHub Actions workflows: +```yaml +- name: Install dependencies + run: | + cargo build -p torrust-dependency-installer --bin dependency-installer + cargo run -p torrust-dependency-installer --bin dependency-installer -- install +``` -- **`.github/workflows/test-e2e.yml`** -- **`.github/workflows/test-lxd-provision.yml`** +### Local Development -## Troubleshooting +For local development, the dependency installer automatically handles: -### Permission Issues +- **CI Detection**: Automatically applies CI-specific configurations when needed +- **Permissions**: Proper handling of LXD socket permissions +- **Group Membership**: Sets up appropriate user groups -If you encounter permission errors: +**Important**: For local LXD development, follow the proper group membership approach documented in the tech stack guides. -1. **For CI**: Scripts should handle permissions automatically -2. **For Local**: Follow the group membership setup in the tech stack documentation +### Troubleshooting -### Installation Failures +If you encounter issues with the dependency installer: -1. Check internet connectivity for download-based installations -2. Verify system requirements (Ubuntu/Debian for apt-based installs) -3. Check available disk space -4. Review script output for specific error messages +1. **Check installation status**: `cargo run -p torrust-dependency-installer --bin dependency-installer -- check` +2. **Enable debug logging**: Add `--verbose` flag or `--log-level debug` +3. **View available dependencies**: `cargo run -p torrust-dependency-installer --bin dependency-installer -- list` +4. **Check exit codes**: Exit code 0 = success, non-zero = failure -### Tool-Specific Issues +For detailed troubleshooting, see the [dependency installer README](../../packages/dependency-installer/README.md). -- **OpenTofu**: Requires `curl` and package management tools -- **Ansible**: Requires Python and pip (usually pre-installed) -- **LXD**: Requires snap and sufficient privileges +### Migration Timeline -## Future Enhancements +- **Created**: Issue #113 (Create Dependency Installation Package) +- **Migrated**: Issue #119 (Update CI Workflows and Remove Bash Scripts) +- **Removed bash scripts**: November 2025 -These bash scripts are designed to be simple and maintainable. For more complex installation logic, they may be replaced by Rust utilities in the future while maintaining the same interface. +This directory is preserved for documentation purposes and may be removed in future versions. diff --git a/scripts/setup/install-ansible.sh b/scripts/setup/install-ansible.sh deleted file mode 100755 index e73d8dbd..00000000 --- a/scripts/setup/install-ansible.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# Install Ansible automation platform -# -# Pre-condition: apt package lists should be up-to-date -# (run 'sudo apt-get update' before using this installer) - -set -euo pipefail - -# Check if Ansible is already installed -if command -v ansible &> /dev/null; then - echo "Ansible is already installed, skipping installation" - exit 0 -fi - -sudo apt-get install -y ansible diff --git a/scripts/setup/install-lxd-ci.sh b/scripts/setup/install-lxd-ci.sh deleted file mode 100755 index 66f1a579..00000000 --- a/scripts/setup/install-lxd-ci.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# Install and configure LXD for CI environments -# -# IMPORTANT: This script uses CI-specific approaches like 'sudo chmod 666' on the LXD socket -# and 'sudo' with LXD commands. These approaches are NOT recommended for local development. -# For local use, follow the proper group membership approach documented in templates/tofu/lxd/README.md - -set -euo pipefail - -# Check if LXD is already installed -if command -v lxd &> /dev/null; then - echo "LXD is already installed, proceeding with configuration..." -else - sudo snap install lxd -fi - -# Wait for LXD to fully initialize -echo "Waiting for LXD daemon to start..." -sleep 15 - -# Initialize LXD with default settings -sudo lxd init --auto - -# Add runner to lxd group -sudo usermod -a -G lxd runner - -# IMPORTANT: This approach is ONLY for CI environments -# For local development, use proper group membership instead -# Fix socket permissions for CI environment (NOT recommended for local use) -sudo chmod 666 /var/snap/lxd/common/lxd/unix.socket - -# Test basic LXD functionality -sudo lxc list diff --git a/scripts/setup/install-opentofu.sh b/scripts/setup/install-opentofu.sh deleted file mode 100755 index 8a1db1b5..00000000 --- a/scripts/setup/install-opentofu.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# Install OpenTofu (Terraform alternative) - -set -euo pipefail - -# Check if tofu is already installed -if command -v tofu &> /dev/null; then - echo "OpenTofu is already installed, skipping installation" - exit 0 -fi - -# Download and install OpenTofu -curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh -chmod +x install-opentofu.sh -./install-opentofu.sh --install-method deb -rm install-opentofu.sh