Merge branch 'development_nile_installers' of github.com:Incubaid/herolib into development_nile_installers

This commit is contained in:
Timur Gordon
2025-11-17 16:02:44 +01:00
5 changed files with 63 additions and 58 deletions

View File

@@ -4,25 +4,30 @@ import incubaid.herolib.installers.horus.coordinator
// Example usage of coordinator installer // Example usage of coordinator installer
// This will: // This will:
// 1. Check and install Redis if not running (required dependency) // 1. Check if Rust is installed (installs if not present)
// 2. Install Rust if not already installed // 2. Clone the horus repository
// 3. Clone the horus repository // 3. Build the coordinator binary
// 4. Build the coordinator binary //
// Note: Redis must be pre-installed and running before using the coordinator
println('Building coordinator from horus repository...') println('Building coordinator from horus repository...')
println('(This will install Redis and Rust if not already installed)\n') println('(This will install Rust if not already installed)\n')
// Create coordinator instance - will auto-install Redis if needed // Create coordinator instance
mut coord := coordinator.new()! mut coord := coordinator.new()!
// Build and install // Build and install
// Note: This will skip the build if the binary already exists
coord.install()! coord.install()!
// To force a rebuild even if binary exists, use:
// coord.install(reset: true)!
println('\nCoordinator built and installed successfully!') println('\nCoordinator built and installed successfully!')
println('Binary location: ${coord.binary_path}') println('Binary location: ${coord.binary_path}')
// Note: To start the service, uncomment the lines below // Note: To start the service, uncomment the lines below
// (requires proper zinit or screen session setup) // (requires proper zinit or screen session setup and Redis running)
// coord.start()! // coord.start()!
// if coord.running()! { // if coord.running()! {
// println('Coordinator is running!') // println('Coordinator is running!')

View File

