|
| 1 | +# Integration Test Refactor Summary |
| 2 | + |
| 3 | +> **Note**: This document describes interim changes made during the 12-factor refactoring process. |
| 4 | +> It should be removed once the refactoring described in `infrastructure/docs/refactoring/twelve-factor-refactor/` |
| 5 | +> is completed. |
| 6 | +
|
| 7 | +## Overview |
| 8 | + |
| 9 | +This document summarizes the changes made to align the integration testing workflow with the 12-factor |
| 10 | +configuration principles currently being implemented in the Torrust Tracker Demo project. |
| 11 | + |
| 12 | +## Changes Made |
| 13 | + |
| 14 | +### 1. Updated `setup_torrust_tracker` Function (infrastructure/tests/test-integration.sh) |
| 15 | + |
| 16 | +**Previous Approach:** |
| 17 | + |
| 18 | +- Used `rsync` to copy the entire local repository with exclusions |
| 19 | +- Fallback to `.env.production` if `.env` was missing |
| 20 | +- Ad-hoc configuration handling |
| 21 | + |
| 22 | +**New Approach:** |
| 23 | + |
| 24 | +- Uses `git archive` to export only git-tracked files (equivalent to cloning but with current working |
| 25 | + version) |
| 26 | +- Runs `make configure-local` to generate configuration files using the new infrastructure system |
| 27 | +- Executes the official `application/share/bin/install.sh` script locally |
| 28 | +- Copies the properly configured `storage/` folder to the VM |
| 29 | +- Verifies critical configuration files exist on the VM |
| 30 | + |
| 31 | +**Benefits:** |
| 32 | + |
| 33 | +- Tests the exact version being developed (without untracked files) |
| 34 | +- Uses the official installation process instead of custom logic |
| 35 | +- Leverages the new 12-factor configuration system |
| 36 | +- More robust and maintainable |
| 37 | + |
| 38 | +### 2. Updated Installation Script (application/share/bin/install.sh) |
| 39 | + |
| 40 | +**Previous Approach:** |
| 41 | + |
| 42 | +- Created `.env` from `.env.production` if missing |
| 43 | +- Copied configuration files from default templates |
| 44 | + |
| 45 | +**New Approach:** |
| 46 | + |
| 47 | +- Fails if `.env` is not present (12-factor principle) |
| 48 | +- Expects configuration files to be pre-generated by infrastructure system |
| 49 | +- Verifies that required configuration files exist |
| 50 | +- Provides helpful error messages pointing to the infrastructure commands |
| 51 | + |
| 52 | +**Benefits:** |
| 53 | + |
| 54 | +- Follows 12-factor principles strictly |
| 55 | +- No more arbitrary copying of default configurations |
| 56 | +- Clear error messages guide users to the correct configuration process |
| 57 | +- Separation of concerns between infrastructure and application layers |
| 58 | + |
| 59 | +### 3. Updated Documentation |
| 60 | + |
| 61 | +**Changes:** |
| 62 | + |
| 63 | +- Added deprecation notice to `.env.production` file |
| 64 | +- Updated integration testing guide to reflect new workflow |
| 65 | +- Improved documentation of what files are generated by `make configure-local` |
| 66 | + |
| 67 | +## Workflow Changes |
| 68 | + |
| 69 | +### Before (Old Workflow) |
| 70 | + |
| 71 | +```bash |
| 72 | +# Deploy VM |
| 73 | +make apply |
| 74 | + |
| 75 | +# Copy repo with rsync and fallback configs |
| 76 | +setup_torrust_tracker() # Custom logic in test script |
| 77 | + |
| 78 | +# Start services |
| 79 | +docker compose up -d |
| 80 | +``` |
| 81 | + |
| 82 | +### After (New Workflow) |
| 83 | + |
| 84 | +```bash |
| 85 | +# Deploy VM |
| 86 | +make apply |
| 87 | + |
| 88 | +# Generate configuration files locally |
| 89 | +make configure-local |
| 90 | + |
| 91 | +# Use git archive to copy only tracked files |
| 92 | +git archive HEAD | extract to VM |
| 93 | + |
| 94 | +# Run official installation script locally |
| 95 | +./application/share/bin/install.sh |
| 96 | + |
| 97 | +# Copy configured storage folder to VM |
| 98 | +rsync storage/ to VM |
| 99 | + |
| 100 | +# Start services |
| 101 | +docker compose up -d |
| 102 | +``` |
| 103 | + |
| 104 | +## Files Modified |
| 105 | + |
| 106 | +1. **infrastructure/tests/test-integration.sh** |
| 107 | + - Refactored `setup_torrust_tracker` function |
| 108 | + - Improved error handling and logging |
| 109 | + - Added proper configuration verification |
| 110 | + |
| 111 | +2. **application/share/bin/install.sh** |
| 112 | + - Now requires `.env` to be present (12-factor principle) |
| 113 | + - Verifies configuration files exist |
| 114 | + - Provides helpful error messages |
| 115 | + |
| 116 | +3. **application/.env.production** |
| 117 | + - Added deprecation notice |
| 118 | + - Updated documentation to point to new configuration system |
| 119 | + |
| 120 | +4. **docs/guides/integration-testing-guide.md** |
| 121 | + - Updated to reflect new configuration file generation |
| 122 | + |
| 123 | +## Migration Notes |
| 124 | + |
| 125 | +### For Developers |
| 126 | + |
| 127 | +- The integration test now uses the official installation process |
| 128 | +- Configuration files are generated by the infrastructure system |
| 129 | +- The test workflow is more aligned with production deployment |
| 130 | + |
| 131 | +### For Operations |
| 132 | + |
| 133 | +- The installation script now fails fast if configuration is missing |
| 134 | +- Clear error messages guide to the correct configuration commands |
| 135 | +- No more implicit fallbacks to default configurations |
| 136 | + |
| 137 | +## Testing |
| 138 | + |
| 139 | +All changes have been validated with: |
| 140 | + |
| 141 | +- ✅ Shell script linting (ShellCheck) |
| 142 | +- ✅ Markdown linting (markdownlint) |
| 143 | +- ✅ YAML linting (yamllint) |
| 144 | +- ✅ Full linting pipeline passes |
| 145 | + |
| 146 | +## Next Steps |
| 147 | + |
| 148 | +1. Test the updated integration workflow with `make test` |
| 149 | +2. Update any remaining documentation references to `.env.production` |
| 150 | +3. Consider removing `.env.production` once migration is complete |
| 151 | +4. Update production deployment guides to use the new configuration system |
| 152 | + |
| 153 | +## Benefits Achieved |
| 154 | + |
| 155 | +- **Consistency**: Integration tests now use the same configuration approach as production |
| 156 | +- **Maintainability**: Removed custom configuration logic from test scripts |
| 157 | +- **Robustness**: Proper error handling and validation |
| 158 | +- **12-Factor Compliance**: Configuration is externalized and validated |
| 159 | +- **Developer Experience**: Clear error messages and guidance |
| 160 | +- **Testing Fidelity**: Tests exactly what's being developed (git-tracked files only) |
0 commit comments