Skip to content

Commit 308b6b0

Browse files
committed
Add docker debug scripts for npx UX
1 parent 7c759a0 commit 308b6b0

File tree

5 files changed

+219
-3
lines changed

5 files changed

+219
-3
lines changed

scripts/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Scripts
2+
3+
## Development Scripts
4+
5+
### `start-dev-services.sh`
6+
Starts development services (Ollama and Qdrant) via Docker containers.
7+
8+
### `stop-dev-services.sh`
9+
Stops development services (Ollama and Qdrant) Docker containers.
10+
11+
## Git Hooks
12+
13+
### `pre-push`
14+
Git pre-push hook that runs before pushing changes to the repository.
15+
16+
## Testing
17+
18+
### `docker-debug/`
19+
Docker-based testing environment for debugging directory-indexer CLI functionality. See [docker-debug/README.md](./docker-debug/README.md) for complete setup and usage instructions.
20+
21+
Quick start:
22+
```bash
23+
./scripts/docker-debug/setup-debug-container.sh
24+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:22.04
2+
3+
# Install Node.js and npm
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
ca-certificates \
7+
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
8+
&& apt-get install -y nodejs \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Create working directory
12+
WORKDIR /app
13+
14+
# Keep container running
15+
CMD ["tail", "-f", "/dev/null"]

scripts/docker-debug/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Docker Debug Container
2+
3+
Container setup for testing and debugging directory-indexer CLI functionality with live code iteration.
4+
5+
## Purpose
6+
7+
This container allows testing the CLI in a clean Ubuntu environment with Node.js while mounting the local `dist/` folder for live code updates. Useful for:
8+
9+
- Testing npm package installation and CLI functionality
10+
- Debugging CLI entry point and symlink issues
11+
- Validating commands work as expected for end users
12+
- Testing both `directory-indexer` and `npx directory-indexer` usage
13+
14+
## Prerequisites
15+
16+
Start the development services first:
17+
18+
```bash
19+
./scripts/start-dev-services.sh
20+
```
21+
22+
This starts Ollama and Qdrant via Docker, which the CLI needs for indexing and search operations.
23+
24+
## Setup
25+
26+
**Quick setup with helper script:**
27+
```bash
28+
./scripts/docker-debug/setup-debug-container.sh
29+
```
30+
31+
**Manual setup:**
32+
33+
1. **Build the test container:**
34+
```bash
35+
docker build -f scripts/docker-debug/Dockerfile.test -t test-directory-indexer .
36+
```
37+
38+
2. **Set up debug container:**
39+
```bash
40+
# Clean up any existing container
41+
docker stop test-directory-indexer 2>/dev/null || true
42+
docker rm test-directory-indexer 2>/dev/null || true
43+
44+
# Run container without dist mount first
45+
docker run -d --name test-directory-indexer --network host \
46+
-v $(pwd)/tests/test_data:/test-data \
47+
test-directory-indexer
48+
49+
# Install the package to create proper structure
50+
docker exec test-directory-indexer npm install -g directory-indexer@latest
51+
52+
# Stop and recreate with dist mounted for live development
53+
docker stop test-directory-indexer
54+
docker rm test-directory-indexer
55+
docker run -d --name test-directory-indexer --network host \
56+
-v $(pwd)/dist:/usr/lib/node_modules/directory-indexer/dist \
57+
-v $(pwd)/tests/test_data:/test-data \
58+
test-directory-indexer
59+
60+
# Fix permissions on mounted CLI
61+
docker exec test-directory-indexer chmod +x /usr/lib/node_modules/directory-indexer/dist/cli.js
62+
```
63+
64+
## Testing
65+
66+
Test CLI commands:
67+
68+
```bash
69+
# Help and version
70+
docker exec test-directory-indexer directory-indexer --help
71+
docker exec test-directory-indexer directory-indexer --version
72+
73+
# Status and indexing
74+
docker exec test-directory-indexer directory-indexer status
75+
docker exec test-directory-indexer directory-indexer index /test-data
76+
docker exec test-directory-indexer directory-indexer search "test query"
77+
78+
# Test with npx
79+
docker exec test-directory-indexer npx directory-indexer --help
80+
docker exec test-directory-indexer npx directory-indexer status
81+
```
82+
83+
## Live Development
84+
85+
After making changes to source code:
86+
87+
1. **Rebuild locally:**
88+
```bash
89+
npm run build
90+
```
91+
92+
2. **Test immediately in container** (no restart needed):
93+
```bash
94+
docker exec test-directory-indexer directory-indexer --help
95+
```
96+
97+
The mounted `dist/` folder allows immediate testing of changes without rebuilding the container.
98+
99+
## Cleanup
100+
101+
```bash
102+
docker stop test-directory-indexer
103+
docker rm test-directory-indexer
104+
```
105+
106+
## Network Setup
107+
108+
The container uses `--network host` to access:
109+
- **Qdrant**: `localhost:6333`
110+
- **Ollama**: `localhost:11434`
111+
112+
Both services must be running on the host before testing CLI commands that require them.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Setup debug container for directory-indexer CLI testing
4+
set -e
5+
6+
echo "Setting up debug container for directory-indexer CLI testing..."
7+
8+
# Get script directory and project root
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
11+
12+
cd "$PROJECT_ROOT"
13+
14+
# Clean up any existing container gracefully
15+
echo "Cleaning up existing debug container..."
16+
if docker ps -a --format '{{.Names}}' | grep -q "^test-directory-indexer$"; then
17+
echo " Stopping existing container..."
18+
docker stop test-directory-indexer 2>/dev/null || true
19+
echo " Removing existing container..."
20+
docker rm test-directory-indexer 2>/dev/null || true
21+
fi
22+
23+
# Build the test container if it doesn't exist
24+
if ! docker images | grep -q test-directory-indexer; then
25+
echo "Building test container..."
26+
docker build -f scripts/docker-debug/Dockerfile.test -t test-directory-indexer .
27+
fi
28+
29+
# Run container without dist mount first
30+
echo "Starting container and installing package..."
31+
docker run -d --name test-directory-indexer --network host \
32+
-v "$(pwd)/tests/test_data:/test-data" \
33+
test-directory-indexer
34+
35+
# Install the package to create proper structure
36+
docker exec test-directory-indexer npm install -g directory-indexer@latest
37+
38+
# Stop and recreate with dist mounted for live development
39+
echo "Recreating container with live dist mount..."
40+
docker stop test-directory-indexer
41+
docker rm test-directory-indexer
42+
docker run -d --name test-directory-indexer --network host \
43+
-v "$(pwd)/dist:/usr/lib/node_modules/directory-indexer/dist" \
44+
-v "$(pwd)/tests/test_data:/test-data" \
45+
test-directory-indexer
46+
47+
# Reinstall package to recreate symlinks with mounted dist
48+
echo "Recreating symlinks with mounted dist..."
49+
docker exec test-directory-indexer npm install -g directory-indexer@latest 2>/dev/null || true
50+
51+
# Fix permissions on mounted CLI
52+
docker exec test-directory-indexer chmod +x /usr/lib/node_modules/directory-indexer/dist/cli.js
53+
54+
echo ""
55+
echo "✅ Debug container ready!"
56+
echo ""
57+
echo "Test commands:"
58+
echo " docker exec test-directory-indexer directory-indexer --help"
59+
echo " docker exec test-directory-indexer directory-indexer status"
60+
echo " docker exec test-directory-indexer directory-indexer index /test-data"
61+
echo ""
62+
echo "After making changes to src/cli.ts:"
63+
echo " npm run build"
64+
echo " docker exec test-directory-indexer directory-indexer --help"
65+
echo ""

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
import { Command } from 'commander';
4+
import { fileURLToPath } from 'url';
45
import { indexDirectories } from './indexing.js';
56
import { searchContent, findSimilarFiles, getFileContent } from './search.js';
67
import { loadConfig } from './config.js';
@@ -159,6 +160,5 @@ export async function main() {
159160
await program.parseAsync();
160161
}
161162

162-
if (import.meta.url === `file://${process.argv[1]}`) {
163-
main().catch(console.error);
164-
}
163+
// For CLI scripts, we can call main directly since this file is only used as an executable
164+
main().catch(console.error);

0 commit comments

Comments
 (0)