feat: add cargo config and update gitignore #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: E2E Tests | |
# NOTE: This workflow 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 config/tofu/lxd/README.md | |
on: | |
push: | |
branches: [main, develop] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: # Allow manual triggering | |
jobs: | |
e2e-tests: | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 # Set reasonable timeout for E2E tests | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
- name: Cache Rust dependencies | |
uses: Swatinem/rust-cache@v2 | |
- name: Install and configure LXD | |
run: | | |
sudo snap install lxd | |
# 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 | |
- name: Install OpenTofu | |
run: | | |
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 | |
- name: Install Ansible | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y ansible | |
- name: Verify installations | |
run: | | |
sudo lxc version | |
tofu version | |
ansible --version | |
cargo --version | |
- name: Build E2E tests binary | |
run: | | |
cargo build --bin e2e-tests --release | |
- name: Run wait-cloud-init E2E test | |
run: | | |
# Run the E2E test with verbose output for better debugging | |
# Use sudo -E and preserve PATH to ensure cargo is accessible | |
sudo -E env "PATH=$PATH" cargo run --bin e2e-tests -- wait-cloud-init --verbose | |
env: | |
# Preserve environment variables for the E2E test | |
RUST_LOG: debug | |
- name: Get test outputs (on success) | |
if: success() | |
working-directory: config/tofu/lxd | |
run: | | |
echo "=== Infrastructure Outputs ===" | |
sudo -E tofu output || echo "No outputs available" | |
echo "=== Container Status ===" | |
sudo lxc list torrust-vm || echo "Container not found" | |
echo "=== Container Info ===" | |
sudo lxc info torrust-vm || echo "Container info not available" | |
- name: Debug information (on failure) | |
if: failure() | |
run: | | |
echo "=== LXD Status ===" | |
sudo lxc list || echo "LXC list failed" | |
echo "=== OpenTofu State ===" | |
cd config/tofu/lxd | |
sudo -E tofu show || echo "No state to show" | |
echo "=== System Resources ===" | |
df -h | |
free -h | |
echo "=== Recent logs ===" | |
sudo journalctl --since "10 minutes ago" --no-pager | tail -50 || echo "Journal logs not available" | |
- name: Cleanup infrastructure (always run) | |
if: always() | |
working-directory: config/tofu/lxd | |
run: | | |
echo "Cleaning up test infrastructure..." | |
# Use sudo for CI environment cleanup | |
# NOTE: For local development, use "sg lxd -c 'tofu destroy'" instead | |
sudo -E tofu destroy -auto-approve || echo "Destroy command failed or nothing to destroy" | |
sudo lxc delete torrust-vm --force || echo "Container deletion failed or container doesn't exist" | |
- name: Final verification | |
if: always() | |
run: | | |
echo "Verifying final cleanup..." | |
sudo lxc list | |
echo "=== Test Summary ===" | |
echo "E2E test workflow completed" | |
if [ "${{ job.status }}" = "success" ]; then | |
echo "✅ All tests passed successfully" | |
else | |
echo "❌ Some tests failed - check logs above" | |
fi |