@@ -95,46 +95,22 @@ pub fn build_coordinator() ! {
println(' - HTTP port: ${cfg.http_port}') println(' - HTTP port: ${cfg.http_port}')
println(' - WS port: ${cfg.ws_port}\n') println(' - WS port: ${cfg.ws_port}\n')
// Ensure Redis is installed and running (required for coordinator)
println('🔍 Step 1/4: Checking Redis dependency...')
// First check if redis-server is installed
if !osal.cmd_exists_profile('redis-server') {
println(' Redis is not installed')
println('📥 Installing Redis...')
osal.package_install('redis-server')!
println(' Redis installed')
} else {
println(' Redis is already installed')
}
// Now check if it's running
println('🔍 Checking if Redis is running...')
redis_check := osal.exec(cmd: 'redis-cli -c -p 6379 ping', stdout: false, raise_error: false)!
if redis_check.exit_code != 0 {
println(' Redis is not running')
println('🚀 Starting Redis...')
osal.exec(cmd: 'systemctl start redis-server')!
println(' Redis started successfully\n')
} else {
println(' Redis is already running\n')
}
// Ensure rust is installed // Ensure rust is installed
println('🔍 Step 2/4: Checking Rust dependency...') println('Step 1/3: Checking Rust dependency...')
mut rust_installer := rust.get()! if !osal.cmd_exists('rustc') {
res := osal.exec(cmd: 'rustc -V', stdout: false, raise_error: false)! println('Rust not found, installing...')
if res.exit_code != 0 { mut rust_installer := rust.get()!
println('📥 Installing Rust...')
rust_installer.install()! rust_installer.install()!
println(' Rust installed\n') println('Rust installed successfully\n')
} else { } else {
println(' Rust is already installed: ${res.output.trim_space()}\n') res := osal.exec(cmd: 'rustc --version', stdout: false, raise_error: false)!
println('Rust is already installed: ${res.output.trim_space()}\n')
} }
// Clone or get the repository // Clone or get the repository
println('🔍 Step 3/4: Cloning/updating horus repository...') println('Step 2/3: Cloning/updating horus repository...')
mut gs := gittools.new()! // Use the configured repo_path or default coderoot
mut gs := gittools.new(coderoot: '/root/code')!
mut repo := gs.get_repo( mut repo := gs.get_repo(
url: 'https://git.ourworld.tf/herocode/horus.git' url: 'https://git.ourworld.tf/herocode/horus.git'
pull: true pull: true
@@ -146,9 +122,9 @@ pub fn build_coordinator() ! {
println(' Repository ready at: ${cfg.repo_path}\n') println(' Repository ready at: ${cfg.repo_path}\n')
// Build the coordinator binary from the horus workspace // Build the coordinator binary from the horus workspace
println('🔍 Step 4/4: Building coordinator binary...') println('Step 3/3: Building coordinator binary...')
println(' This may take several minutes (compiling Rust code)...') println('WARNING: This may take several minutes (compiling Rust code)...')
println('📝 Running: cargo build -p hero-coordinator --release\n') println('Running: cargo build -p hero-coordinator --release\n')
cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-coordinator --release' cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-coordinator --release'
osal.execute_stdout(cmd)! osal.execute_stdout(cmd)!

View File

@@ -38,7 +38,13 @@ pub fn new(args ArgsGet) !&CoordinatorServer {
log_level: args.log_level log_level: args.log_level
repo_path: args.repo_path repo_path: args.repo_path
} }
set(obj)!
// Try to set in Redis, if it fails (Redis not available), use in-memory config
set(obj) or {
console.print_debug('Redis not available, using in-memory configuration')
set_in_mem(obj)!
}
return get(name: args.name)! return get(name: args.name)!
} }

View File

@@ -15,14 +15,14 @@ A V language installer module for building and managing the Coordinator service.
### Using the Example Script ### Using the Example Script
```bash ```bash
cd /root/code/github/incubaid/herolib/examples/installers/infra cd /root/code/github/incubaid/herolib/examples/installers/horus
./coordinator.vsh ./coordinator.vsh
``` ```
### Manual Usage ### Manual Usage
```v ```v
import incubaid.herolib.installers.infra.coordinator as coordinator_installer import incubaid.herolib.installers.horus.coordinator as coordinator_installer
mut coordinator := coordinator_installer.get()! mut coordinator := coordinator_installer.get()!
coordinator.install()! coordinator.install()!
@@ -36,6 +36,7 @@ coordinator.start()!
name:'default' name:'default'
binary_path:'/hero/var/bin/coordinator' binary_path:'/hero/var/bin/coordinator'
redis_addr:'127.0.0.1:6379' redis_addr:'127.0.0.1:6379'
redis_port:6379
http_port:8081 http_port:8081
ws_port:9653 ws_port:9653
log_level:'info' log_level:'info'
@@ -47,6 +48,7 @@ coordinator.start()!
- **name**: Instance name (default: 'default') - **name**: Instance name (default: 'default')
- **binary_path**: Path where the coordinator binary will be installed (default: '/hero/var/bin/coordinator') - **binary_path**: Path where the coordinator binary will be installed (default: '/hero/var/bin/coordinator')
- **redis_addr**: Redis server address (default: '127.0.0.1:6379') - **redis_addr**: Redis server address (default: '127.0.0.1:6379')
- **redis_port**: Redis server port (default: 6379)
- **http_port**: HTTP API port (default: 8081) - **http_port**: HTTP API port (default: 8081)
- **ws_port**: WebSocket API port (default: 9653) - **ws_port**: WebSocket API port (default: 9653)
- **log_level**: Rust log level - trace, debug, info, warn, error (default: 'info') - **log_level**: Rust log level - trace, debug, info, warn, error (default: 'info')
@@ -56,14 +58,33 @@ coordinator.start()!
### Install ### Install
Builds the coordinator binary from the horus workspace. This will: Builds the coordinator binary from the horus workspace. This will:
1. Install Rust if not present 1. Check if Rust is installed (installs if not present)
2. Clone the horus repository from git.ourworld.tf 2. Clone the horus repository from git.ourworld.tf
3. Build the coordinator binary with `cargo build -p hero-coordinator --release` 3. Build the coordinator binary with `cargo build -p hero-coordinator --release`
**Note**: The installer skips the build if the binary already exists at the configured path.
```bash ```bash
hero coordinator.install hero coordinator.install
``` ```
### Force Reinstall
To force a rebuild even if the binary already exists, use the `reset` flag:
```v
import incubaid.herolib.installers.horus.coordinator as coordinator_installer
mut coordinator := coordinator_installer.get()!
coordinator.install(reset: true)! // Force reinstall
```
Or manually delete the binary before running install:
```bash
rm /hero/var/bin/coordinator
hero coordinator.install
```
### Start ### Start
Starts the coordinator service using zinit: Starts the coordinator service using zinit:
@@ -95,9 +116,9 @@ hero coordinator.destroy
## Requirements ## Requirements
- **Dependencies**: - **Dependencies**:
- Rust toolchain (automatically installed) - Rust toolchain (automatically installed if not present)
- Git (for cloning repository) - Git (for cloning repository)
- Redis (must be running separately) - Redis (must be pre-installed and running)
- Mycelium (must be installed and running separately) - Mycelium (must be installed and running separately)
## Architecture ## Architecture
@@ -111,21 +132,23 @@ The installer follows the standard herolib installer pattern:
## Notes ## Notes
- The installer builds from source rather than downloading pre-built binaries - The installer builds from source rather than downloading pre-built binaries
- Mycelium is expected to be already installed and running in the environment - **Redis must be pre-installed and running** - the installer does not install Redis
- Redis must be running and accessible at the configured address - The installer checks if the binary already exists and skips rebuild unless `reset: true` is used
- Rust is automatically installed if not present (checks for `rustc` command)
- The binary is built with `RUSTFLAGS="-A warnings"` to suppress warnings - The binary is built with `RUSTFLAGS="-A warnings"` to suppress warnings
- Service management uses zinit by default - Service management uses zinit by default
## Example Workflow ## Example Workflow
```v ```v
import incubaid.herolib.installers.infra.coordinator as hc import incubaid.herolib.installers.horus.coordinator as hc
// Get installer instance // Get installer instance
mut coordinator := hc.get()! mut coordinator := hc.get()!
// Customize configuration // Customize configuration
coordinator.redis_addr = '127.0.0.1:6379' coordinator.redis_addr = '127.0.0.1:6379'
coordinator.redis_port = 6379
coordinator.http_port = 8081 coordinator.http_port = 8081
coordinator.log_level = 'debug' coordinator.log_level = 'debug'
hc.set(coordinator)! hc.set(coordinator)!

View File

@@ -1,5 +0,0 @@
name: ${cfg.configpath}