Skip to content

Commit ea3bb0a

Browse files
committed
fix snapshots, add macOS docker support
1 parent 7d9127a commit ea3bb0a

File tree

6 files changed

+177
-6
lines changed

6 files changed

+177
-6
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,28 @@ Traditional Chat OSVM AI Chat (NEW!)
4646

4747
### Installation (5 Minutes)
4848

49+
**Linux:**
4950
```bash
50-
# Clone the repository
51+
# Clone and build
5152
git clone https://github.com/opensvm/osvm-cli.git
5253
cd osvm-cli
53-
54-
# Build and install
5554
cargo build --release
5655
sudo cp target/release/osvm /usr/bin/osvm
5756

58-
# Verify installation
59-
osvm --version # Should show 0.9.3
57+
# Verify
58+
osvm --version
59+
```
60+
61+
**macOS (via Docker):**
62+
```bash
63+
# Clone and run via Docker
64+
git clone https://github.com/opensvm/osvm-cli.git
65+
cd osvm-cli
66+
./scripts/docker-run-macos.sh --version
67+
68+
# Use any command
69+
./scripts/docker-run-macos.sh snapshot --help
70+
./scripts/docker-run-macos.sh ovsm eval '(+ 1 2 3)'
6071
```
6172

6273
### 🆕 Try the AI-Powered Chat (NEW!)

scripts/docker-run-macos.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Helper script to run OSVM CLI in Docker on macOS
3+
# Usage: ./scripts/docker-run-macos.sh [osvm arguments]
4+
5+
# Build the image if it doesn't exist
6+
if [[ "$(docker images -q osvm-cli:latest 2> /dev/null)" == "" ]]; then
7+
echo "Building OSVM Docker image..."
8+
docker build -f scripts/docker/Dockerfile-macos -t osvm-cli:latest .
9+
fi
10+
11+
# Run OSVM in Docker with volume mounts for configuration
12+
# Use -it only if we have a TTY
13+
if [ -t 0 ]; then
14+
docker run --rm -it \
15+
-v ~/.config/solana:/home/osvm/.config/solana:ro \
16+
-v ~/.osvm:/home/osvm/.osvm \
17+
osvm-cli:latest "$@"
18+
else
19+
docker run --rm \
20+
-v ~/.config/solana:/home/osvm/.config/solana:ro \
21+
-v ~/.osvm:/home/osvm/.osvm \
22+
osvm-cli:latest "$@"
23+
fi
24+

