Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Add lumier docker-first interface

f-trycua591a4561e571
diff --git a/.gitignore b/.gitignore
index 8265a5a1b2..33b01bd861 100644
--- a/.gitignore
+++ b/.gitignore
@@ -246,4 +246,7 @@ trajectories/
.gradio_settings.json
# Lumier Storage
-storage/
\ No newline at end of file
+storage/
+
+# Trashes
+.Trashes
\ No newline at end of file
diff --git a/libs/lume/src/Commands/Logs.swift b/libs/lume/src/Commands/Logs.swift
new file mode 100644
index 0000000000..d659eba527
--- /dev/null
+++ b/libs/lume/src/Commands/Logs.swift
@@ -0,0 +1,389 @@
+import ArgumentParser
+import Foundation
+
+struct Logs: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ abstract: "View lume serve logs",
+ subcommands: [Info.self, Error.self, All.self],
+ defaultSubcommand: All.self
+ )
+
+ // Common functionality for reading log files
+ static func readLogFile(path: String, lines: Int? = nil, follow: Bool = false) -> String {
+ let fileManager = FileManager.default
+
+ // Check if file exists
+ guard fileManager.fileExists(atPath: path) else {
+ return "Log file not found at \(path)"
+ }
+
+ do {
+ // Read file content
+ let content = try String(contentsOfFile: path, encoding: .utf8)
+
+ // If lines parameter is provided, return only the specified number of lines from the end
+ if let lineCount = lines {
+ let allLines = content.components(separatedBy: .newlines)
+ let startIndex = max(0, allLines.count - lineCount)
+ let lastLines = Array(allLines[startIndex...])
+ return lastLines.joined(separator: "\n")
+ }
+
+ return content
+ } catch {
+ return "Error reading log file: \(error.localizedDescription)"
+ }
+ }
+
+ // Method for tailing a log file (following new changes)
+ static func tailLogFile(path: String, initialLines: Int? = 10) {
+ let fileManager = FileManager.default
+
+ // Check if file exists
+ guard fileManager.fileExists(atPath: path) else {
+ print("Log file not found at \(path)")
+ return
+ }
+
+ do {
+ // Get initial content with only the specified number of lines from the end
+ var lastPosition: UInt64 = 0
+ let fileHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: path))
+
+ // First, print the last few lines of the file
+ if let lines = initialLines {
+ let content = try String(contentsOfFile: path, encoding: .utf8)
+ let allLines = content.components(separatedBy: .newlines)
+ let startIndex = max(0, allLines.count - lines)
+ let lastLines = Array(allLines[startIndex...])
+ print(lastLines.joined(separator: "\n"))
+ }
+
+ // Get current file size
+ lastPosition = UInt64(try fileManager.attributesOfItem(atPath: path)[.size] as? UInt64 ?? 0)
+
+ // Set up for continuous monitoring
+ print("\nTailing log file... Press Ctrl+C to stop")
+
+ // Monitor file for changes
+ while true {
+ // Brief pause to reduce CPU usage
+ Thread.sleep(forTimeInterval: 0.5)
+
+ // Get current size
+ let currentSize = try fileManager.attributesOfItem(atPath: path)[.size] as? UInt64 ?? 0
+
+ // If file has grown
+ if currentSize > lastPosition {
+ // Seek to where we last read
+ fileHandle.seek(toFileOffset: lastPosition)
+
+ // Read new content
+ if let newData = try? fileHandle.readToEnd() {
+ if let newContent = String(data: newData, encoding: .utf8) {
+ // Print new content without trailing newline
+ if newContent.hasSuffix("\n") {
+ print(newContent, terminator: "")
+ } else {
+ print(newContent)
+ }
+ }
+ }
+
+ // Update position
+ lastPosition = currentSize
+ }
+
+ // Handle file rotation (if file became smaller)
+ else if currentSize < lastPosition {
+ // File was probably rotated, start from beginning
+ lastPosition = 0
+ fileHandle.seek(toFileOffset: 0)
+
+ if let newData = try? fileHandle.readToEnd() {
+ if let newContent = String(data: newData, encoding: .utf8) {
+ print(newContent, terminator: "")
+ }
+ }
+
+ lastPosition = currentSize
+ }
+ }
+ } catch {
+ print("Error tailing log file: \(error.localizedDescription)")
+ }
+ }
+
+ // MARK: - Info Logs Subcommand
+
+ struct Info: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "info",
+ abstract: "View info logs from the daemon"
+ )
+
+ @Option(name: .shortAndLong, help: "Number of lines to display from the end of the file")
+ var lines: Int?
+
+ @Flag(name: .shortAndLong, help: "Follow log file continuously (like tail -f)")
+ var follow: Bool = false
+
+ func run() throws {
+ let logPath = "/tmp/lume_daemon.log"
+
+ print("=== Info Logs ===")
+
+ if follow {
+ // Use tailing functionality to continuously monitor the log
+ Logs.tailLogFile(path: logPath, initialLines: lines ?? 10)
+ } else {
+ // Regular one-time viewing of logs
+ let content = Logs.readLogFile(path: logPath, lines: lines)
+ print(content)
+ }
+ }
+ }
+
+ // MARK: - Error Logs Subcommand
+
+ struct Error: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "error",
+ abstract: "View error logs from the daemon"
+ )
+
+ @Option(name: .shortAndLong, help: "Number of lines to display from the end of the file")
+ var lines: Int?
+
+ @Flag(name: .shortAndLong, help: "Follow log file continuously (like tail -f)")
+ var follow: Bool = false
+
+ func run() throws {
+ let logPath = "/tmp/lume_daemon.error.log"
+
+ print("=== Error Logs ===")
+
+ if follow {
+ // Use tailing functionality to continuously monitor the log
+ Logs.tailLogFile(path: logPath, initialLines: lines ?? 10)
+ } else {
+ // Regular one-time viewing of logs
+ let content = Logs.readLogFile(path: logPath, lines: lines)
+ print(content)
+ }
+ }
+ }
+
+ // MARK: - All Logs Subcommand
+
+ struct All: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "all",
+ abstract: "View both info and error logs from the daemon"
+ )
+
+ @Option(name: .shortAndLong, help: "Number of lines to display from the end of each file")
+ var lines: Int?
+
+ @Flag(name: .shortAndLong, help: "Follow log files continuously (like tail -f)")
+ var follow: Bool = false
+
+ // Custom implementation to tail both logs simultaneously
+ private func tailBothLogs(infoPath: String, errorPath: String, initialLines: Int? = 10) {
+ let fileManager = FileManager.default
+ var infoExists = fileManager.fileExists(atPath: infoPath)
+ var errorExists = fileManager.fileExists(atPath: errorPath)
+
+ if !infoExists && !errorExists {
+ print("Neither info nor error log files found")
+ return
+ }
+
+ // Print initial content
+ print("=== Info Logs ===")
+ if infoExists {
+ if let lines = initialLines {
+ let content = (try? String(contentsOfFile: infoPath, encoding: .utf8)) ?? ""
+ let allLines = content.components(separatedBy: .newlines)
+ let startIndex = max(0, allLines.count - lines)
+ let lastLines = Array(allLines[startIndex...])
+ print(lastLines.joined(separator: "\n"))
+ }
+ } else {
+ print("Info log file not found")
+ }
+
+ print("\n=== Error Logs ===")
+ if errorExists {
+ if let lines = initialLines {
+ let content = (try? String(contentsOfFile: errorPath, encoding: .utf8)) ?? ""
+ let allLines = content.components(separatedBy: .newlines)
+ let startIndex = max(0, allLines.count - lines)
+ let lastLines = Array(allLines[startIndex...])
+ print(lastLines.joined(separator: "\n"))
+ }
+ } else {
+ print("Error log file not found")
+ }
+
+ print("\nTailing both log files... Press Ctrl+C to stop")
+
+ // Initialize file handles and positions
+ var infoHandle: FileHandle? = nil
+ var errorHandle: FileHandle? = nil
+ var infoPosition: UInt64 = 0
+ var errorPosition: UInt64 = 0
+
+ // Set up file handles
+ if infoExists {
+ do {
+ infoHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: infoPath))
+ infoPosition = UInt64(try fileManager.attributesOfItem(atPath: infoPath)[.size] as? UInt64 ?? 0)
+ } catch {
+ print("Error opening info log file: \(error.localizedDescription)")
+ }
+ }
+
+ if errorExists {
+ do {
+ errorHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: errorPath))
+ errorPosition = UInt64(try fileManager.attributesOfItem(atPath: errorPath)[.size] as? UInt64 ?? 0)
+ } catch {
+ print("Error opening error log file: \(error.localizedDescription)")
+ }
+ }
+
+ // Monitor both files for changes
+ while true {
+ Thread.sleep(forTimeInterval: 0.5)
+
+ // Check for new content in info log
+ if let handle = infoHandle {
+ do {
+ // Re-check existence in case file was deleted
+ infoExists = fileManager.fileExists(atPath: infoPath)
+ if !infoExists {
+ print("\n[Info log file was removed]")
+ infoHandle = nil
+ continue
+ }
+
+ let currentSize = try fileManager.attributesOfItem(atPath: infoPath)[.size] as? UInt64 ?? 0
+
+ if currentSize > infoPosition {
+ handle.seek(toFileOffset: infoPosition)
+ if let newData = try? handle.readToEnd() {
+ if let newContent = String(data: newData, encoding: .utf8) {
+ print("\n--- New Info Log Content ---")
+ if newContent.hasSuffix("\n") {
+ print(newContent, terminator: "")
+ } else {
+ print(newContent)
+ }
+ }
+ }
+ infoPosition = currentSize
+ } else if currentSize < infoPosition {
+ // File was rotated
+ print("\n[Info log was rotated]")
+ infoPosition = 0
+ handle.seek(toFileOffset: 0)
+ if let newData = try? handle.readToEnd() {
+ if let newContent = String(data: newData, encoding: .utf8) {
+ print("\n--- New Info Log Content ---")
+ print(newContent, terminator: "")
+ }
+ }
+ infoPosition = currentSize
+ }
+ } catch {
+ print("\nError reading info log: \(error.localizedDescription)")
+ }
+ } else if fileManager.fileExists(atPath: infoPath) && !infoExists {
+ // File exists again after being deleted
+ do {
+ infoHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: infoPath))
+ infoPosition = 0
+ infoExists = true
+ print("\n[Info log file reappeared]")
+ } catch {
+ print("\nError reopening info log: \(error.localizedDescription)")
+ }
+ }
+
+ // Check for new content in error log
+ if let handle = errorHandle {
+ do {
+ // Re-check existence in case file was deleted
+ errorExists = fileManager.fileExists(atPath: errorPath)
+ if !errorExists {
+ print("\n[Error log file was removed]")
+ errorHandle = nil
+ continue
+ }
+
+ let currentSize = try fileManager.attributesOfItem(atPath: errorPath)[.size] as? UInt64 ?? 0
+
+ if currentSize > errorPosition {
+ handle.seek(toFileOffset: errorPosition)
+ if let newData = try? handle.readToEnd() {
+ if let newContent = String(data: newData, encoding: .utf8) {
+ print("\n--- New Error Log Content ---")
+ if newContent.hasSuffix("\n") {
+ print(newContent, terminator: "")
+ } else {
+ print(newContent)
+ }
+ }
+ }
+ errorPosition = currentSize
+ } else if currentSize < errorPosition {
+ // File was rotated
+ print("\n[Error log was rotated]")
+ errorPosition = 0
+ handle.seek(toFileOffset: 0)
+ if let newData = try? handle.readToEnd() {
+ if let newContent = String(data: newData, encoding: .utf8) {
+ print("\n--- New Error Log Content ---")
+ print(newContent, terminator: "")
+ }
+ }
+ errorPosition = currentSize
+ }
+ } catch {
+ print("\nError reading error log: \(error.localizedDescription)")
+ }
+ } else if fileManager.fileExists(atPath: errorPath) && !errorExists {
+ // File exists again after being deleted
+ do {
+ errorHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: errorPath))
+ errorPosition = 0
+ errorExists = true
+ print("\n[Error log file reappeared]")
+ } catch {
+ print("\nError reopening error log: \(error.localizedDescription)")
+ }
+ }
+ }
+ }
+
+ func run() throws {
+ let infoLogPath = "/tmp/lume_daemon.log"
+ let errorLogPath = "/tmp/lume_daemon.error.log"
+
+ if follow {
+ // Use custom tailing implementation for both logs
+ tailBothLogs(infoPath: infoLogPath, errorPath: errorLogPath, initialLines: lines ?? 10)
+ } else {
+ // Regular one-time viewing of logs
+ let infoContent = Logs.readLogFile(path: infoLogPath, lines: lines)
+ let errorContent = Logs.readLogFile(path: errorLogPath, lines: lines)
+
+ print("=== Info Logs ===")
+ print(infoContent)
+ print("\n=== Error Logs ===")
+ print(errorContent)
+ }
+ }
+ }
+}
diff --git a/libs/lume/src/Server/Handlers.swift b/libs/lume/src/Server/Handlers.swift
index bf289350a2..9ac2073266 100644
--- a/libs/lume/src/Server/Handlers.swift
+++ b/libs/lume/src/Server/Handlers.swift
@@ -519,6 +519,55 @@ extension Server {
}
}
+ // MARK: - Log Handlers
+
+ func handleGetLogs(type: String?, lines: Int?) async throws -> HTTPResponse {
+ do {
+ let logType = type?.lowercased() ?? "all"
+ let infoPath = "/tmp/lume_daemon.log"
+ let errorPath = "/tmp/lume_daemon.error.log"
+
+ let fileManager = FileManager.default
+ var response: [String: String] = [:]
+
+ // Function to read log files
+ func readLogFile(path: String) -> String? {
+ guard fileManager.fileExists(atPath: path) else {
+ return nil
+ }
+
+ do {
+ let content = try String(contentsOfFile: path, encoding: .utf8)
+
+ // If lines parameter is provided, return only the specified number of lines from the end
+ if let lineCount = lines {
+ let allLines = content.components(separatedBy: .newlines)
+ let startIndex = max(0, allLines.count - lineCount)
+ let lastLines = Array(allLines[startIndex...])
+ return lastLines.joined(separator: "\n")
+ }
+
+ return content
+ } catch {
+ return "Error reading log file: \(error.localizedDescription)"
+ }
+ }
+
+ // Get logs based on requested type
+ if logType == "info" || logType == "all" {
+ response["info"] = readLogFile(path: infoPath) ?? "Info log file not found"
+ }
+
+ if logType == "error" || logType == "all" {
+ response["error"] = readLogFile(path: errorPath) ?? "Error log file not found"
+ }
+
+ return try .json(response)
+ } catch {
+ return .badRequest(message: error.localizedDescription)
+ }
+ }
+
// MARK: - Private Helper Methods
nonisolated private func startVM(
diff --git a/libs/lume/src/Server/Server.swift b/libs/lume/src/Server/Server.swift
index 782efa7054..fda4d92e74 100644
--- a/libs/lume/src/Server/Server.swift
+++ b/libs/lume/src/Server/Server.swift
@@ -44,7 +44,10 @@ final class Server {
func extractParams(_ request: HTTPRequest) -> [String: String] {
var params: [String: String] = [:]
let routeParts = path.split(separator: "/")
- let requestParts = request.path.split(separator: "/")
+
+ // Split request path to remove query parameters
+ let requestPathOnly = request.path.split(separator: "?", maxSplits: 1)[0]
+ let requestParts = requestPathOnly.split(separator: "/")
for (routePart, requestPart) in zip(routeParts, requestParts) {
if routePart.hasPrefix(":") {
@@ -261,6 +264,20 @@ final class Server {
}
return try await self.handleRemoveLocation(name)
}),
+
+ // Logs retrieval route
+ Route(
+ method: "GET", path: "/lume/logs",
+ handler: { [weak self] request in
+ guard let self else { throw HTTPError.internalError }
+
+ // Extract query parameters
+ let type = self.extractQueryParam(request: request, name: "type") // "info", "error", or "all"
+ let linesParam = self.extractQueryParam(request: request, name: "lines")
+ let lines = linesParam.flatMap { Int($0) } // Convert to Int if present
+
+ return try await self.handleGetLogs(type: type, lines: lines)
+ }),
Route(
method: "POST", path: "/lume/config/locations/default/:name",
handler: { [weak self] request in
@@ -287,10 +304,16 @@ final class Server {
// Helper to extract query parameters from the URL
private func extractQueryParam(request: HTTPRequest, name: String) -> String? {
- if let urlComponents = URLComponents(string: request.path),
- let queryItems = urlComponents.queryItems
+ // Extract only the query part by splitting on '?'
+ let parts = request.path.split(separator: "?", maxSplits: 1)
+ guard parts.count > 1 else { return nil } // No query parameters
+
+ let queryString = String(parts[1])
+ // Create a placeholder URL with the query string
+ if let urlComponents = URLComponents(string: "http://placeholder.com?"+queryString),
+ let queryItems = urlComponents.queryItems
{
- return queryItems.first(where: { $0.name == name })?.value
+ return queryItems.first(where: { $0.name == name })?.value?.removingPercentEncoding
}
return nil
}
diff --git a/libs/lume/src/Utils/CommandRegistry.swift b/libs/lume/src/Utils/CommandRegistry.swift
index 4d128971b8..44f7acd7bc 100644
--- a/libs/lume/src/Utils/CommandRegistry.swift
+++ b/libs/lume/src/Utils/CommandRegistry.swift
@@ -18,6 +18,7 @@ enum CommandRegistry {
Delete.self,
Prune.self,
Config.self,
+ Logs.self,
]
}
}
diff --git a/libs/lumier/Dockerfile b/libs/lumier/Dockerfile
index 710eb80b7a..06829adfa1 100644
--- a/libs/lumier/Dockerfile
+++ b/libs/lumier/Dockerfile
@@ -3,7 +3,6 @@ FROM debian:bullseye-slim AS lumier-base
# Set environment variables for Lume API server configuration
ENV LUME_API_HOST="host.docker.internal"
-ENV LUME_API_PORT="8080"
# Default VM configuration (can be overridden at runtime)
ENV VERSION="ghcr.io/trycua/macos-sequoia-vanilla:latest"
@@ -12,7 +11,7 @@ ENV CPU_CORES="4"
ENV DISK_SIZE="100"
ENV DISPLAY="1024x768"
ENV VM_NAME="lumier"
-ENV HOST_DATA_PATH=""
+ENV HOST_SHARED_PATH=""
ENV LUMIER_DEBUG="0"
# Install necessary tools and noVNC dependencies
@@ -30,25 +29,19 @@ RUN apt-get update && \
procps && \
rm -rf /var/lib/apt/lists/*
-# Add a dummy environment variable to invalidate cache
-ENV CACHEBUST=1
-
# Download and install noVNC without caching
-RUN wget https://github.com/trycua/noVNC/archive/refs/heads/master.zip -O master1.zip && \
- unzip master1.zip && \
+RUN wget https://github.com/trycua/noVNC/archive/refs/heads/master.zip -O master.zip && \
+ unzip master.zip && \
mv noVNC-master /opt/noVNC && \
- rm master1.zip
+ rm master.zip
# Set environment variables for noVNC
ENV NOVNC_PATH="/opt/noVNC"
-# Create directory structure
-RUN mkdir -p /run/bin /run/lib /run/config /run/hooks
+# Create necessary directories
+RUN mkdir -p /run/bin /run/lib /run/config /run/hooks /run/lifecycle
# Copy scripts to the container
-COPY src/bin/tunnel.sh /run/bin/
-COPY src/bin/tunnel-script.sh /usr/local/bin/lume
-COPY src/bin/tunnel-script.sh /usr/local/bin/sshpass
COPY src/config/constants.sh /run/config/
COPY src/bin/entry.sh /run/bin/entry.sh
@@ -56,14 +49,16 @@ COPY src/bin/entry.sh /run/bin/entry.sh
COPY src/lib/ /run/lib/
COPY src/hooks/ /run/hooks/
+# Copy on-logon script to lifecycle directory
+COPY src/hooks/on-logon.sh /run/lifecycle/
+
# Make scripts executable
-RUN chmod +x /usr/local/bin/lume \
- /usr/local/bin/sshpass \
+RUN chmod +x \
/run/bin/* \
- /run/hooks/* 2>/dev/null || true
+ /run/hooks/* \
+ /run/lifecycle/* 2>/dev/null || true
# Expose ports for noVNC and Lume API
-EXPOSE 8080
EXPOSE 8006
# VOLUME setup
diff --git a/libs/lumier/README.md b/libs/lumier/README.md
index 65803e3998..edb25f7fa8 100644
--- a/libs/lumier/README.md
+++ b/libs/lumier/README.md
@@ -15,19 +15,55 @@
</h1>
</div>
-**Lumier** provides a Docker-based interface for the `lume` CLI, allowing you to easily run macOS virtual machines inside a container with VNC access. It creates a secure tunnel to execute lume commands on your host machine while providing a containerized environment for your applications.
+**Lumier** provides a Docker-based interface for the `lume` CLI, allowing you to easily run macOS virtual machines inside a container with VNC access. It interacts directly with the `lume serve` API running on your host machine to manage VMs.
## Requirements
Before using Lumier, make sure you have:
-1. Install [lume](https://github.com/trycua/cua/blob/main/libs/lume/README.md) on your host machine
+1. Install [lume](https://github.com/trycua/cua/blob/main/libs/lume/README.md) on your host machine and ensure `lume serve` is running (typically on port 3000).
2. Docker installed on your host machine
-3. `socat` installed for the tunnel (install with Homebrew: `brew install socat`)
-## Installation
+## Usage (Direct Docker Commands - Recommended)
-You can use Lumier directly from its directory or install it to your system:
+The primary way to use Lumier is directly through Docker commands. This gives you full control over the container environment.
+
+Ensure `lume serve` is running on your host machine before starting the container.
+
+```bash
+# 1. Build the Docker image (if not already built or pulled)
+docker build -t lumier:latest .
+
+# 2. Run the container
+docker run -it --rm \
+ --name lumier-vm \
+ -p 8006:8006 \
+ -v $(pwd)/storage:/storage \
+ -v $(pwd)/shared:/shared \
+ -e VM_NAME=lumier-vm \
+ -e VERSION=ghcr.io/trycua/macos-sequoia-cua:latest \
+ -e CPU_CORES=4 \
+ -e RAM_SIZE=8192 \
+ -e HOST_STORAGE_PATH=$(pwd)/storage \
+ -e HOST_SHARED_PATH=$(pwd)/shared \
+ lumier:latest
+```
+
+Note that when using Docker directly, you're responsible for:
+- Ensuring `lume serve` is running on the host.
+- Building the Docker image (or pulling `trycua/lumier:latest`).
+- Providing all necessary environment variables (`-e`) and volume mounts (`-v`).
+- Mapping the VNC port (`-p 8006:8006`).
+
+See "Available Environment Variables" below for customization options.
+
+## Optional Helper Script (`lumier`)
+
+For convenience, an optional helper script `lumier` is provided. It simplifies some common tasks like building the image and passing arguments to `docker run`.
+
+### Installation (Optional, for `lumier` script)
+
+If you want to use the `lumier` helper script system-wide, you can install it:
```bash
# Option 1: Install to your user's bin directory (recommended)
@@ -40,32 +76,15 @@ You can use Lumier directly from its directory or install it to your system:
./install.sh --help
```
-After installation, you can run `lumier` from anywhere in your terminal.
-
-If you get a "command not found" error, make sure the installation directory is in your PATH. The installer will warn you if it isn't and provide instructions to add it.
-
-## Usage
-
-There are two ways to use Lumier: with the provided script or directly with Docker.
-
-### Option 1: Using the Lumier Script
+### Using the Lumier Script
-Lumier provides a simple CLI interface to manage VMs in Docker with full Docker compatibility:
+If you installed the script, you can use it as a wrapper around Docker commands:
```bash
-# Show help and available commands
+# Show help for the script
lumier help
-# Start the tunnel to connect to lume
-lumier start
-
-# Check if the tunnel is running
-lumier status
-
-# Stop the tunnel
-lumier stop
-
-# Build the Docker image (optional, happens automatically on first run)
+# Build the Docker image (optional, happens automatically on first run if not pulled)
lumier build
# Run a VM with default settings
@@ -73,63 +92,25 @@ lumier run -it --rm
# Run a VM with custom settings using Docker's -e flag
lumier run -it --rm \
- --name lumier-vm \
+ --name lumier1-vm \
-p 8006:8006 \
- -v $(pwd)/storage:/storage \
- -v $(pwd)/shared:/data \
+ -v $(pwd)/storage1:/storage \
+ -v $(pwd)/shared1:/shared \
-e VERSION=ghcr.io/trycua/macos-sequoia-cua:latest \
- -e CPU_CORES=4 \
- -e RAM_SIZE=8192
+ -e CPU_CORES=8 \
+ -e RAM_SIZE=16GB
# Note:
-# The lumier script now automatically detects the real host paths for ./storage and ./shared
-# and passes them to the container as HOST_STORAGE_PATH and HOST_DATA_PATH.
-# You do NOT need to specify these environment variables manually.
-# The VM name is always set from the container name.
+# The lumier script will automatically:
+# 1. Detect user-provided volume paths for /storage and /shared and use those exact paths
+# 2. If not specified, default to ./storage and ./shared in the current directory
+# 3. Pass the resolved paths to the container as HOST_STORAGE_PATH and HOST_SHARED_PATH
+# 4. Create any non-existent directories automatically via Docker's volume mounting
+# 5. Set the VM name from the container name
+#
+# You do NOT need to specify HOST_STORAGE_PATH or HOST_SHARED_PATH environment variables manually.
```
-### Option 2: Using Docker Directly
-
-You can also use Docker commands directly without the lumier utility:
-
-```bash
-# 1. Start the tunnel manually
-cd libs/lumier
-socat TCP-LISTEN:8080,reuseaddr,fork EXEC:"$PWD/src/bin/tunnel.sh" &
-TUNNEL_PID=$!
-
-# 2. Build the Docker image
-docker build -t lumier:latest .
-
-# 3. Run the container
-docker run -it --rm \
- --name lumier-vm \
- -p 8006:8006 \
- -v $(pwd)/storage:/storage \
- -v $(pwd)/shared:/data \
- -e VM_NAME=lumier-vm \
- -e VERSION=ghcr.io/trycua/macos-sequoia-cua:latest \
- -e CPU_CORES=4 \
- -e RAM_SIZE=8192 \
- -e HOST_STORAGE_PATH=$(pwd)/storage \
- -e HOST_DATA_PATH=$(pwd)/shared \
- lumier:latest
-
-# 4. Stop the tunnel when you're done
-kill $TUNNEL_PID
-
-# Alternatively, find and kill the tunnel process
-# First, find the process
-lsof -i TCP:8080
-# Then kill it by PID
-kill <PID>
-```
-
-Note that when using Docker directly, you're responsible for:
-- Starting and managing the tunnel
-- Building the Docker image
-- Providing the correct environment variables
-
## Available Environment Variables
These variables can be set using Docker's `-e` flag:
@@ -139,7 +120,7 @@ These variables can be set using Docker's `-e` flag:
- `CPU_CORES`: Set the number of CPU cores (default: 4)
- `RAM_SIZE`: Set the memory size in MB (default: 8192)
- `DISPLAY`: Set the display resolution (default: 1024x768)
-- `HOST_DATA_PATH`: Path on the host to share with the VM
+- `HOST_SHARED_PATH`: Path on the host to share with the VM
- `LUMIER_DEBUG`: Enable debug mode (set to 1)
## Project Structure
@@ -155,14 +136,12 @@ lumier/
├── src/ # Source code
│ ├── bin/ # Executable scripts
│ │ ├── entry.sh # Docker entrypoint
-│ │ ├── server.sh # Tunnel server manager
-│ │ └── tunnel.sh # Tunnel request handler
+│ │ └── utils.sh # Utility functions
│ ├── config/ # Configuration
│ │ └── constants.sh # Shared constants
│ ├── hooks/ # Lifecycle hooks
│ │ └── on-logon.sh # Run after VM boots
│ └── lib/ # Shared library code
-│ ├── utils.sh # Utility functions
│ └── vm.sh # VM management functions
└── mount/ # Default shared directory
```
diff --git a/libs/lumier/examples/Custom.Dockerfile b/libs/lumier/examples/Custom.Dockerfile
new file mode 100644
index 0000000000..9938f65616
--- /dev/null
+++ b/libs/lumier/examples/Custom.Dockerfile
@@ -0,0 +1,31 @@
+# Custom Lumier image that uses the base lumier:latest image
+# and overrides environment variables as needed
+FROM trycua/lumier:latest
+
+# Default environment variables that can be overridden at build time
+# These values will override the defaults from the base image
+ARG CUSTOM_VERSION="ghcr.io/trycua/macos-sequoia-vanilla:latest"
+ARG CUSTOM_RAM_SIZE="16384"
+ARG CUSTOM_CPU_CORES="8"
+ARG CUSTOM_DISK_SIZE="100"
+ARG CUSTOM_DISPLAY="1024x768"
+ARG CUSTOM_VM_NAME="custom-vanilla-lumier"
+
+# Set environment variables based on build args
+ENV VERSION=${CUSTOM_VERSION}
+ENV RAM_SIZE=${CUSTOM_RAM_SIZE}
+ENV CPU_CORES=${CUSTOM_CPU_CORES}
+ENV DISK_SIZE=${CUSTOM_DISK_SIZE}
+ENV DISPLAY=${CUSTOM_DISPLAY}
+ENV VM_NAME=${CUSTOM_VM_NAME}
+
+# Create the necessary directory for lifecycle scripts
+RUN mkdir -p /run/lifecycle
+
+# Copy custom on-logon script to be executed inside the VM after login
+COPY src/lifecycle/on-logon.sh /run/lifecycle/on-logon.sh
+
+# Make sure the script is executable
+RUN chmod +x /run/lifecycle/on-logon.sh
+
+# We're using the default entrypoint from the base image
diff --git a/libs/lumier/examples/docker-compose.yml b/libs/lumier/examples/docker-compose.yml
new file mode 100644
index 0000000000..96afbd18b9
--- /dev/null
+++ b/libs/lumier/examples/docker-compose.yml
@@ -0,0 +1,44 @@
+version: '3'
+
+# IMPORTANT: Before using this docker-compose file, start the tunnel manually:
+# socat TCP-LISTEN:8080,reuseaddr,fork EXEC:"$(pwd)/../src/bin/tunnel.sh" &
+
+services:
+ lumier:
+ image: lumier:latest # or trycua/lumier:latest if using the Docker Hub image
+ container_name: lumier-vm
+ restart: unless-stopped
+ ports:
+ - "8006:8006" # Port for VNC access
+ volumes:
+ - ../storage:/storage # VM persistent storage (relative path from docker-compose.yml)
+ - ../shared:/data # Shared folder accessible in the VM
+ environment:
+ - VM_NAME=lumier-vm
+ - VERSION=ghcr.io/trycua/macos-sequoia-vanilla:latest # Default MacOS image
+ - CPU_CORES=4 # Number of CPU cores
+ - RAM_SIZE=8192 # RAM in MB
+ - HOST_STORAGE_PATH=${PWD}/../storage # Required for Docker-only setup
+ - HOST_SHARED_PATH=${PWD}/../shared # Required for Docker-only setup
+ - LUMIER_DEBUG=0 # Set to 1 for debug mode
+ # Network mode host is optional but can improve performance
+ # network_mode: host
+
+ # Uncomment the following lines if needed for KVM virtualization
+ # devices:
+ # - /dev/kvm
+ # - /dev/net/tun
+ stop_signal: SIGINT
+ stop_grace_period: 2m
+
+# Note: When using Docker Compose for Lumier, you're responsible for:
+# - Starting and managing the tunnel (using socat as shown above)
+# - Building the Docker image before first use (docker-compose build)
+# - Providing the correct environment variables (HOST_STORAGE_PATH and HOST_SHARED_PATH)
+#
+# To stop the tunnel when done:
+# 1. Find the process: lsof -i TCP:8080
+# 2. Kill it by PID: kill <PID>
+#
+# Access the VM via VNC at: http://localhost:8006/vnc.html
+# The password will be displayed in the logs (docker-compose logs)
diff --git a/libs/lumier/install.sh b/libs/lumier/install.sh
index bd9e3b6b95..359ebdd45c 100755
--- a/libs/lumier/install.sh
+++ b/libs/lumier/install.sh
@@ -111,21 +111,11 @@ check_dependencies() {
exit 1
fi
- # Check if socat is installed
- if ! command -v socat &> /dev/null; then
- echo "${YELLOW}Warning: socat is required but not installed.${NORMAL}"
- echo "Installing socat with Homebrew..."
-
- # Check if Homebrew is installed
- if ! command -v brew &> /dev/null; then
- echo "${RED}Error: Homebrew is required to install socat.${NORMAL}"
- echo "Please install Homebrew first: https://brew.sh/"
- echo "Or install socat manually, then run this script again."
- exit 1
- fi
-
- # Install socat
- brew install socat
+ # Check if netcat (nc) is installed - should be pre-installed on macOS
+ if ! command -v nc &> /dev/null; then
+ echo "${RED}Error: netcat (nc) is required but not found.${NORMAL}"
+ echo "This should be pre-installed on macOS. Please check your system installation."
+ exit 1
fi
# Check if Docker is installed
diff --git a/libs/lumier/mount/setup.sh b/libs/lumier/lifecycle/setup.sh
similarity index 100%
rename from libs/lumier/mount/setup.sh
rename to libs/lumier/lifecycle/setup.sh
diff --git a/libs/lumier/lumier b/libs/lumier/lumier
index 1c3912cb50..a5c783e03f 100755
--- a/libs/lumier/lumier
+++ b/libs/lumier/lumier
@@ -5,7 +5,6 @@ set -eo pipefail
# Always use the current working directory as the build context
SCRIPT_DIR="$(pwd)"
-PORT=8080
DEBUG=${LUMIER_DEBUG:-0}
usage() {
@@ -16,10 +15,9 @@ Usage: $(basename "$0") COMMAND [OPTIONS]
Commands:
run [DOCKER_ARGS] Build (if needed) and run the Lumier container with Docker args
- tunnel start Start the Lumier tunnel
- tunnel stop Stop the Lumier tunnel
- tunnel status Check the status of the Lumier tunnel
build [DOCKER_ARGS] Build the Lumier Docker image with optional Docker args
+ push [TAG] Push the Lumier image to Docker Hub with optional tag
+ pull Pull the trycua/lumier:latest image from Docker Hub
help Show this help message
Docker Container Environment Variables:
@@ -29,7 +27,8 @@ Docker Container Environment Variables:
VERSION Set the VM image (default: ghcr.io/trycua/macos-sequoia-vanilla:latest)
CPU_CORES Set the number of CPU cores (default: 4)
RAM_SIZE Set the memory size in MB (default: 8192)
- HOST_DATA_PATH Path to mount as shared directory in the VM
+ HOST_STORAGE_PATH Path to mount as shared directory in the VM
+ HOST_SHARED_PATH Path to mount as shared directory in the VM
LUMIER_DEBUG Enable debug mode (set to 1)
Script Environment Variables:
@@ -45,36 +44,20 @@ Examples:
-e VM_NAME=my-vm \\
-e VERSION=ghcr.io/trycua/macos-sequoia-cua:latest \\
-e RAM_SIZE=16384 \\
- -v $(pwd)/mount:/data
+ -v $(pwd)/mount:/shared
# Build with a custom image name
LUMIER_IMAGE=myorg/lumier:v1 $(basename "$0") build
-EOF
-}
-
-# Check if the tunnel is active
-is_tunnel_active() {
- if lsof -i TCP:$PORT 2>/dev/null | grep LISTEN > /dev/null; then
- return 0 # Tunnel is active
- else
- return 1 # Tunnel is not active
- fi
-}
-# Start the tunnel if needed
-ensure_tunnel() {
- if ! is_tunnel_active; then
- echo "Tunnel is not active. Starting tunnel..."
- "$SCRIPT_DIR/src/bin/server.sh" start
- sleep 2 # Wait for the tunnel to start
-
- if ! is_tunnel_active; then
- echo "Failed to start tunnel. Make sure 'lume' is installed on your host."
- exit 1
- fi
- else
- echo "Tunnel is already active."
- fi
+ # Push to Docker Hub
+ $(basename "$0") push v1.0.0
+
+ # Push with a custom image name
+ LUMIER_IMAGE=myorg/lumier:v1 $(basename "$0") push
+
+ # Pull trycua/lumier:latest from Docker Hub
+ $(basename "$0") pull
+EOF
}
# Build the Docker image with cache busting
@@ -91,9 +74,10 @@ build_image() {
echo "Lumier image built successfully: $image_name"
}
-# Run the Docker container
-run_container() {
+# Push the Docker image to Docker Hub
+push_image() {
local image_name="${LUMIER_IMAGE:-lumier:latest}"
+ local tag="${1:-latest}"
# Ensure the Docker image exists
if ! docker image inspect "$image_name" &>/dev/null; then
@@ -101,12 +85,122 @@ run_container() {
build_image
fi
- # Ensure the tunnel is running
- ensure_tunnel
+ # If the image doesn't have a Docker Hub repository format, use the tag argument
+ if [[ "$image_name" != *"/"* && "$image_name" != "ghcr.io/"* ]]; then
+ # If tag was provided and the image name doesn't already have a tag
+ if [[ -n "$tag" && "$image_name" != *":"* ]]; then
+ # Extract the base name without any tag
+ local base_name="${image_name%%:*}"
+ # Tag the image for Docker Hub with the provided tag
+ local hub_image="${DOCKER_USERNAME:-trycua}/$base_name:$tag"
+ echo "Tagging image $image_name as $hub_image"
+ docker tag "$image_name" "$hub_image"
+ image_name="$hub_image"
+ else
+ # Tag with Docker Hub username but keep the existing tag
+ local base_name_with_tag="$image_name"
+ local hub_image="${DOCKER_USERNAME:-trycua}/$base_name_with_tag"
+ echo "Tagging image $image_name as $hub_image"
+ docker tag "$image_name" "$hub_image"
+ image_name="$hub_image"
+ fi
+ elif [[ "$image_name" != *":"* && -n "$tag" ]]; then
+ # If the image has a repo format but no tag, add the provided tag
+ image_name="${image_name}:${tag}"
+ echo "Using image name with tag: $image_name"
+ fi
+
+ echo "Pushing image to Docker Hub: $image_name"
+ docker push "$image_name"
+ echo "Image pushed successfully: $image_name"
+}
+
+# Pull the trycua/lumier:latest image from Docker Hub
+pull_image() {
+ local image_name="trycua/lumier:latest"
+
+ echo "Pulling image from Docker Hub: $image_name"
+ docker pull "$image_name"
+
+ # Check if the pull was successful
+ if docker image inspect "$image_name" &>/dev/null; then
+ echo "Image pulled successfully: $image_name"
+
+ # If LUMIER_IMAGE is set to something else, tag the pulled image with that name
+ if [[ -n "${LUMIER_IMAGE}" && "${LUMIER_IMAGE}" != "$image_name" ]]; then
+ echo "Tagging pulled image as ${LUMIER_IMAGE}"
+ docker tag "$image_name" "${LUMIER_IMAGE}"
+ echo "Image tagged successfully as ${LUMIER_IMAGE}"
+ fi
+ else
+ echo "Failed to pull image: $image_name"
+ exit 1
+ fi
+}
+
+# Run the Docker container
+run_container() {
+ local image_name="${LUMIER_IMAGE:-lumier:latest}"
+
+ # Ensure the Docker image exists locally
+ if ! docker image inspect "$image_name" &>/dev/null; then
+ echo "Lumier image '$image_name' not found locally."
+ # Check if it exists on Docker Hub (only for the default image)
+ if [[ "$image_name" == "lumier:latest" ]]; then
+ echo "Attempting to pull trycua/lumier:latest from Docker Hub..."
+ if docker pull trycua/lumier:latest; then
+ echo "Successfully pulled trycua/lumier:latest."
+ image_name="trycua/lumier:latest" # Use the pulled image
+ else
+ echo "Failed to pull image from Docker Hub. Building locally..."
+ build_image
+ fi
+ else
+ echo "Building image locally..."
+ build_image # Build other images if not found
+ fi
+ fi
+
+ # Extract volume paths from arguments if provided
+ STORAGE_PATH="${HOST_STORAGE_PATH:-./storage}"
+ SHARED_PATH="${HOST_SHARED_PATH:-./shared}"
+
+ # Parse user-provided volume arguments to extract paths
+ local prev_was_v=false
+ for arg in "$@"; do
+ if $prev_was_v; then
+ # Format is HOST_PATH:CONTAINER_PATH
+ local host_path=${arg%%:*}
+ local container_path=${arg#*:}
+
+ # Update the paths based on container mount points
+ if [[ "$container_path" == "/storage" ]]; then
+ # Use the exact path provided by the user without calling realpath
+ STORAGE_PATH="$host_path"
+ elif [[ "$container_path" == "/shared" ]]; then
+ # Use the exact path provided by the user without calling realpath
+ SHARED_PATH="$host_path"
+ fi
+ prev_was_v=false
+ elif [[ "$arg" == "-v" ]]; then
+ prev_was_v=true
+ elif [[ "$arg" == --volume=* ]]; then
+ # Handle --volume=HOST:CONTAINER format
+ local volume_spec=${arg#--volume=}
+ local host_path=${volume_spec%%:*}
+ local container_path=${volume_spec#*:}
+
+ if [[ "$container_path" == "/storage" ]]; then
+ # Use the exact path provided by the user without calling realpath
+ STORAGE_PATH="$host_path"
+ elif [[ "$container_path" == "/shared" ]]; then
+ # Use the exact path provided by the user without calling realpath
+ SHARED_PATH="$host_path"
+ fi
+ fi
+ done
- # Automatically resolve and pass host paths for storage and data
- STORAGE_PATH="${HOST_STORAGE_PATH:-$(realpath ./storage)}"
- DATA_PATH="${HOST_DATA_PATH:-$(realpath ./shared)}"
+ # Note: Docker will automatically create these directories if they don't exist
# Only add -e if not already present in args
DOCKER_ARGS=( )
@@ -118,7 +212,7 @@ run_container() {
DOCKER_ARGS+=( -e "$var=$val" )
}
add_env_var HOST_STORAGE_PATH "$STORAGE_PATH"
- add_env_var HOST_DATA_PATH "$DATA_PATH"
+ add_env_var HOST_SHARED_PATH "$SHARED_PATH"
# Detect --name argument and set VM_NAME if not already present
local container_name=""
@@ -165,30 +259,17 @@ case "${1:-help}" in
shift
run_container "$@"
;;
- tunnel)
- # Handle tunnel subcommands
- case "${2:-}" in
- start)
- "$SCRIPT_DIR/src/bin/server.sh" start
- ;;
- stop)
- "$SCRIPT_DIR/src/bin/server.sh" stop
- ;;
- status)
- "$SCRIPT_DIR/src/bin/server.sh" status
- ;;
- *)
- echo "Unknown tunnel subcommand: $2"
- usage
- exit 1
- ;;
- esac
- ;;
-
build)
shift
build_image "$@"
;;
+ push)
+ shift
+ push_image "$@"
+ ;;
+ pull)
+ pull_image
+ ;;
help)
usage
;;
diff --git a/libs/lumier/mount/server.py b/libs/lumier/mount/server.py
deleted file mode 100644
index 464c26ad50..0000000000
--- a/libs/lumier/mount/server.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from flask import Flask
-
-app = Flask(__name__)
-
-def hello_world():
- return 'Hello, World, from VM!'
-
-if __name__ == '__main__':
- app.run(debug=True, host="0.0.0.0", port=5001)
\ No newline at end of file
diff --git a/libs/lumier/src/bin/entry.sh b/libs/lumier/src/bin/entry.sh
index 66a375ad38..712035a037 100755
--- a/libs/lumier/src/bin/entry.sh
+++ b/libs/lumier/src/bin/entry.sh
@@ -35,9 +35,12 @@ fi
if mountpoint -q /storage; then
echo "/storage is mounted"
fi
-if mountpoint -q /data; then
- echo "/data is mounted"
+if mountpoint -q /shared; then
+ echo "/shared is mounted"
fi
+# if mountpoint -q /data; then
+# echo "/data is mounted"
+# fi
# Log startup info
echo "Lumier VM is starting..."
@@ -84,15 +87,5 @@ if [ -n "${VNC_PORT:-}" ] && [ -n "${VNC_PASSWORD:-}" ]; then
echo "noVNC interface available at: http://localhost:8006/vnc.html?password=${VNC_PASSWORD}&autoconnect=true&logging=debug"
fi
-# Run any post-startup hooks
-if [ -d "/run/hooks" ]; then
- for hook in /run/hooks/*; do
- if [ -x "$hook" ]; then
- echo "Running hook: $(basename "$hook")"
- "$hook"
- fi
- done
-fi
-
echo "Lumier is running. Press Ctrl+C to stop."
tail -f /dev/null
\ No newline at end of file
diff --git a/libs/lumier/src/bin/server.sh b/libs/lumier/src/bin/server.sh
deleted file mode 100755
index 5849d667f7..0000000000
--- a/libs/lumier/src/bin/server.sh
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env bash
-
-# Exit on errors, undefined variables, and propagate errors in pipes
-set -euo pipefail
-
-# Source constants if available
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-if [ -f "${SCRIPT_DIR}/../config/constants.sh" ]; then
- source "${SCRIPT_DIR}/../config/constants.sh"
-fi
-
-# Use the tunnel port from constants if available, otherwise default to 8080
-PORT="${TUNNEL_PORT:-8080}"
-TUNNEL_SCRIPT="${SCRIPT_DIR}/tunnel.sh"
-
-# Function to check if the tunnel is active
-is_tunnel_active() {
- if lsof -i TCP:$PORT 2>/dev/null | grep LISTEN > /dev/null; then
- return 0 # Tunnel is active
- else
- return 1 # Tunnel is not active
- fi
-}
-
-# Function to start the tunnel
-start_tunnel() {
- echo "Starting tunnel on port $PORT..."
- if is_tunnel_active; then
- echo "Tunnel is already running on port $PORT."
- return 0
- fi
-
- # Start socat in the background
- socat TCP-LISTEN:$PORT,reuseaddr,fork EXEC:"$TUNNEL_SCRIPT" &
- SOCAT_PID=$!
-
- # Check if the tunnel started successfully
- sleep 1
- if ! is_tunnel_active; then
- echo "Failed to start tunnel on port $PORT."
- return 1
- fi
-
- echo "Tunnel started successfully on port $PORT (PID: $SOCAT_PID)."
- return 0
-}
-
-# Function to stop the tunnel
-stop_tunnel() {
- echo "Stopping tunnel on port $PORT..."
- if ! is_tunnel_active; then
- echo "No tunnel running on port $PORT."
- return 0
- fi
-
- # Find and kill the socat process
- local pid=$(lsof -i TCP:$PORT | grep LISTEN | awk '{print $2}')
- if [ -n "$pid" ]; then
- kill $pid
- echo "Tunnel stopped (PID: $pid)."
- return 0
- else
- echo "Failed to find process using port $PORT."
- return 1
- fi
-}
-
-# Function to check tunnel status
-status_tunnel() {
- if is_tunnel_active; then
- local pid=$(lsof -i TCP:$PORT | grep LISTEN | awk '{print $2}')
- echo "Tunnel is active on port $PORT (PID: $pid)."
- return 0
- else
- echo "No tunnel running on port $PORT."
- return 1
- fi
-}
-
-# Parse command line arguments
-case "${1:-}" in
- start)
- start_tunnel
- ;;
- stop)
- stop_tunnel
- ;;
- restart)
- stop_tunnel
- start_tunnel
- ;;
- status)
- status_tunnel
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|status}"
- exit 1
- ;;
-esac
\ No newline at end of file
diff --git a/libs/lumier/src/bin/tunnel.sh b/libs/lumier/src/bin/tunnel.sh
deleted file mode 100755
index 6de1428209..0000000000
--- a/libs/lumier/src/bin/tunnel.sh
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env bash
-
-# Exit on errors, undefined variables, and propagate errors in pipes
-set -euo pipefail
-
-# Source constants if available
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-if [ -f "${SCRIPT_DIR}/../config/constants.sh" ]; then
- source "${SCRIPT_DIR}/../config/constants.sh"
-fi
-
-# Handle errors and cleanup
-cleanup() {
- local exit_code=$?
- # Clean up any temporary files if they exist
- [ -n "${temp_file:-}" ] && [ -f "$temp_file" ] && rm "$temp_file"
- [ -n "${fifo:-}" ] && [ -p "$fifo" ] && rm "$fifo"
- exit $exit_code
-}
-trap cleanup EXIT INT TERM
-
-log_debug() {
- if [ "${LUMIER_DEBUG:-0}" -eq 1 ]; then
- echo "[DEBUG] $*" >&2
- fi
-}
-
-send_error_response() {
- local status_code=$1
- local message=$2
- echo "HTTP/1.1 $status_code"
- echo "Content-Type: text/plain"
- echo ""
- echo "$message"
- exit 1
-}
-
-# Read the HTTP request line
-read -r request_line
-log_debug "Request: $request_line"
-
-# Read headers and look for Content-Length
-content_length=0
-while IFS= read -r header; do
- [[ $header == $'\r' ]] && break # End of headers
- log_debug "Header: $header"
- if [[ "$header" =~ ^Content-Length:\ ([0-9]+) ]]; then
- content_length="${BASH_REMATCH[1]}"
- fi
-done
-
-# Read the body using the content length
-command=""
-if [ "$content_length" -gt 0 ]; then
- command=$(dd bs=1 count="$content_length" 2>/dev/null)
- log_debug "Received command: $command"
-fi
-
-# Determine the executable and arguments based on the command
-if [[ "$command" == lume* ]]; then
- executable="$(which lume || echo "/usr/local/bin/lume")"
- command_args="${command#lume}" # Remove 'lume' from the command
-elif [[ "$command" == sshpass* ]]; then
- executable="$(which sshpass || echo "/usr/local/bin/sshpass")"
- command_args="${command#sshpass}"
-else
- send_error_response "400 Bad Request" "Unsupported command: $command"
-fi
-
-# Check if executable exists
-if [ ! -x "$executable" ]; then
- send_error_response "500 Internal Server Error" "Executable not found or not executable: $executable"
-fi
-
-# Create a temporary file to store the command
-temp_file=$(mktemp)
-echo "$executable $command_args" > "$temp_file"
-chmod +x "$temp_file"
-
-# Create a FIFO (named pipe) for capturing output
-fifo=$(mktemp -u)
-mkfifo "$fifo"
-
-# Execute the command and pipe its output through awk to ensure line-buffering
-{
- log_debug "Executing: $executable $command_args"
- "$temp_file" 2>&1 | awk '{ print; fflush() }' > "$fifo"
-} &
-
-# Stream the output from the FIFO as an HTTP response
-{
- echo -e "HTTP/1.1 200 OK\r"
- echo -e "Content-Type: text/plain\r"
- echo -e "\r"
- cat "$fifo"
-}
\ No newline at end of file
diff --git a/libs/lumier/src/hooks/on-logon.sh b/libs/lumier/src/hooks/on-logon.sh
index faa817c085..1072da6215 100755
--- a/libs/lumier/src/hooks/on-logon.sh
+++ b/libs/lumier/src/hooks/on-logon.sh
@@ -1,8 +1,9 @@
-setup_script="$DATA_FOLDER_PATH/setup.sh"
+lifecycle_folder="$SHARED_FOLDER_PATH/lifecycle"
+on_logon_script="$lifecycle_folder/on-logon.sh"
-if [ -f "$setup_script" ]; then
- chmod +x "$setup_script"
- source "$setup_script"
+if [ -f "$on_logon_script" ]; then
+ chmod +x "$on_logon_script"
+ source "$on_logon_script"
else
- echo "Setup script not found at: $setup_script"
-fi
\ No newline at end of file
+ echo "No on-logon script found in $lifecycle_folder"
+fi
diff --git a/libs/lumier/src/lib/utils.sh b/libs/lumier/src/lib/utils.sh
index 7d59966950..fb0ee58567 100755
--- a/libs/lumier/src/lib/utils.sh
+++ b/libs/lumier/src/lib/utils.sh
@@ -52,22 +52,43 @@ execute_remote_script() {
echo "VNC password exported to VM: $vnc_password"
- data_folder_path="$VM_SHARED_FILES_PATH/$data_folder"
- echo "Data folder path in VM: $data_folder_path"
+ # Set a default mount point for data in the VM if data_folder is provided
+ if [ -n "$data_folder" ]; then
+ shared_folder_path="/Volumes/My Shared Files"
+ echo "Data folder path in VM: $shared_folder_path"
+ else
+ shared_folder_path=""
+ fi
# Read the script content and prepend the shebang
script_content="#!/usr/bin/env bash\n"
- if [ -n "$data_folder" ]; then
- script_content+="export VNC_PASSWORD='$vnc_password'\n"
- script_content+="export DATA_FOLDER_PATH='$data_folder_path'\n"
+ # Always export VNC_PASSWORD
+ script_content+="export VNC_PASSWORD='$vnc_password'\n"
+ # Export SHARED_FOLDER_PATH only if we have a data folder path
+ if [ -n "$shared_folder_path" ]; then
+ script_content+="export SHARED_FOLDER_PATH='$shared_folder_path'\n"
fi
+
+ # Add debug message to the script to confirm it's being run
+ script_content+="echo \"[DEBUG] Starting on-logon script execution...\"\n"
+
+ # Add the original script content
script_content+="$(<"$script_path")"
-
+
+ # Add more debug messages after script execution
+ script_content+="\necho \"[DEBUG] Finished executing on-logon script.\"\n"
+
+ # Print debug info to the docker logs
+ echo "[DEBUG] Executing remote script with content length: $(echo -n "$script_content" | wc -c) bytes"
+ echo "[DEBUG] Script path: $script_path"
+
# Use a here-document to send the script content
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$host" "bash -s" <<EOF
$script_content
EOF
+ echo "[DEBUG] Script execution completed."
+
# Check the exit status of the sshpass command
if [ $? -ne 0 ]; then
echo "Failed to execute script on remote host $host."
@@ -75,10 +96,6 @@ EOF
fi
}
-# Example usage
-# output = execute_remote_script('192.168.1.100', 'username', 'password', '/path/to/script.sh')
-# print(output)
-
extract_json_field() {
local field_name=$1
local input=$2
diff --git a/libs/lumier/src/lib/vm.sh b/libs/lumier/src/lib/vm.sh
index 5bcd5d7d94..62a627f770 100755
--- a/libs/lumier/src/lib/vm.sh
+++ b/libs/lumier/src/lib/vm.sh
@@ -8,33 +8,45 @@ start_vm() {
fi
# Check if VM exists and its status using JSON format
- VM_INFO=$(lume get "$VM_NAME" --storage "$STORAGE_PATH" -f json 2>&1)
+ VM_INFO=$(lume_get "$VM_NAME" "$STORAGE_PATH")
+ echo "VM_INFO: $VM_INFO"
# Check if VM not found error
if [[ $VM_INFO == *"Virtual machine not found"* ]]; then
IMAGE_NAME="${VERSION##*/}"
- lume pull "$IMAGE_NAME" "$VM_NAME" --storage "$STORAGE_PATH"
+ # Parse registry and organization from VERSION
+ REGISTRY=$(echo $VERSION | cut -d'/' -f1)
+ ORGANIZATION=$(echo $VERSION | cut -d'/' -f2)
+
+ echo "[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] INFO: Pulling VM image $IMAGE_NAME from $REGISTRY/$ORGANIZATION to $STORAGE_PATH"
+ lume_pull "$IMAGE_NAME" "$VM_NAME" "$STORAGE_PATH" "$REGISTRY" "$ORGANIZATION"
else
# Parse the JSON status - check if it contains "status" : "running"
if [[ $VM_INFO == *'"status" : "running"'* ]]; then
lume_stop "$VM_NAME" "$STORAGE_PATH"
- # lume stop "$VM_NAME" --storage "$STORAGE_PATH"
fi
fi
- # Set VM parameters
- lume set "$VM_NAME" --cpu "$CPU_CORES" --memory "${RAM_SIZE}MB" --display "$DISPLAY" --storage "$STORAGE_PATH"
+ # Format memory size for display purposes
+ MEMORY_DISPLAY="$RAM_SIZE"
+ if [[ ! "$RAM_SIZE" == *"GB"* && ! "$RAM_SIZE" == *"MB"* ]]; then
+ MEMORY_DISPLAY="${RAM_SIZE}MB"
+ fi
+
+ # Set VM parameters using the new wrapper function
+ echo "[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] INFO: Updating VM settings cpu=$CPU_CORES name=$VM_NAME location=$STORAGE_PATH display=$DISPLAY memory=$MEMORY_DISPLAY disk_size=unchanged"
+ lume_set "$VM_NAME" "$STORAGE_PATH" "$CPU_CORES" "$RAM_SIZE" "$DISPLAY"
# Fetch VM configuration
- CONFIG_JSON=$(lume get "$VM_NAME" --storage "$STORAGE_PATH" -f json)
+ CONFIG_JSON=$(lume_get "$VM_NAME" "$STORAGE_PATH")
- # Setup data directory args if necessary
+ # Setup shared directory args if necessary
SHARED_DIR_ARGS=""
- if [ -d "/data" ]; then
- if [ -n "$HOST_DATA_PATH" ]; then
- SHARED_DIR_ARGS="--shared-dir=$HOST_DATA_PATH"
+ if [ -d "/shared" ]; then
+ if [ -n "$HOST_SHARED_PATH" ]; then
+ SHARED_DIR_ARGS="--shared-dir=$HOST_SHARED_PATH"
else
- echo "Warning: /data volume exists but HOST_DATA_PATH is not set. Cannot mount volume."
+ echo "Warning: /shared volume exists but HOST_SHARED_PATH is not set. Cannot mount volume."
fi
fi
@@ -49,8 +61,9 @@ start_vm() {
attempt=0
while [ $attempt -lt $max_attempts ]; do
- # Get VM info as JSON
- VM_INFO=$(lume get "$VM_NAME" --storage "$STORAGE_PATH" -f json 2>/dev/null)
+ # Get VM info as JSON using the API function
+ VM_INFO=$(lume_get "$VM_NAME" "$STORAGE_PATH")
+ # VM_INFO=$(lume get "$VM_NAME" --storage "$STORAGE_PATH" -f json 2>/dev/null)
# Check if VM has status 'running'
if [[ $VM_INFO == *'"status" : "running"'* ]]; then
@@ -76,7 +89,6 @@ start_vm() {
exit 1
fi
-
# Parse VNC URL to extract password and port
VNC_PASSWORD=$(echo "$vnc_url" | sed -n 's/.*:\(.*\)@.*/\1/p')
VNC_PORT=$(echo "$vnc_url" | sed -n 's/.*:\([0-9]\+\)$/\1/p')
@@ -90,22 +102,98 @@ start_vm() {
# Execute on-logon.sh if present
on_logon_script="/run/lifecycle/on-logon.sh"
- if [ -f "$on_logon_script" ]; then
- execute_remote_script "$vm_ip" "$HOST_USER" "$HOST_PASSWORD" "$on_logon_script" "$VNC_PASSWORD" "$DATA_FOLDER"
+ # Use HOST_SHARED_PATH which is set earlier in the script
+ echo "Executing on-logon.sh on VM..."
+ execute_remote_script "$vm_ip" "$HOST_USER" "$HOST_PASSWORD" "$on_logon_script" "$VNC_PASSWORD" "$HOST_SHARED_PATH"
+}
+
+# Get VM information using curl
+lume_get() {
+ local vm_name="$1"
+ local storage="$2"
+ local format="${3:-json}"
+ local debug="${4:-false}"
+
+ local api_host="${LUME_API_HOST:-host.docker.internal}"
+ local api_port="${LUME_API_PORT:-3000}"
+
+ # URL encode the storage path for the query parameter
+ # Replace special characters with their URL encoded equivalents
+ local encoded_storage=$(echo "$storage" | sed 's/\//%2F/g' | sed 's/ /%20/g' | sed 's/:/%3A/g')
+
+ # Construct API URL with encoded storage parameter
+ local api_url="http://${api_host}:${api_port}/lume/vms/${vm_name}?storage=${encoded_storage}"
+
+ # Construct the full curl command
+ local curl_cmd="curl --connect-timeout 6000 --max-time 5000 -s '$api_url'"
+
+ # Print debug info
+ if [[ "$debug" == "true" || "$LUMIER_DEBUG" == "1" ]]; then
+ echo "[DEBUG] Calling API: $api_url"
+ echo "[DEBUG] Full curl command: $curl_cmd"
+ fi
+
+ # Always log the curl command before sending
+ echo "[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] INFO: Executing curl request: $api_url"
+
+ # Make the API call
+ local response=$(curl --connect-timeout 6000 \
+ --max-time 5000 \
+ -s \
+ "$api_url")
+
+ # Print the response if debugging is enabled
+ if [[ "$debug" == "true" || "$LUMIER_DEBUG" == "1" ]]; then
+ echo "[DEBUG] API Response:"
+ echo "$response" | jq '.' 2>/dev/null || echo "$response"
fi
+
+ # Output the response
+ echo "$response"
+}
- # The VM is still running because we never killed lume run.
- # If you want to stop the VM at some point, you can kill $LUME_PID or use lume_stop.
+# Set VM properties using curl
+lume_set() {
+ local vm_name="$1"
+ local storage="$2"
+ local cpu="${3:-4}"
+ local memory="${4:-8192}"
+ local display="${5:-1024x768}"
+
+ local api_host="${LUME_API_HOST:-host.docker.internal}"
+ local api_port="${LUME_API_PORT:-3000}"
+
+ # Handle memory format for the API
+ if [[ "$memory" == *"GB"* ]]; then
+ # Already in GB format, keep as is
+ : # No-op
+ elif [[ "$memory" =~ ^[0-9]+$ ]]; then
+ # If memory is a simple number, assume MB and convert to GB
+ memory="$(awk "BEGIN { printf \"%.1f\", $memory/1024 }")GB"
+ fi
+
+ echo "[DEBUG] Formatted memory value: $memory"
+
+ curl --connect-timeout 6000 \
+ --max-time 5000 \
+ -s \
+ -X PATCH \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"cpu\": $cpu,
+ \"memory\": \"$memory\",
+ \"display\": \"$display\",
+ \"storage\": \"$storage\"
+ }" \
+ "http://${api_host}:${api_port}/lume/vms/${vm_name}"
}
stop_vm() {
echo "Stopping VM '$VM_NAME'..."
STORAGE_PATH="$HOST_STORAGE_PATH"
- if [ -z "$STORAGE_PATH" ]; then
- STORAGE_PATH="storage_${VM_NAME}"
- fi
- # Check if the VM exists and is running (use lume get for speed)
- VM_INFO=$(lume get "$VM_NAME" --storage "$STORAGE_PATH" -f json 2>/dev/null)
+ # Check if the VM exists and is running
+ echo "STORAGE_PATH: $STORAGE_PATH"
+ VM_INFO=$(lume_get "$VM_NAME" "$STORAGE_PATH")
if [[ -z "$VM_INFO" || $VM_INFO == *"Virtual machine not found"* ]]; then
echo "VM '$VM_NAME' does not exist."
elif [[ $VM_INFO == *'"status" : "running"'* ]]; then
@@ -119,7 +207,15 @@ stop_vm() {
}
is_vm_running() {
- lume ls | grep -q "$VM_NAME"
+ # Check VM status using the API function
+ local vm_info
+ vm_info=$(lume_get "$VM_NAME" "$HOST_STORAGE_PATH")
+ if [[ $vm_info == *'"status" : "running"'* ]]; then
+ return 0 # Running
+ else
+ return 1 # Not running or doesn't exist
+ fi
+ # lume ls | grep -q "$VM_NAME" # Old CLI check
}
# Stop VM with storage location specified using curl
@@ -134,6 +230,36 @@ lume_stop() {
"http://host.docker.internal:3000/lume/vms/${vm_name}/stop"
}
+# Pull a VM image using curl
+lume_pull() {
+ local image="$1" # Image name with tag
+ local vm_name="$2" # Name for the new VM
+ local storage="$3" # Storage location
+ local registry="${4:-ghcr.io}" # Registry, default is ghcr.io
+ local organization="${5:-trycua}" # Organization, default is trycua
+
+ local api_host="${LUME_API_HOST:-host.docker.internal}"
+ local api_port="${LUME_API_PORT:-3000}"
+
+ echo "[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] INFO: Pulling image $image from $registry/$organization to $storage"
+
+ # Pull image via API
+ curl --connect-timeout 6000 \
+ --max-time 5000 \
+ -s \
+ -X POST \
+ -H "Content-Type: application/json" \
+ -d "{
+ \"image\": \"$image\",
+ \"name\": \"$vm_name\",
+ \"registry\": \"$registry\",
+ \"organization\": \"$organization\",
+ \"storage\": \"$storage\"
+ }" \
+ "http://${api_host}:${api_port}/lume/pull"
+}
+
+
# Run VM with VNC client started and shared directory using curl
lume_run() {
# Parse args
@@ -175,7 +301,5 @@ lume_run() {
-H 'Content-Type: application/json' \
-d '$json_body' \
http://host.docker.internal:3000/lume/vms/$vm_name/run"
- echo "[lume_run] Running:"
- echo "$curl_cmd"
eval "$curl_cmd"
}
\ No newline at end of file