refactor: integrate worker-runner generation into install/update flow

update configure services to call generate_n8n_workers.sh instead of
prompting for separate runner count. update start_services.py and
apply_update.sh to include docker-compose.n8n-workers.yml when present.
This commit is contained in:
Yury Kossakovsky
2025-12-09 17:34:12 -07:00
parent d54eca620c
commit 98f2dd807e
3 changed files with 25 additions and 58 deletions

View File

@@ -126,62 +126,10 @@ N8N_WORKER_COUNT="${N8N_WORKER_COUNT:-1}"
# Persist N8N_WORKER_COUNT to .env
write_env_var "N8N_WORKER_COUNT" "$N8N_WORKER_COUNT"
# ----------------------------------------------------------------
# Prompt for number of n8n runners (for Code/Python node execution)
# ----------------------------------------------------------------
echo "" # Add a newline for better formatting
log_info "Configuring n8n runner count..."
EXISTING_N8N_RUNNER_COUNT="$(read_env_var N8N_RUNNER_COUNT)"
require_whiptail
if [[ -n "$EXISTING_N8N_RUNNER_COUNT" ]]; then
N8N_RUNNER_COUNT_CURRENT="$EXISTING_N8N_RUNNER_COUNT"
N8N_RUNNER_COUNT_INPUT_RAW=$(wt_input "n8n Runners (instances)" "Enter new number of n8n runners, or leave as current ($N8N_RUNNER_COUNT_CURRENT)." "") || true
if [[ -z "$N8N_RUNNER_COUNT_INPUT_RAW" ]]; then
N8N_RUNNER_COUNT="$N8N_RUNNER_COUNT_CURRENT"
else
if [[ "$N8N_RUNNER_COUNT_INPUT_RAW" =~ ^0*[1-9][0-9]*$ ]]; then
N8N_RUNNER_COUNT_TEMP="$((10#$N8N_RUNNER_COUNT_INPUT_RAW))"
if [[ "$N8N_RUNNER_COUNT_TEMP" -ge 1 ]]; then
if wt_yesno "Confirm Runners" "Update n8n runners to $N8N_RUNNER_COUNT_TEMP?" "yes"; then
N8N_RUNNER_COUNT="$N8N_RUNNER_COUNT_TEMP"
else
N8N_RUNNER_COUNT="$N8N_RUNNER_COUNT_CURRENT"
log_info "Change declined. Keeping N8N_RUNNER_COUNT at $N8N_RUNNER_COUNT."
fi
else
log_warning "Invalid input '$N8N_RUNNER_COUNT_INPUT_RAW'. Number must be positive. Keeping $N8N_RUNNER_COUNT_CURRENT."
N8N_RUNNER_COUNT="$N8N_RUNNER_COUNT_CURRENT"
fi
else
log_warning "Invalid input '$N8N_RUNNER_COUNT_INPUT_RAW'. Please enter a positive integer. Keeping $N8N_RUNNER_COUNT_CURRENT."
N8N_RUNNER_COUNT="$N8N_RUNNER_COUNT_CURRENT"
fi
fi
else
while true; do
N8N_RUNNER_COUNT_INPUT_RAW=$(wt_input "n8n Runners" "Enter number of n8n runners for Code/Python nodes (default 1)." "1") || true
N8N_RUNNER_COUNT_CANDIDATE="${N8N_RUNNER_COUNT_INPUT_RAW:-1}"
if [[ "$N8N_RUNNER_COUNT_CANDIDATE" =~ ^0*[1-9][0-9]*$ ]]; then
N8N_RUNNER_COUNT_VALIDATED="$((10#$N8N_RUNNER_COUNT_CANDIDATE))"
if [[ "$N8N_RUNNER_COUNT_VALIDATED" -ge 1 ]]; then
if wt_yesno "Confirm Runners" "Run $N8N_RUNNER_COUNT_VALIDATED n8n runner(s)?" "yes"; then
N8N_RUNNER_COUNT="$N8N_RUNNER_COUNT_VALIDATED"
break
fi
else
log_error "Number of runners must be a positive integer." >&2
fi
else
log_error "Invalid input '$N8N_RUNNER_COUNT_CANDIDATE'. Please enter a positive integer (e.g., 1, 2)." >&2
fi
done
fi
# Ensure N8N_RUNNER_COUNT is definitely set (should be by logic above)
N8N_RUNNER_COUNT="${N8N_RUNNER_COUNT:-1}"
# Persist N8N_RUNNER_COUNT to .env
write_env_var "N8N_RUNNER_COUNT" "$N8N_RUNNER_COUNT"
# Generate worker-runner pairs configuration
# Each worker gets its own dedicated task runner sidecar
log_info "Generating n8n worker-runner pairs configuration..."
bash "$SCRIPT_DIR/generate_n8n_workers.sh"
# ----------------------------------------------------------------

View File

@@ -57,6 +57,12 @@ log_success "Service configuration completed."
log_info "Pulling latest versions of selected containers..."
COMPOSE_FILES_FOR_PULL=("-f" "$PROJECT_ROOT/docker-compose.yml")
# Check if n8n workers file exists (generated by 05_configure_services.sh)
N8N_WORKERS_COMPOSE_FILE="$PROJECT_ROOT/docker-compose.n8n-workers.yml"
if [ -f "$N8N_WORKERS_COMPOSE_FILE" ]; then
COMPOSE_FILES_FOR_PULL+=("-f" "$N8N_WORKERS_COMPOSE_FILE")
fi
# Check if Supabase directory and its docker-compose.yml exist
SUPABASE_DOCKER_DIR="$PROJECT_ROOT/supabase/docker"
SUPABASE_COMPOSE_FILE_PATH="$SUPABASE_DOCKER_DIR/docker-compose.yml"

View File

@@ -192,6 +192,11 @@ def stop_existing_containers():
if os.path.exists(dify_compose_path):
cmd.extend(["-f", dify_compose_path])
# Check if the n8n workers compose file exists. If so, include it in the 'down' command.
n8n_workers_compose_path = "docker-compose.n8n-workers.yml"
if os.path.exists(n8n_workers_compose_path):
cmd.extend(["-f", n8n_workers_compose_path])
cmd.append("down")
run_command(cmd)
@@ -219,14 +224,22 @@ def start_local_ai():
"""Start the local AI services (using its compose file)."""
print("Starting local AI services...")
# Build compose files list
compose_files = ["-f", "docker-compose.yml"]
# Check if n8n workers compose file exists (generated by generate_n8n_workers.sh)
n8n_workers_compose_path = "docker-compose.n8n-workers.yml"
if os.path.exists(n8n_workers_compose_path):
compose_files.extend(["-f", n8n_workers_compose_path])
# Explicitly build services and pull newer base images first.
print("Checking for newer base images and building services...")
build_cmd = ["docker", "compose", "-p", "localai", "-f", "docker-compose.yml", "build", "--pull"]
build_cmd = ["docker", "compose", "-p", "localai"] + compose_files + ["build", "--pull"]
run_command(build_cmd)
# Now, start the services using the newly built images. No --build needed as we just built.
print("Starting containers...")
up_cmd = ["docker", "compose", "-p", "localai", "-f", "docker-compose.yml", "up", "-d"]
up_cmd = ["docker", "compose", "-p", "localai"] + compose_files + ["up", "-d"]
run_command(up_cmd)
def generate_searxng_secret_key():