Skip to content

feat: implement trait-based container actions architecture #12

feat: implement trait-based container actions architecture

feat: implement trait-based container actions architecture #12

name: E2E Provision Tests
# This workflow tests ONLY infrastructure provisioning (creating VMs/containers)
# It does NOT test software configuration/installation to avoid GitHub Actions
# network connectivity issues with LXD VMs.
#
# 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 templates/tofu/lxd/README.md
#
# NETWORK TUNING: We use smorimoto/tune-github-hosted-runner-network to fix flaky networking
# issues that cause Docker GPG key downloads to fail intermittently in GitHub Actions.
# See: https://github.com/actions/runner-images/issues/1187 and https://github.com/actions/runner-images/issues/2890
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
workflow_dispatch: # Allow manual triggering
jobs:
e2e-provision-tests:
runs-on: ubuntu-latest
timeout-minutes: 30 # Reduced timeout since we're not installing software
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Tune GitHub-hosted runner network
uses: smorimoto/tune-github-hosted-runner-network@v1
- 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: ./scripts/setup/install-lxd-ci.sh
- name: Install OpenTofu
run: ./scripts/setup/install-opentofu.sh
- name: Verify installations
run: |
sudo lxc version
tofu version
cargo --version
- name: Build E2E provision tests binary
run: |
cargo build --bin e2e-provision-tests --release
- name: Run E2E provision test
run: |
# Run the E2E provision test with debug logging for better debugging
# Use sudo -E and preserve PATH to ensure cargo is accessible
echo "🚀 Starting E2E provision test at $(date)"
sudo -E env "PATH=$PATH" cargo run --bin e2e-provision-tests
echo "✅ E2E provision test completed at $(date)"
env:
# Preserve environment variables for the E2E test
RUST_LOG: debug
- name: Get test outputs (on success)
if: success()
working-directory: build/tofu/lxd
run: |
echo "=== Infrastructure Outputs ==="
sudo -E tofu output || echo "No outputs available"
echo "=== Container Status ==="
sudo lxc list torrust-tracker-vm || echo "Container not found"
# Check if the container has an IP address before proceeding
sudo lxc info torrust-tracker-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 build/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: build/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-tracker-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 provision test workflow completed"
if [ "${{ job.status }}" = "success" ]; then
echo "✅ All provision tests passed successfully"
else
echo "❌ Some provision tests failed - check logs above"
fi