Merge branch 'development_nile_installers' of github.com:Incubaid/herolib into development_nile_installers
This commit is contained in:
@@ -4,25 +4,30 @@ import incubaid.herolib.installers.horus.coordinator
|
||||
|
||||
// Example usage of coordinator installer
|
||||
// This will:
|
||||
// 1. Check and install Redis if not running (required dependency)
|
||||
// 2. Install Rust if not already installed
|
||||
// 3. Clone the horus repository
|
||||
// 4. Build the coordinator binary
|
||||
// 1. Check if Rust is installed (installs if not present)
|
||||
// 2. Clone the horus repository
|
||||
// 3. Build the coordinator binary
|
||||
//
|
||||
// Note: Redis must be pre-installed and running before using the coordinator
|
||||
|
||||
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()!
|
||||
|
||||
// Build and install
|
||||
// Note: This will skip the build if the binary already exists
|
||||
coord.install()!
|
||||
|
||||
// To force a rebuild even if binary exists, use:
|
||||
// coord.install(reset: true)!
|
||||
|
||||
println('\nCoordinator built and installed successfully!')
|
||||
println('Binary location: ${coord.binary_path}')
|
||||
|
||||
// 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()!
|
||||
// if coord.running()! {
|
||||
// println('Coordinator is running!')
|
||||
|
||||
@@ -95,46 +95,22 @@ pub fn build_coordinator() ! {
|
||||
println(' - HTTP port: ${cfg.http_port}')
|
||||
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
|
||||
println('🔍 Step 2/4: Checking Rust dependency...')
|
||||
mut rust_installer := rust.get()!
|
||||
res := osal.exec(cmd: 'rustc -V', stdout: false, raise_error: false)!
|
||||
if res.exit_code != 0 {
|
||||
println('📥 Installing Rust...')
|
||||
println('Step 1/3: Checking Rust dependency...')
|
||||
if !osal.cmd_exists('rustc') {
|
||||
println('Rust not found, installing...')
|
||||
mut rust_installer := rust.get()!
|
||||
rust_installer.install()!
|
||||
println('✅ Rust installed\n')
|
||||
println('Rust installed successfully\n')
|
||||
} 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
|
||||
println('🔍 Step 3/4: Cloning/updating horus repository...')
|
||||
mut gs := gittools.new()!
|
||||
println('Step 2/3: Cloning/updating horus repository...')
|
||||
// Use the configured repo_path or default coderoot
|
||||
mut gs := gittools.new(coderoot: '/root/code')!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://git.ourworld.tf/herocode/horus.git'
|
||||
pull: true
|
||||
@@ -146,9 +122,9 @@ pub fn build_coordinator() ! {
|
||||
println('✅ Repository ready at: ${cfg.repo_path}\n')
|
||||
|
||||
// Build the coordinator binary from the horus workspace
|
||||
println('🔍 Step 4/4: Building coordinator binary...')
|
||||
println('⚠️ This may take several minutes (compiling Rust code)...')
|
||||
println('📝 Running: cargo build -p hero-coordinator --release\n')
|
||||
println('Step 3/3: Building coordinator binary...')
|
||||
println('WARNING: This may take several minutes (compiling Rust code)...')
|
||||
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'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
@@ -38,7 +38,13 @@ pub fn new(args ArgsGet) !&CoordinatorServer {
|
||||
log_level: args.log_level
|
||||
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)!
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ A V language installer module for building and managing the Coordinator service.
|
||||
### Using the Example Script
|
||||
|
||||
```bash
|
||||
cd /root/code/github/incubaid/herolib/examples/installers/infra
|
||||
cd /root/code/github/incubaid/herolib/examples/installers/horus
|
||||
./coordinator.vsh
|
||||
```
|
||||
|
||||
### Manual Usage
|
||||
|
||||
```v
|
||||
import incubaid.herolib.installers.infra.coordinator as coordinator_installer
|
||||
import incubaid.herolib.installers.horus.coordinator as coordinator_installer
|
||||
|
||||
mut coordinator := coordinator_installer.get()!
|
||||
coordinator.install()!
|
||||
@@ -36,6 +36,7 @@ coordinator.start()!
|
||||
name:'default'
|
||||
binary_path:'/hero/var/bin/coordinator'
|
||||
redis_addr:'127.0.0.1:6379'
|
||||
redis_port:6379
|
||||
http_port:8081
|
||||
ws_port:9653
|
||||
log_level:'info'
|
||||
@@ -47,6 +48,7 @@ coordinator.start()!
|
||||
- **name**: Instance name (default: 'default')
|
||||
- **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_port**: Redis server port (default: 6379)
|
||||
- **http_port**: HTTP API port (default: 8081)
|
||||
- **ws_port**: WebSocket API port (default: 9653)
|
||||
- **log_level**: Rust log level - trace, debug, info, warn, error (default: 'info')
|
||||
@@ -56,14 +58,33 @@ coordinator.start()!
|
||||
|
||||
### Install
|
||||
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
|
||||
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
|
||||
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
|
||||
Starts the coordinator service using zinit:
|
||||
|
||||
@@ -95,9 +116,9 @@ hero coordinator.destroy
|
||||
## Requirements
|
||||
|
||||
- **Dependencies**:
|
||||
- Rust toolchain (automatically installed)
|
||||
- Rust toolchain (automatically installed if not present)
|
||||
- Git (for cloning repository)
|
||||
- Redis (must be running separately)
|
||||
- Redis (must be pre-installed and running)
|
||||
- Mycelium (must be installed and running separately)
|
||||
|
||||
## Architecture
|
||||
@@ -111,21 +132,23 @@ The installer follows the standard herolib installer pattern:
|
||||
## Notes
|
||||
|
||||
- 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 running and accessible at the configured address
|
||||
- **Redis must be pre-installed and running** - the installer does not install Redis
|
||||
- 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
|
||||
- Service management uses zinit by default
|
||||
|
||||
## Example Workflow
|
||||
|
||||
```v
|
||||
import incubaid.herolib.installers.infra.coordinator as hc
|
||||
import incubaid.herolib.installers.horus.coordinator as hc
|
||||
|
||||
// Get installer instance
|
||||
mut coordinator := hc.get()!
|
||||
|
||||
// Customize configuration
|
||||
coordinator.redis_addr = '127.0.0.1:6379'
|
||||
coordinator.redis_port = 6379
|
||||
coordinator.http_port = 8081
|
||||
coordinator.log_level = 'debug'
|
||||
hc.set(coordinator)!
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
name: ${cfg.configpath}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user