A lightweight, fault-tolerant Command-Line Interface (CLI) built with modern C++ for automated software deployment and intelligent state rollback.
This tool is designed to act as a reliable state-machine for CI/CD pipelines, ensuring that any deployment failure triggers an immediate and clean rollback to a safe state, minimizing system downtime.
- Automated Deployment Execution: Seamlessly triggers and monitors external deployment scripts or binaries.
- Intelligent Rollback Mechanism: Real-time capturing of process exit codes. Automatically halts and initiates recovery scripts if a non-zero exit status is detected.
- Process Sub-system Monitoring: Built to directly interface with the OS environment using standard C/C++ libraries.
- Extensible Scripting Foundation: Decouples core logic from execution logic via flexible shell scripting (
deploy.sh,rollback.sh).
.
├── CMakeLists.txt # CMake build configuration
├── .github/workflows/ # CI (build + unit tests)
├── include/
│ └── deploy-cli.h # Core headers and definitions
├── scripts/
│ ├── build.sh # Automated compilation script
│ ├── deploy.sh # Mock deployment execution script
│ ├── rollback.sh # Mock system recovery script
│ └── setup_v1.sh # Demo environment bootstrap
├── src/
│ └── main.cpp # CLI entry point and state-machine logic
└── tests/
└── test_main.cpp # doctest unit tests
- A C++17 compatible compiler (GCC, Clang, or MSVC)
- CMake (3.10 or higher)
You can quickly build the project using the provided shell script:
chmod +x scripts/build.sh
./scripts/build.shAlternatively, use standard CMake commands:
mkdir build && cd build
cmake ..
makeRun the CLI tool by specifying the target deployment path:
./deploy-cli --path /var/www/target_appExpected Workflow (Simulated):
- The CLI parses the arguments and invokes
scripts/deploy.sh. - If
deploy.shencounters an error (e.g., exit 1), the CLI intercepts the error. - The CLI immediately triggers
scripts/rollback.shto restore the system state. - Logs are outputted to the standard output/error stream for pipeline monitoring.
deploy-cli distinguishes three outcomes so CI/CD pipelines can react differently to each:
| Code | Meaning |
|---|---|
0 |
Deployment succeeded. No rollback was necessary. |
1 |
Deployment failed, but the automatic rollback succeeded — the system is back to a stable, known-good state. |
2 |
Rollback itself failed (or a crash-recovery rollback failed) — the system is in an unsafe/unknown state and needs manual intervention. |
Unit tests (doctest) cover ConfigParser::parseYaml, ArgumentParser::parseArgs, and
ProcessManager/DeployController — including shell-injection safety (malicious
target_path values), the fork/exec hang-avoidance behavior, and all three exit-code
outcomes above:
./scripts/build.sh
cd build && ctest --output-on-failure- Replace
std::systemwith POSIXpopenfor real-time stdout/stderr streaming. - Implement a persistent logging system to write deployment histories to
.logfiles. - Add JSON configuration parsing for complex deployment workflows.
This project is licensed under the MIT License - see the LICENSE file for details.