This repository was archived by the owner on Oct 10, 2025. It is now read-only.
forked from torrust/torrust-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
[#14] Phase 2: Twelve-Factor App Refactoring - Persistent Data Volume Implementation #20
Merged
josecelano
merged 15 commits into
main
from
14-phase-2-12-factor-app-refactoring-part-4
Jul 29, 2025
Merged
[#14] Phase 2: Twelve-Factor App Refactoring - Persistent Data Volume Implementation #20
josecelano
merged 15 commits into
main
from
14-phase-2-12-factor-app-refactoring-part-4
Jul 29, 2025
Conversation
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
…t implementation - Updated twelve-factor refactoring documentation to show Phase 1 is COMPLETE - Changed status from 'IN PROGRESS' to 'PHASE 1 COMPLETE' with all 12 factors implemented - Updated twelve-factor violations table to show full compliance (all ✅) - Added twelve-factor architecture diagram to main README.md in Mermaid format - Added twelve-factor architecture diagram to copilot-instructions.md in ASCII art format - Updated main README.md to use twelve-factor deployment workflow commands - Documented all working configuration management features: - Environment templates (local.env, production.env.tpl) - Configuration processing (configure-env.sh) - Template rendering (.tpl → actual configs) - Multi-environment support - Updated implementation phases to reflect actual completion status - Fixed documentation to accurately represent the production-ready state
…o MyAccessToken in local environment - Ensures consistency with documentation and configuration templates - Resolves API authentication failures in E2E tests - All environment configs now use the standardized MyAccessToken
…tion This commit completes the replacement of 'local-dev-admin-token-12345' with 'MyAccessToken' across all components and improves error reporting for API endpoint failures. Changes: - Replace old token with MyAccessToken in documentation (integration-testing-guide.md, smoke-testing-guide.md) - Replace old token with MyAccessToken in test scripts (test-e2e.sh) - Improve API endpoint error reporting in deploy-app.sh and health-check.sh - Show HTTP status code and response body on API failures - Use proper HTTP status checking and temp file handling - Fix ShellCheck linting issues with variable assignments and comparisons Benefits: - API authentication failures now show actual error details - Consistent token usage across all environments and documentation - Better debugging capabilities for deployment issues - Cleaner code that passes linting validation Testing: - Validated API endpoint works with MyAccessToken - Confirmed error reporting shows detailed failure information - E2E tests now use standardized token consistently
- Renamed infrastructure/config/environments/local.env to local.env.tpl - Updated configure-env.sh to process local.env.tpl template into local.env - Modified .gitignore to exclude generated local.env while keeping template - Updated documentation references in README, copilot-instructions, and guides - Ensures consistent template-based configuration approach for all environments Both local and production environments now use the same .env.tpl -> .env pattern: - local.env.tpl (committed template) -> local.env (generated, git-ignored) - production.env.tpl (template) -> production.env (generated, git-ignored)
- Add comprehensive README to infrastructure/config/environments/ explaining git archive deployment behavior - Add git status check to deployment script that warns about uncommitted changes - Explains why E2E tests might fail when template changes aren't committed - Documents git archive benefits for production safety and reproducibility - Provides troubleshooting guide for configuration deployment issues - Includes best practices for development and production workflows
- Create comprehensive plan for supporting multiple infrastructure providers - Document proposed architecture with provider-specific modules - Include detailed implementation plan with 5-week timeline - Add Hetzner provider implementation examples - Maintain twelve-factor app compliance throughout - Enable easy addition of future providers (AWS, GCP, etc.) - Preserve backward compatibility with existing local workflow This plan enables the repository to support multiple cloud providers while maintaining clean separation between infrastructure provisioning and application deployment as per twelve-factor methodology.
This commit implements a dedicated 20GB persistent data volume that survives VM destruction, ensuring critical application data is preserved across infrastructure changes. ## Infrastructure Changes **Terraform Configuration:** - Add variable (default: 20GB) - Add resource - Attach persistent volume as second disk to VM **Cloud-init Configuration:** - Add disk setup for with GPT partition table - Add ext4 filesystem creation with 'torrust-data' label - Add automatic mount to with noatime option - Add directory structure creation and ownership setup ## Application Changes **Docker Compose Volume Mounts:** - Replace all `./storage/` paths with `/var/lib/torrust/` direct mounts - Remove symlink complexity for cleaner, more explicit configuration - Maintain same container functionality with persistent storage **Deployment Script Updates:** - Replace symlink creation with direct directory structure setup - Update all docker compose commands to use `--env-file /var/lib/torrust/compose/.env` - Add comprehensive persistent storage directory creation - Preserve existing .env files during deployment ## Data Persistence Benefits **What Survives VM Destruction:** - MySQL database (tracker data, user accounts, statistics) - Environment configuration (.env file with passwords/tokens) - Prometheus metrics (historical monitoring data) - Tracker logs and state - SSL certificates (when configured) - All application persistent data **What Gets Refreshed:** - Application code (deployed fresh from git) - System configuration (VM rebuilt from cloud-init) - Docker images (pulled fresh) ## Architecture Improvements **Twelve-Factor Compliance:** - Clean separation between infrastructure (Build) and application (Release/Run) - Configuration persists while code is deployed fresh - Maintains stateless application design with persistent data store **Filesystem Hierarchy Standard:** - Uses `/var/lib/torrust` for application persistent data - Follows Linux FHS conventions for service data storage - Clear separation between transient and persistent data ## Testing - All infrastructure tests pass - Docker Compose syntax validation passes - End-to-end deployment tests successful - Persistent data preservation verified across VM recreations This implementation provides production-ready data persistence while maintaining the clean twelve-factor architecture and deployment workflow.
…EADME Clean up trailing whitespace in documentation to maintain consistent code style and satisfy linting requirements.
- Use consistent 'application' subdirectory in persistent volume - Change from /var/lib/torrust/compose/.env to /var/lib/torrust/application/.env - Update all deployment script references to use new path structure - Update application tests to reflect new persistent volume architecture - Maintain consistency between local (application/.env) and VM paths Benefits: - Consistent directory structure inside and outside VM - Cleaner path organization aligned with project structure - Better maintainability and understanding for developers All tests pass after refactoring.
- Add detailed comment explaining persistent data volume configuration - Clarify that /dev/vdb is the second disk attached for persistent storage - Document specific data types stored: database, config, SSL certs, logs, metrics - Explain data survival across VM destruction and infrastructure recreation - Improve maintainability and understanding of storage architecture This makes the cloud-init configuration self-documenting for the persistent data strategy implemented in the twelve-factor architecture.
- Add missing step to copy generated config files from application/storage/ to /var/lib/torrust/ - Copy tracker.toml, prometheus.yml, and nginx.conf to persistent volume after generation - Fixes container startup issues where services couldn't find configuration files - Ensures all generated configs are available in the persistent volume for Docker mounts - Resolves Prometheus restart loop and nginx 502 errors - Validates persistent data volume implementation with E2E tests Problem: Configuration files were generated in application/storage/ but Docker Compose was mounting from /var/lib/torrust/, causing containers to fail to start. Solution: Added explicit copy step in deploy-app.sh to move generated configs to persistent volume after configure-env.sh runs.
Implements persistent data architecture with standardized directory structure: - Move Docker Compose .env from application/.env to application/storage/compose/.env - Update configure-env.sh to generate .env in persistent storage location - Update deploy-app.sh to use /var/lib/torrust/compose/.env path in VM - Add local configuration generation in deploy-app.sh (twelve-factor Build stage) - Update all Docker Compose commands to use new .env path - Create application/storage/compose/.gitignore to maintain directory structure This ensures all application data (DB, config, SSL, logs, .env) is stored in the persistent volume /var/lib/torrust/ for proper data separation and backup capabilities. Fixes deployment issues where .env file was not found in VM due to improper configuration generation order.
Streamlines the deployment process by directly copying configuration files from local machine to persistent volume, eliminating intermediate storage steps: - Remove complex storage backup/restore logic during repository updates - Eliminate intermediate configuration file copying through VM storage folder - Copy generated config files directly from local to /var/lib/torrust/ via SCP - Simplify repository replacement logic (no storage preservation needed) - Reduce deployment complexity and potential error points Benefits: - 63 lines of code removed (103 removed, 40 added) - Cleaner deployment flow: Local generation → Direct transfer → Service start - Better separation of concerns between repository and persistent data - Fewer file operations and reduced chance of deployment failures - Easier to debug and maintain All E2E tests pass confirming the deployment works correctly with the simplified approach.
Remove legacy scripts replaced by twelve-factor deployment workflow: - application/share/bin/deploy-torrust-tracker-demo.com.sh - application/share/bin/install.sh These scripts have been superseded by the new infrastructure-based deployment process: - Configuration generation: infrastructure/scripts/configure-env.sh - Deployment automation: infrastructure/scripts/deploy-app.sh - Twelve-factor workflow: make infra-apply + make app-deploy Also updated: - application/README.md: Remove references to deleted scripts - application/docs/deployment.md: Document new deployment workflow - application/tests/test-unit-application.sh: Test remaining utility scripts Benefits: - Reduces maintenance burden - Eliminates duplicate/conflicting deployment methods - Simplifies codebase to focus on modern twelve-factor approach - Removes potential confusion between legacy and new workflows
Remove temporary backup files that are no longer needed: - Makefile.backup - Makefile.old These were likely created during development iterations and should not be tracked in version control.
ACK 21df7d8 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Overview
This pull request implements Phase 2 of the twelve-factor app refactoring for the Torrust Tracker Demo, focusing on persistent data volume implementation and deployment script simplification.
Resolves #14
📋 Summary of Changes
🗄️ Persistent Data Volume Implementation
/var/lib/torrust/
volume🚀 Deployment Script Simplification
📁 Configuration Management
🔧 Technical Implementation
Persistent Volume Structure
Deployment Workflow Improvements
Configuration File Management
infrastructure/scripts/configure-env.sh
/var/lib/torrust/*/
locations✅ Testing & Validation
Test Coverage
Validation Results
🔄 Twelve-Factor Compliance Status
This PR fully implements Factors 1-12:
make infra-apply
+make app-deploy
📖 Key Commits
f13b08d
: Implement persistent data volume for VM data persistence2cc9fb8
: Standardize environment file path structureba4d174
: Copy generated configuration files to persistent volume9877fa6
: Move Docker Compose .env to persistent volumed3e9ed5
: Simplify deployment script configuration file handling🚀 Benefits
🔄 Migration Impact
📝 Next Steps
This completes Phase 2 of the twelve-factor refactoring. Future phases will include:
Ready for review and merge into
main
🚀