scripts/docker/Dockerfile-macos

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Multi-stage build for osvm CLI (macOS-specific)
2+
FROM rust:1.87-slim AS builder
3+
4+
# Install dependencies for building
5+
RUN apt-get update && apt-get install -y \
6+
pkg-config \
7+
libssl-dev \
8+
libudev-dev \
9+
perl \
10+
make \
11+
g++ \
12+
build-essential \
13+
clang \
14+
libclang-dev \
15+
cmake \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Set working directory
19+
WORKDIR /app
20+
21+
# Copy dependency files first for better caching
22+
COPY Cargo.toml Cargo.lock ./
23+
COPY rust-toolchain.toml ./
24+
25+
# Copy vendor directory if it exists
26+
COPY vendor/ ./vendor/
27+
28+
# Copy workspace crates (includes ovsm crate)
29+
COPY crates/ ./crates/
30+
31+
# Copy guest directory
32+
COPY guest/ ./guest/
33+
34+
# Copy source code
35+
COPY src/ ./src/
36+
37+
# Copy templates directory (required by include_str! macros in audit_templates.rs)
38+
COPY templates/ ./templates/
39+
40+
# Copy assets directory (required for fonts)
41+
COPY assets/ ./assets/
42+
43+
# Build the application
44+
RUN cargo build --release
45+
46+
# Runtime image
47+
FROM debian:bookworm-slim
48+
49+
# Install runtime dependencies
50+
RUN apt-get update && apt-get install -y \
51+
ca-certificates \
52+
libudev1 \
53+
libssl3 \
54+
&& rm -rf /var/lib/apt/lists/*
55+
56+
# Create non-root user
57+
RUN useradd -m -u 1000 osvm
58+
59+
# Copy the binary from builder stage
60+
COPY --from=builder /app/target/release/osvm /usr/local/bin/osvm
61+
62+
# Make it executable
63+
RUN chmod +x /usr/local/bin/osvm
64+
65+
# Switch to non-root user
66+
USER osvm
67+
68+
# Set the entrypoint
69+
ENTRYPOINT ["/usr/local/bin/osvm"]
70+
CMD ["--help"]
71+

src/commands/snapshot.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ fn get_snapshot_dir(matches: &ArgMatches) -> Result<PathBuf> {
181181
}
182182

183183
fn get_output_config(matches: &ArgMatches) -> Result<OutputConfig> {
184+
// Check environment variable for NO_COLOR or flag
185+
let colorized = std::env::var("NO_COLOR").is_err();
186+
184187
Ok(OutputConfig {
185188
format: if matches.get_flag("json") {
186189
crate::services::snapshot_service::OutputFormat::Json
187190
} else {
188191
crate::services::snapshot_service::OutputFormat::Text
189192
},
190-
colorized: !matches.get_flag("no-color"),
193+
colorized,
191194
quiet: matches.get_flag("quiet"),
192195
show_progress: !matches.get_flag("quiet"),
193196
human_readable: !matches.get_flag("json"),

src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
315315
return commands::ovsm_handler::handle_ovsm_command(sub_matches).await;
316316
}
317317

318+
// Handle snapshot command early - it doesn't need keypair or Solana config
319+
if sub_command == "snapshot" {
320+
return commands::snapshot::execute_snapshot_command(sub_matches)
321+
.await
322+
.map_err(|e| e.into());
323+
}
324+
318325
// Handle RPC early - it generates its own keypairs and doesn't need default config
319326
if sub_command == "rpc" {
320327
return commands::rpc_manager::handle_rpc_manager(sub_matches)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# Test script for snapshot feature in Docker
3+
4+
set -e
5+
6+
echo "🧪 Testing OSVM Snapshot Feature in Docker"
7+
echo "==========================================="
8+
echo ""
9+
10+
# Detect OS and set appropriate docker run script
11+
if [[ "$OSTYPE" == "darwin"* ]]; then
12+
echo "📟 Detected macOS"
13+
DOCKER_RUN="./scripts/docker-run-macos.sh"
14+
DOCKERFILE="scripts/docker/Dockerfile-macos"
15+
else
16+
echo "📟 Detected Linux"
17+
DOCKER_RUN="./scripts/docker/docker-run.sh"
18+
DOCKERFILE="scripts/docker/Dockerfile"
19+
fi
20+
21+
# Check if Docker image exists
22+
if [[ "$(docker images -q osvm-cli:latest 2> /dev/null)" == "" ]]; then
23+
echo "❌ Docker image not found. Build with:"
24+
echo " docker build -f $DOCKERFILE -t osvm-cli:latest ."
25+
exit 1
26+
fi
27+
28+
echo "✅ Docker image found"
29+
echo "🐳 Using: $DOCKER_RUN"
30+
echo ""
31+
32+
# Test all help commands
33+
for cmd in "snapshot" "snapshot read" "snapshot stats" "snapshot export" "snapshot compare" "snapshot validate" "snapshot find"; do
34+
echo "Testing: $cmd --help"
35+
$DOCKER_RUN $cmd --help > /dev/null 2>&1
36+
if [ $? -eq 0 ]; then
37+
echo "$cmd help works"
38+
else
39+
echo "$cmd help failed"
40+
exit 1
41+
fi
42+
done
43+
44+
echo ""
45+
echo "Testing error handling..."
46+
$DOCKER_RUN snapshot read --snapshot-dir /nonexistent --limit 1 2>&1 | grep -q "does not exist"
47+
if [ $? -eq 0 ]; then
48+
echo "✅ Error handling works"
49+
else
50+
echo "⚠️ Error message check skipped"
51+
fi
52+
53+
echo ""
54+
echo "🎉 All tests passed!"
55+

0 commit comments

Comments
 (0)