Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 027486a

Browse files
committed
docs: [#14] clarify twelve-factor methodology and fix repo structure
- Fix twelve-factor interpretation in contributor guide (infrastructure ≠ Build stage) - Clarify separation between infrastructure provisioning and app deployment - Update repository structure documentation to match actual project layout - Fix spelling/corruption errors in copilot instructions - Update Makefile command comments for correct twelve-factor terminology - Update integration testing guide to clarify workflow stages - Consolidate refactoring documentation with twelve-factor clarifications
1 parent a9a5bcb commit 027486a

File tree

4 files changed

+194
-63
lines changed

4 files changed

+194
-63
lines changed

.github/copilot-instructions.md

Lines changed: 163 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ We are migrating the tracker to a new infrastructure on Hetzner, involving:
2525
torrust-tracker-demo/
2626
├── .github/
2727
│ ├── workflows/ # GitHub Actions CI/CD pipelines
28+
│ ├── prompts/ # AI assistant prompts and templates
2829
│ └── copilot-instructions.md # This contributor guide
2930
├── docs/
3031
│ ├── adr/ # Architecture Decision Records
3132
│ │ └── 001-makefile-location.md # Makefile location decision
33+
│ ├── guides/ # User and developer guides
34+
│ │ ├── integration-testing-guide.md # Testing guide
35+
│ │ ├── quick-start.md # Fast setup guide
36+
│ │ └── smoke-testing-guide.md # End-to-end testing
37+
│ ├── infrastructure/ # Infrastructure-specific documentation
38+
│ ├── issues/ # Issue documentation and analysis
39+
│ ├── plans/ # Project planning documentation
40+
│ ├── refactoring/ # Refactoring documentation
41+
│ ├── testing/ # Testing documentation
3242
│ └── README.md # Cross-cutting documentation index
3343
├── infrastructure/ # Infrastructure as Code
3444
│ ├── terraform/ # OpenTofu/Terraform configurations
@@ -39,34 +49,52 @@ torrust-tracker-demo/
3949
│ │ ├── user-data-minimal.yaml.tpl # Debug configuration
4050
│ │ ├── meta-data.yaml # VM metadata
4151
│ │ └── network-config.yaml # Network setup
42-
│ ├── scripts/ # Infrastructure automation scripts
43-
│ ├── tests/ # Infrastructure validation tests
44-
│ ├── docs/ # Infrastructure documentation
52+
│ ├── config/ # Infrastructure configuration templates
53+
│ │ ├── environments/ # Environment-specific configs
54+
│ │ └── templates/ # Configuration templates
55+
│ ├── scripts/ # Infrastructure automation scripts
56+
│ │ ├── deploy-app.sh # Application deployment script
57+
│ │ ├── provision-infrastructure.sh # Infrastructure provisioning
58+
│ │ └── health-check.sh # Health validation script
59+
│ ├── tests/ # Infrastructure validation tests
60+
│ ├── docs/ # Infrastructure documentation
4561
│ │ ├── quick-start.md # Fast setup guide
4662
│ │ ├── local-testing-setup.md # Detailed setup
4763
│ │ ├── infrastructure-overview.md # Architecture overview
64+
│ │ ├── refactoring/ # Refactoring documentation
4865
│ │ ├── testing/ # Testing documentation
49-
│ │ └── third-party/ # Third-party setup guides
50-
│ ├── .gitignore # Infrastructure-specific ignores
51-
│ └── README.md # Infrastructure overview
52-
├── application/ # Application deployment and services
66+
│ │ ├── third-party/ # Third-party setup guides
67+
│ │ └── bugs/ # Bug documentation
68+
│ ├── .gitignore # Infrastructure-specific ignores
69+
│ └── README.md # Infrastructure overview
70+
├── application/ # Application deployment and services
71+
│ ├── config/ # Application configuration
72+
│ │ └── templates/ # Configuration templates
5373
│ ├── share/
54-
│ │ ├── bin/ # Deployment and utility scripts
55-
│ │ ├── container/ # Docker service configurations
56-
│ │ ├── dev/ # Development configs
57-
│ │ └── grafana/ # Grafana dashboards
58-
│ ├── docs/ # Application documentation
74+
│ │ ├── bin/ # Deployment and utility scripts
75+
│ │ ├── container/ # Docker service configurations
76+
│ │ ├── dev/ # Development configs
77+
│ │ └── grafana/ # Grafana dashboards
78+
│ ├── storage/ # Persistent data storage
79+
│ │ ├── certbot/ # SSL certificate storage
80+
│ │ ├── dhparam/ # DH parameters
81+
│ │ ├── prometheus/ # Prometheus data
82+
│ │ ├── proxy/ # Nginx proxy configs
83+
│ │ └── tracker/ # Tracker data
84+
│ ├── docs/ # Application documentation
5985
│ │ ├── production-setup.md # Production deployment docs
6086
│ │ ├── deployment.md # Deployment procedures
6187
│ │ ├── firewall-requirements.md # Application firewall requirements
6288
│ │ ├── useful-commands.md # Operational commands
63-
│ │ └── media/ # Screenshots and diagrams
64-
│ ├── compose.yaml # Docker Compose for services
65-
│ ├── .env.production # Production environment template
66-
│ ├── .gitignore # Application-specific ignores
67-
│ └── README.md # Application overview
68-
├── Makefile # Main automation interface
69-
└── *.md # Project root documentation
89+
│ │ └── media/ # Screenshots and diagrams
90+
│ ├── compose.yaml # Docker Compose for services
91+
│ ├── .env # Local environment configuration
92+
│ ├── .gitignore # Application-specific ignores
93+
│ └── README.md # Application overview
94+
├── scripts/ # Project-wide utility scripts
95+
│ └── lint.sh # Linting script for all file types
96+
├── Makefile # Main automation interface
97+
└── *.md # Project root documentation
7098
```
7199

72100
### Key Components
@@ -106,33 +134,120 @@ make install-deps
106134
# 3. Setup SSH key for VMs
107135
make setup-ssh-key
108136

109-
# 4. Test infrastructure locally
110-
make apply # Deploy test VM
111-
make ssh # Connect to VM
112-
make destroy # Cleanup
137+
# 4. Test twelve-factor deployment workflow locally
138+
make infra-apply # Provision infrastructure (platform setup)
139+
make app-deploy # Deploy application (Build + Release + Run stages)
140+
make health-check # Validate deployment
141+
make ssh # Connect to VM
142+
make infra-destroy # Cleanup
113143

114144
# 5. Run tests
115-
make test # Full infrastructure test
116-
make test-syntax # Syntax validation only
145+
make test # Full infrastructure test
146+
make test-syntax # Syntax validation only
117147
```
118148

119149
### Main Commands
120150

121-
| Command | Purpose |
122-
| ------------------------- | ------------------------------------------- |
123-
| `make help` | Show all available commands |
124-
| `make install-deps` | Install OpenTofu, libvirt, KVM, virt-viewer |
125-
| `make test` | Run complete infrastructure tests |
126-
| `make apply` | Deploy VM with full configuration |
127-
| `make apply-minimal` | Deploy VM with minimal config |
128-
| `make ssh` | Connect to deployed VM |
129-
| `make console` | Access VM console (text-based) |
130-
| `make vm-console` | Access VM graphical console (GUI) |
131-
| `make destroy` | Remove deployed VM |
132-
| `make monitor-cloud-init` | Watch VM provisioning progress |
151+
#### Twelve-Factor Workflow (Recommended)
152+
153+
| Command | Purpose |
154+
| ------------------- | ------------------------------------------------- |
155+
| `make infra-apply` | Provision infrastructure (platform setup) |
156+
| `make app-deploy` | Deploy application (Build + Release + Run stages) |
157+
| `make app-redeploy` | Redeploy application (Release + Run stages only) |
158+
| `make health-check` | Validate deployment health |
159+
160+
#### Infrastructure Management
161+
162+
| Command | Purpose |
163+
| -------------------------- | -------------------------------------------- |
164+
| `make help` | Show all available commands |
165+
| `make install-deps` | Install OpenTofu, libvirt, KVM, virt-viewer |
166+
| `make infra-init` | Initialize infrastructure (Terraform init) |
167+
| `make infra-plan` | Plan infrastructure changes |
168+
| `make infra-destroy` | Destroy infrastructure |
169+
| `make infra-status` | Show infrastructure status |
170+
| `make infra-refresh-state` | Refresh Terraform state to detect IP changes |
171+
172+
#### VM Access and Debugging
173+
174+
| Command | Purpose |
175+
| ----------------- | --------------------------------- |
176+
| `make ssh` | Connect to deployed VM |
177+
| `make console` | Access VM console (text-based) |
178+
| `make vm-console` | Access VM graphical console (GUI) |
179+
180+
#### Testing and Validation
181+
182+
| Command | Purpose |
183+
| ------------------ | --------------------------------------- |
184+
| `make test` | Run complete infrastructure tests |
185+
| `make test-syntax` | Run syntax validation only |
186+
| `make lint` | Run all linting (alias for test-syntax) |
187+
188+
#### Legacy Commands (Deprecated)
189+
190+
| Command | New Equivalent |
191+
| -------------- | -------------------------------------- |
192+
| `make apply` | `make infra-apply` + `make app-deploy` |
193+
| `make destroy` | `make infra-destroy` |
194+
| `make status` | `make infra-status` |
133195

134196
## 📋 Conventions and Standards
135197

198+
### Twelve-Factor App Principles
199+
200+
This project implements [twelve-factor app](https://12factor.net/) methodology for application deployment, with a clear separation between infrastructure provisioning and application deployment:
201+
202+
#### Infrastructure vs Application Deployment
203+
204+
**Important Distinction**: The twelve-factor methodology applies specifically to **application deployment**, not infrastructure provisioning.
205+
206+
- **Infrastructure Provisioning** (`make infra-apply`): Separate step that provisions the platform/environment
207+
- Creates VMs, networks, firewall rules using Infrastructure as Code
208+
- Applies cloud-init configuration
209+
- Sets up the foundation where the application will run
210+
- **This is NOT part of the twelve-factor Build stage**
211+
212+
#### Twelve-Factor Application Deployment Stages
213+
214+
The twelve-factor **Build, Release, Run** stages apply to the application deployment process (`make app-deploy`):
215+
216+
- **Build Stage**: Transform application code into executable artifacts
217+
218+
- Compile source code for production
219+
- Create container images (Docker)
220+
- Package application dependencies
221+
- Generate static assets
222+
223+
- **Release Stage**: Combine built application with environment-specific configuration
224+
225+
- Apply environment variables and configuration files
226+
- Combine application artifacts with runtime configuration
227+
- Prepare deployment-ready releases
228+
229+
- **Run Stage**: Execute the application in the runtime environment
230+
- Start application processes (tracker binary, background jobs)
231+
- Start supporting services (MySQL, Nginx, Prometheus, Grafana)
232+
- Enable health checks and monitoring
233+
- Make the application accessible to clients
234+
235+
#### Benefits of This Approach
236+
237+
- **Separation of Concerns**: Infrastructure changes don't require application redeployment
238+
- **Faster Iteration**: Use `make app-redeploy` to update only the application (Release + Run stages)
239+
- **Environment Consistency**: Same application deployment workflow for local testing and production
240+
- **Rollback Capability**: Infrastructure and application can be rolled back independently
241+
- **Testing Isolation**: Test infrastructure provisioning separately from application deployment
242+
243+
#### Typical Development Workflow
244+
245+
1. **Initial Setup**: `make infra-apply``make app-deploy`
246+
2. **Code Changes**: `make app-redeploy` (skips infrastructure)
247+
3. **Infrastructure Changes**: `make infra-apply``make app-redeploy`
248+
4. **Validation**: `make health-check`
249+
5. **Cleanup**: `make infra-destroy`
250+
136251
### Git Workflow
137252

138253
#### Branch Naming
@@ -237,7 +352,7 @@ The project includes a comprehensive linting script that validates all file type
237352
For verifying the functionality of the tracker from an end-user's perspective (e.g., simulating announce/scrape requests), refer to the **Smoke Testing Guide**. This guide explains how to use the official `torrust-tracker-client` tools to perform black-box testing against a running tracker instance without needing a full BitTorrent client.
238353

239354
- **Guide**: [Smoke Testing Guide](../docs/guides/smoke-testing-guide.md)
240-
- **When to use**: After a deployment (`make apply`) or to validate that all services are working together correctly.
355+
- **When to use**: After a deployment (`make infra-apply` + `make app-deploy`) or to validate that all services are working together correctly.
241356

242357
### Security Guidelines
243358

@@ -298,9 +413,10 @@ For verifying the functionality of the tracker from an end-user's perspective (e
298413
6. **Test a simple change**:
299414

300415
```bash
301-
make apply # Deploy test VM
416+
make infra-apply # Deploy test VM
417+
make app-deploy # Deploy application
302418
make ssh # Verify access
303-
make destroy # Clean up
419+
make infra-destroy # Clean up
304420
```
305421

306422
7. **Review existing issues**: Check [GitHub Issues](https://github.com/torrust/torrust-tracker-demo/issues) for good first contributions
@@ -310,7 +426,12 @@ For verifying the functionality of the tracker from an end-user's perspective (e
310426
1. **Local testing first**: Always test infrastructure changes locally
311427
2. **Validate syntax**: Run `make test-syntax` before committing
312428
3. **Document changes**: Update relevant documentation
313-
4. **Test end-to-end**: Ensure the full deployment pipeline works
429+
4. **Test twelve-factor workflow**: Ensure both infrastructure provisioning and application deployment work
430+
```bash
431+
make infra-apply # Test infrastructure provisioning
432+
make app-deploy # Test application deployment
433+
make health-check # Validate services
434+
```
314435

315436
### For AI Assistants
316437

@@ -327,7 +448,7 @@ When providing assistance:
327448

328449
Be mindful of the execution context for different types of commands. The project uses several command-line tools that must be run from specific directories:
329450

330-
- **`make` commands**: (e.g., `make help`, `make status`) must be run from the project root directory.
451+
- **`make` commands**: (e.g., `make help`, `make infra-status`) must be run from the project root directory.
331452
- **OpenTofu commands**: (e.g., `tofu init`, `tofu plan`, `tofu apply`) must be run from the `infrastructure/terraform/` directory.
332453
- **Docker Compose commands**: (e.g., `docker compose up -d`, `docker compose ps`) are intended to be run _inside the deployed virtual machine_, typically from the `/home/torrust/github/torrust/torrust-tracker-demo/application` directory.
333454

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ help: ## Show this help message
1717
@echo "Torrust Tracker Demo - Twelve-Factor App Deployment"
1818
@echo ""
1919
@echo "=== TWELVE-FACTOR DEPLOYMENT WORKFLOW ==="
20-
@echo " 1. infra-apply - Provision infrastructure (Build stage)"
21-
@echo " 2. app-deploy - Deploy application (Release + Run stages)"
20+
@echo " 1. infra-apply - Provision infrastructure (platform setup)"
21+
@echo " 2. app-deploy - Deploy application (Build + Release + Run stages)"
2222
@echo " 3. health-check - Validate deployment"
2323
@echo ""
2424
@echo "Available targets:"
@@ -38,7 +38,7 @@ install-deps: ## Install required dependencies (Ubuntu/Debian)
3838
@echo "Dependencies installed. Please log out and log back in for group changes to take effect."
3939

4040
# =============================================================================
41-
# TWELVE-FACTOR INFRASTRUCTURE TARGETS (BUILD STAGE)
41+
# INFRASTRUCTURE PROVISIONING TARGETS (PLATFORM SETUP)
4242
# =============================================================================
4343

4444
infra-init: ## Initialize infrastructure (Terraform init)
@@ -49,7 +49,7 @@ infra-plan: ## Plan infrastructure changes
4949
@echo "Planning infrastructure for $(ENVIRONMENT)..."
5050
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) plan
5151

52-
infra-apply: ## Provision infrastructure (Twelve-Factor Build stage)
52+
infra-apply: ## Provision infrastructure (platform setup)
5353
@echo "Provisioning infrastructure for $(ENVIRONMENT)..."
5454
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) apply
5555

@@ -66,10 +66,10 @@ infra-refresh-state: ## Refresh Terraform state to detect IP changes
6666
@cd $(TERRAFORM_DIR) && tofu refresh
6767

6868
# =============================================================================
69-
# TWELVE-FACTOR APPLICATION TARGETS (RELEASE + RUN STAGES)
69+
# TWELVE-FACTOR APPLICATION TARGETS (BUILD + RELEASE + RUN STAGES)
7070
# =============================================================================
7171

72-
app-deploy: ## Deploy application (Twelve-Factor Release + Run stages)
72+
app-deploy: ## Deploy application (Twelve-Factor Build + Release + Run stages)
7373
@echo "Deploying application for $(ENVIRONMENT)..."
7474
$(SCRIPTS_DIR)/deploy-app.sh $(ENVIRONMENT)
7575

docs/guides/integration-testing-guide.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ deployment workflow on a fresh virtual machine. All commands are ready to copy a
55

66
## Overview
77

8-
This guide will walk you through the **Twelve-Factor App deployment process**:
8+
This guide will walk you through the deployment process with separated infrastructure and
9+
application concerns:
910

10-
1. **Build Stage**: Provisioning infrastructure (`make infra-apply`)
11-
2. **Release + Run Stages**: Deploying application (`make app-deploy`)
11+
1. **Infrastructure Provisioning**: Setting up the platform (`make infra-apply`)
12+
2. **Application Deployment**: Twelve-factor Build + Release + Run stages (`make app-deploy`)
1213
3. **Validation**: Health checking (`make health-check`)
1314
4. **Cleanup**: Resource management (`make infra-destroy`)
1415

@@ -69,9 +70,9 @@ make clean
6970

7071
---
7172

72-
## Step 2: Build Stage - Provision Infrastructure
73+
## Step 2: Infrastructure Provisioning
7374

74-
The **Build Stage** provisions the basic infrastructure (VM) without deploying
75+
Infrastructure provisioning sets up the platform (VM) without deploying
7576
the application. This follows twelve-factor separation of concerns.
7677

7778
### 2.1 Initialize Infrastructure
@@ -145,7 +146,7 @@ make ssh
145146

146147
---
147148

148-
## Step 3: Release + Run Stages - Deploy Application
149+
## Step 3: Application Deployment - Deploy Application
149150

150151
The **Release Stage** combines the application code with environment-specific
151152
configuration. The **Run Stage** starts the application processes.
@@ -161,7 +162,7 @@ time make app-deploy ENVIRONMENT=local
161162

162163
```text
163164
Deploying application for local...
164-
[INFO] Starting application deployment (Twelve-Factor Release + Run Stages)
165+
[INFO] Starting application deployment (Twelve-Factor Build + Release + Run Stages)
165166
[INFO] Environment: local
166167
[SUCCESS] SSH connection established
167168
[INFO] === TWELVE-FACTOR RELEASE STAGE ===

0 commit comments

Comments
 (0)