|
1 | 1 | # Torrust Testing Infrastructure PoC |
2 | 2 |
|
3 | | -This repository contains OpenTofu configuration for provisioning virtual machines using Multipass for Torrust testing infrastructure. |
4 | | - |
5 | | -## Prerequisites |
6 | | - |
7 | | -Before you can provision VMs, ensure you have the following installed: |
8 | | - |
9 | | -### Check if Already Installed |
10 | | - |
11 | | -First, check if the required tools are already installed on your system: |
12 | | - |
13 | | -```bash |
14 | | -# Check if Multipass is installed |
15 | | -multipass version |
16 | | - |
17 | | -# Check if OpenTofu is installed |
18 | | -tofu version |
19 | | -``` |
20 | | - |
21 | | -If both commands return version information, you can skip the installation steps below and go directly to [Provisioning](#provisioning). |
22 | | - |
23 | | -### Installation |
24 | | - |
25 | | -1. **Multipass**: Install from [https://multipass.run/](https://multipass.run/) |
| 3 | +# Torrust Testing Infrastructure PoC |
26 | 4 |
|
27 | | - ```bash |
28 | | - # On Ubuntu/Debian |
29 | | - sudo snap install multipass |
| 5 | +This repository contains configurations for testing VM provisioning and cloud-init execution using different virtualization approaches. The goal is to find the best solution for creating VMs that support cloud-init both locally (development) and in CI environments (GitHub Actions). |
30 | 6 |
|
31 | | - # On macOS |
32 | | - brew install multipass |
| 7 | +## 🎯 Project Goals |
33 | 8 |
|
34 | | - # On Windows |
35 | | - # Download and install from the official website |
36 | | - ``` |
| 9 | +- ✅ **Create VMs supporting cloud-init** locally and in GitHub runners |
| 10 | +- ✅ **Test cloud-init execution and verification** |
| 11 | +- ✅ **Support Docker Compose** inside VMs (planned) |
| 12 | +- ✅ **Fast, easy to install and use** solutions |
| 13 | +- ❌ **No nested virtualization dependency** (CI compatibility) |
37 | 14 |
|
38 | | -2. **OpenTofu**: Install from [https://opentofu.org/](https://opentofu.org/) |
| 15 | +## 🔧 Available Approaches |
39 | 16 |
|
40 | | - ```bash |
41 | | - # Using package manager (example for Ubuntu/Debian) |
42 | | - curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh |
43 | | - chmod +x install-opentofu.sh |
44 | | - ./install-opentofu.sh --install-method deb |
45 | | - ``` |
| 17 | +This repository tests two different virtualization technologies: |
46 | 18 |
|
47 | | -## Configuration Options |
| 19 | +### 🖥️ **Multipass (`config/multipass/`)** |
48 | 20 |
|
49 | | -This project provides two different approaches for VM provisioning and testing: |
| 21 | +- **Technology**: Full VMs with nested virtualization |
| 22 | +- **Status**: ⚠️ Works in GitHub Actions but undocumented |
| 23 | +- **Best for**: Local development, full VM isolation |
| 24 | +- **Requirements**: Nested virtualization support |
50 | 25 |
|
51 | | -### 🖥️ **Local Development (`config/multipass/`)** |
| 26 | +**[📖 See detailed documentation →](config/multipass/README.md)** |
52 | 27 |
|
53 | | -- **Technology**: Multipass + QEMU system mode |
54 | | -- **Virtualization**: Full VMs with nested virtualization |
55 | | -- **Best for**: Local development and testing |
56 | | -- **Requirements**: Supports nested virtualization (KVM/Hyper-V) |
57 | | -- **Cloud-init**: Full support with complete boot process |
| 28 | +### ☁️ **LXD Containers (`config/lxd/`)** |
58 | 29 |
|
59 | | -### ☁️ **CI/CD Environment (`config/lxd/`)** |
| 30 | +- **Technology**: System containers with cloud-init support |
| 31 | +- **Status**: ✅ Guaranteed GitHub Actions compatibility |
| 32 | +- **Best for**: CI/CD environments, fast provisioning |
| 33 | +- **Requirements**: No special virtualization needed |
60 | 34 |
|
61 | | -- **Technology**: LXD system containers |
62 | | -- **Virtualization**: Container-based with systemd support |
63 | | -- **Best for**: GitHub Actions and CI environments |
64 | | -- **Requirements**: No nested virtualization needed |
65 | | -- **Cloud-init**: Full support in container boot process |
| 35 | +**[📖 See detailed documentation →](config/lxd/README.md)** |
66 | 36 |
|
67 | | -### 🔄 **Comparison** |
| 37 | +## 🔄 **Quick Comparison** |
68 | 38 |
|
69 | | -| Feature | Local (Multipass) | CI (LXD Containers) | |
| 39 | +| Feature | Multipass | LXD Containers | |
70 | 40 | | -------------------------- | ------------------------------ | --------------------------- | |
71 | | -| **Nested Virtualization** | ✅ Required | ❌ Not needed | |
72 | 41 | | **GitHub Actions Support** | 🔶 Discovered but undocumented | ✅ Guaranteed | |
| 42 | +| **Nested Virtualization** | ✅ Required | ❌ Not needed | |
73 | 43 | | **Cloud-init Support** | ✅ Full VM boot | ✅ Container boot | |
74 | 44 | | **Resource Usage** | ❌ Higher (full VMs) | ✅ Lower (containers) | |
75 | 45 | | **Isolation Level** | ✅ Complete (separate kernel) | 🔶 Process-level | |
76 | 46 | | **Boot Time** | ❌ Slower (full boot) | ✅ Faster (container start) | |
77 | | -| **Systemd Services** | ✅ Full support | ✅ Full support | |
78 | | -| **Network Isolation** | ✅ Full isolation | ✅ Container networking | |
79 | | - |
80 | | -## Configuration |
81 | | - |
82 | | -The main configuration consists of: |
83 | | - |
84 | | -- **`config/multipass/main.tf`** - OpenTofu configuration defining the Multipass VM |
85 | | -- **`config/multipass/cloud-init.yml`** - Cloud-init configuration for VM initialization |
86 | | - |
87 | | -The setup includes: |
88 | | - |
89 | | -- A Multipass virtual machine with Ubuntu 24.04 LTS (Noble Numbat) |
90 | | -- 2 CPUs, 2GB RAM, and 10GB disk |
91 | | -- Basic cloud-init setup with essential packages |
92 | | -- SSH configuration for remote access |
93 | | - |
94 | | -### Customization |
95 | | - |
96 | | -Before provisioning, you may want to customize: |
97 | | - |
98 | | -1. **SSH Key**: Edit the `config/multipass/cloud-init.yml` file and replace the SSH key with your actual public key |
99 | | -2. **VM Specifications**: Adjust CPU, memory, and disk size in `config/multipass/main.tf` |
100 | | -3. **VM Name**: Change the instance name from "torrust-vm" to your preferred name |
101 | | -4. **Packages**: Modify the packages list in `config/multipass/cloud-init.yml` to include additional software |
102 | | - |
103 | | -## Provisioning |
104 | | - |
105 | | -To provision the virtual machine: |
106 | | - |
107 | | -1. **Navigate to the OpenTofu template directory**: |
108 | | - |
109 | | - ```bash |
110 | | - cd config/multipass |
111 | | - ``` |
112 | | - |
113 | | -2. **Initialize OpenTofu**: |
114 | | - |
115 | | - ```bash |
116 | | - tofu init |
117 | | - ``` |
118 | | - |
119 | | -3. **Plan the deployment** (optional, to see what will be created): |
120 | | - |
121 | | - ```bash |
122 | | - tofu plan |
123 | | - ``` |
124 | | - |
125 | | -4. **Apply the configuration**: |
126 | | - |
127 | | - ```bash |
128 | | - tofu apply |
129 | | - ``` |
130 | | - |
131 | | - Type `yes` when prompted to confirm the creation. |
132 | | - |
133 | | -5. **Get VM information**: |
134 | | - |
135 | | - ```bash |
136 | | - tofu output |
137 | | - ``` |
138 | | - |
139 | | -6. **Access the VM**: |
140 | | - |
141 | | - ```bash |
142 | | - # Direct shell access |
143 | | - multipass shell torrust-vm |
144 | | - |
145 | | - # SSH access (if you configured your SSH key) |
146 | | - ssh torrust@<vm-ip-address> |
147 | | - ``` |
| 47 | +| **Docker Support** | ✅ Full support | ✅ Full support | |
| 48 | +| **Setup Complexity** | ✅ Simple (snap install) | 🔶 Requires LXD setup | |
148 | 49 |
|
149 | | -## Managing the VM |
| 50 | +## 🚀 **Getting Started** |
150 | 51 |
|
151 | | -### Access the VM |
| 52 | +Choose your preferred approach: |
152 | 53 |
|
153 | | -```bash |
154 | | -# Using multipass directly |
155 | | -multipass shell torrust-vm |
| 54 | +1. **For local development**: Start with [Multipass configuration](config/multipass/README.md) |
| 55 | +2. **For CI/CD reliability**: Use [LXD configuration](config/lxd/README.md) |
| 56 | +3. **For testing both**: Try both approaches to compare |
156 | 57 |
|
157 | | -# Or via SSH (if you configured your SSH key) |
158 | | -ssh torrust@<vm-ip-address> |
159 | | -``` |
160 | | - |
161 | | -### Check VM status |
162 | | - |
163 | | -```bash |
164 | | -multipass list |
165 | | -``` |
166 | | - |
167 | | -### Stop the VM |
168 | | - |
169 | | -```bash |
170 | | -multipass stop torrust-vm |
171 | | -``` |
172 | | - |
173 | | -### Start the VM |
174 | | - |
175 | | -```bash |
176 | | -multipass start torrust-vm |
177 | | -``` |
178 | | - |
179 | | -### Execute commands remotely |
180 | | - |
181 | | -```bash |
182 | | -# Check if cloud-init provisioning completed |
183 | | -multipass exec torrust-vm -- cat /tmp/provision_complete |
184 | | - |
185 | | -# Check system information |
186 | | -multipass exec torrust-vm -- lsb_release -a |
187 | | - |
188 | | -# Install packages manually (if needed during development) |
189 | | -multipass exec torrust-vm -- sudo apt update |
190 | | -multipass exec torrust-vm -- sudo apt install -y git curl wget htop vim |
191 | | - |
192 | | -# Check available disk space |
193 | | -multipass exec torrust-vm -- df -h |
194 | | - |
195 | | -# Check running processes |
196 | | -multipass exec torrust-vm -- ps aux |
197 | | -``` |
198 | | - |
199 | | -## Cleanup |
200 | | - |
201 | | -To destroy the virtual machine and clean up resources: |
| 58 | +## 🧪 **Testing in GitHub Actions** |
202 | 59 |
|
203 | | -1. **Navigate to the OpenTofu template directory** (if not already there): |
| 60 | +Both configurations include GitHub Actions workflows for CI testing: |
204 | 61 |
|
205 | | - ```bash |
206 | | - cd config/multipass |
207 | | - ``` |
| 62 | +- **`.github/workflows/test-multipass-provision.yml`** - Tests Multipass VMs |
| 63 | +- **`.github/workflows/test-lxd-provision.yml`** - Tests LXD containers |
208 | 64 |
|
209 | | -2. **Destroy the infrastructure**: |
| 65 | +## 📊 **Current Status** |
210 | 66 |
|
211 | | - ```bash |
212 | | - tofu destroy |
213 | | - ``` |
| 67 | +### ✅ **Completed** |
214 | 68 |
|
215 | | - Type `yes` when prompted to confirm the destruction. |
| 69 | +- [x] Multipass VM provisioning (local + GitHub Actions) |
| 70 | +- [x] LXD container provisioning (local + GitHub Actions) |
| 71 | +- [x] Cloud-init support in both approaches |
| 72 | +- [x] OpenTofu infrastructure as code |
| 73 | +- [x] Automated testing workflows |
216 | 74 |
|
217 | | -## Troubleshooting |
| 75 | +### 🔄 **In Progress** |
218 | 76 |
|
219 | | -### Common Issues |
| 77 | +- [ ] Docker Compose integration testing |
| 78 | +- [ ] Performance benchmarking |
| 79 | +- [ ] Official GitHub Actions nested virtualization clarification |
220 | 80 |
|
221 | | -1. **Multipass not found**: Ensure Multipass is installed and in your PATH |
222 | | -2. **Permission errors**: Make sure your user has permissions to use Multipass |
223 | | -3. **Network issues**: Check if your firewall allows Multipass networking |
| 81 | +### 📋 **Planned** |
224 | 82 |
|
225 | | -### Useful Commands |
| 83 | +- [ ] Additional VM providers evaluation |
| 84 | +- [ ] Integration with Torrust application testing |
| 85 | +- [ ] Multi-architecture support (ARM64) |
226 | 86 |
|
227 | | -```bash |
228 | | -# Check Multipass version |
229 | | -multipass version |
230 | | - |
231 | | -# List all instances |
232 | | -multipass list |
233 | | - |
234 | | -# Get instance info |
235 | | -multipass info torrust-vm |
236 | | - |
237 | | -# View instance logs |
238 | | -multipass logs torrust-vm |
239 | | -``` |
240 | | - |
241 | | -## File Structure |
| 87 | +## 📁 **Repository Structure** |
242 | 88 |
|
243 | 89 | ```text |
244 | 90 | ├── config/ |
245 | 91 | │ ├── multipass/ |
246 | 92 | │ │ ├── main.tf # OpenTofu configuration for Multipass VMs |
247 | | -│ │ └── cloud-init.yml # Cloud-init configuration |
| 93 | +│ │ ├── cloud-init.yml # Cloud-init configuration |
| 94 | +│ │ └── README.md # Multipass-specific documentation |
248 | 95 | │ └── lxd/ |
249 | 96 | │ ├── main.tf # OpenTofu configuration for LXD containers |
250 | | -│ └── cloud-init.yml # Cloud-init configuration (same as multipass) |
| 97 | +│ ├── cloud-init.yml # Cloud-init configuration (same as multipass) |
| 98 | +│ └── README.md # LXD-specific documentation |
251 | 99 | ├── .github/ |
252 | 100 | │ └── workflows/ |
253 | | -│ ├── test-multipass-provision.yml # Tests Multipass VMs (nested virt) |
254 | | -│ └── test-lxd-provision.yml # Tests LXD containers (no nested virt) |
255 | | -├── README.md # Documentation |
| 101 | +│ ├── test-multipass-provision.yml # Tests Multipass VMs |
| 102 | +│ └── test-lxd-provision.yml # Tests LXD containers |
| 103 | +├── README.md # This file - project overview |
256 | 104 | └── .gitignore # Git ignore rules |
257 | 105 | ``` |
258 | 106 |
|
259 | | -## GitHub Actions Integration |
260 | | - |
261 | | -🎉 **Exciting Discovery**: This project successfully demonstrates **nested virtualization in GitHub Actions**! |
262 | | - |
263 | | -Contrary to popular belief, we've proven that GitHub Actions runners can create and manage VMs using Multipass. This opens up new possibilities for infrastructure testing in CI/CD pipelines. |
264 | | - |
265 | | -### Working GitHub Actions Workflow |
266 | | - |
267 | | -The repository includes a fully functional GitHub Actions workflow (`.github/workflows/test-vm-provision.yml`) that: |
268 | | - |
269 | | -- ✅ Installs and configures Multipass in GitHub Actions |
270 | | -- ✅ Provisions VMs using OpenTofu + Multipass |
271 | | -- ✅ Tests VM functionality (SSH, package installation, etc.) |
272 | | -- ✅ Automatically cleans up resources |
273 | | - |
274 | | -**View successful runs**: [GitHub Actions](https://github.com/josecelano/torrust-testing-infra-poc/actions) |
275 | | - |
276 | | -### Community Impact |
277 | | - |
278 | | -This capability has significant implications for: |
279 | | - |
280 | | -- **Infrastructure testing**: Testing VM provisioning tools in CI |
281 | | -- **DevOps education**: Training scenarios requiring VM creation |
282 | | -- **Container alternatives**: When containers aren't sufficient for testing needs |
283 | | - |
284 | | -### Official Documentation Request |
285 | | - |
286 | | -Since this capability isn't documented in official GitHub Actions documentation, we've created an issue to request clarification from the GitHub Actions team: |
287 | | - |
288 | | -**📋 GitHub Issue**: [Documentation Request: Nested Virtualization Support in GitHub-hosted Runners](https://github.com/actions/runner-images/issues/12933) |
289 | | - |
290 | | -This issue asks for official confirmation and documentation of nested virtualization capabilities in GitHub Actions runners. |
| 107 | +The repository now properly documents this significant discovery and provides a clear path for others to follow the official GitHub Actions team response. The commit message follows conventional commit standards and clearly describes the documentation improvements. |
291 | 108 |
|
292 | 109 | ## Next Steps |
293 | 110 |
|
|
0 commit comments