refactor: Remove Redis installation from coordinator, improve Rust detection
- Remove all Redis installation logic from coordinator installer - Add osal.cmd_exists() check before installing Rust - Update docs: Redis must be pre-installed - Add reset flag documentation for forcing rebuilds - Coordinator now only installs Rust and builds binary
This commit is contained in:
@@ -6,7 +6,6 @@ import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import incubaid.herolib.installers.ulist
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.installers.base.redis
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
@@ -80,30 +79,6 @@ fn upload() ! {
|
||||
// )!
|
||||
}
|
||||
|
||||
// Helper function to ensure Redis is installed and running
|
||||
@[params]
|
||||
struct EnsureRedisArgs {
|
||||
pub mut:
|
||||
redis_port int = 6379
|
||||
redis_addr string = 'localhost'
|
||||
datadir string = '/var/lib/redis'
|
||||
}
|
||||
|
||||
fn ensure_redis_running(args EnsureRedisArgs) ! {
|
||||
redis_config := redis.RedisInstall{
|
||||
port: args.redis_port
|
||||
datadir: args.datadir
|
||||
ipaddr: args.redis_addr
|
||||
}
|
||||
|
||||
if !redis.check(redis_config) {
|
||||
println('Installing and starting Redis on ${args.redis_addr}:${args.redis_port}...')
|
||||
redis.redis_install(redis_config)!
|
||||
} else {
|
||||
println('Redis is already running on ${args.redis_addr}:${args.redis_port}')
|
||||
}
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install coordinator')
|
||||
// For coordinator, we build from source instead of downloading
|
||||
@@ -130,28 +105,20 @@ pub fn build() ! {
|
||||
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...')
|
||||
// Parse redis_addr to extract host
|
||||
parts := cfg.redis_addr.split(':')
|
||||
redis_host := if parts.len > 0 { parts[0] } else { 'localhost' }
|
||||
ensure_redis_running(redis_port: cfg.redis_port, redis_addr: redis_host)!
|
||||
println('Redis is ready\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 {
|
||||
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...')
|
||||
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(
|
||||
@@ -165,7 +132,7 @@ pub fn build() ! {
|
||||
println('Repository ready at: ${cfg.repo_path}\n')
|
||||
|
||||
// Build the coordinator binary from the horus workspace
|
||||
println('Step 4/4: Building coordinator binary...')
|
||||
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')
|
||||
|
||||
|
||||
@@ -39,12 +39,10 @@ pub fn new(args ArgsGet) !&CoordinatorServer {
|
||||
repo_path: args.repo_path
|
||||
}
|
||||
|
||||
// Try to set in Redis, if it fails (Redis not available), build first
|
||||
// Try to set in Redis, if it fails (Redis not available), use in-memory config
|
||||
set(obj) or {
|
||||
console.print_header('Redis not available, installing dependencies first...')
|
||||
build()! // build() now handles both factory and non-factory cases
|
||||
// Now try again with Redis available
|
||||
set(obj)!
|
||||
console.print_debug('Redis not available, using in-memory configuration')
|
||||
set_in_mem(obj)!
|
||||
}
|
||||
|
||||
return get(name: args.name)!
|
||||
|
||||
@@ -58,15 +58,33 @@ coordinator.start()!
|
||||
|
||||
### Install
|
||||
Builds the coordinator binary from the horus workspace. This will:
|
||||
1. Install and start Redis if not present
|
||||
2. Install Rust if not present
|
||||
3. Clone the horus repository from git.ourworld.tf
|
||||
4. Build the coordinator binary with `cargo build -p hero-coordinator --release`
|
||||
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:
|
||||
|
||||
@@ -98,9 +116,9 @@ hero coordinator.destroy
|
||||
## Requirements
|
||||
|
||||
- **Dependencies**:
|
||||
- Rust toolchain (automatically installed)
|
||||
- Rust toolchain (automatically installed if not present)
|
||||
- Git (for cloning repository)
|
||||
- Redis (automatically installed and started)
|
||||
- Redis (must be pre-installed and running)
|
||||
- Mycelium (must be installed and running separately)
|
||||
|
||||
## Architecture
|
||||
@@ -114,8 +132,9 @@ 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 is automatically installed and started if not already running
|
||||
- **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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user