Skip to content

Commit a9e46cf

Browse files
committed
docker
1 parent 237d85c commit a9e46cf

File tree

6 files changed

+353
-220
lines changed

6 files changed

+353
-220
lines changed

.dockerignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Dependencies
2+
node_modules
3+
webui/node_modules
4+
5+
# Models (mounted as volume)
6+
models
7+
8+
# Git
9+
.git
10+
.gitignore
11+
.github
12+
13+
# IDE
14+
.vscode
15+
*.swp
16+
*.swo
17+
*~
18+
19+
# Environment
20+
.env
21+
.env.local
22+
.env.*.local
23+
24+
# Logs
25+
logs
26+
*.log
27+
npm-debug.log*
28+
29+
# OS
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Build
34+
dist
35+
build
36+
37+
# Other
38+
.aider*
39+
memory.json
40+
.gemini

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build stage
4+
FROM node:20-slim AS builder
5+
6+
# Set working directory
7+
WORKDIR /app
8+
9+
# Copy package files
10+
COPY package*.json ./
11+
COPY webui/package*.json ./webui/
12+
13+
# Install dependencies
14+
RUN npm ci --omit=dev && \
15+
cd webui && \
16+
npm ci --omit=dev
17+
18+
# Production stage
19+
FROM node:20-slim
20+
21+
# Install required system dependencies for ONNX Runtime
22+
RUN apt-get update && \
23+
apt-get install -y --no-install-recommends \
24+
ca-certificates \
25+
wget \
26+
&& rm -rf /var/lib/apt/lists/*
27+
28+
# Set working directory
29+
WORKDIR /app
30+
31+
# Copy dependencies from builder
32+
COPY --from=builder /app/node_modules ./node_modules
33+
COPY --from=builder /app/webui/node_modules ./webui/node_modules
34+
35+
# Copy application code
36+
COPY . .
37+
38+
# Create models directory with proper permissions
39+
RUN mkdir -p models && \
40+
chown -R node:node /app
41+
42+
# Switch to non-root user
43+
USER node
44+
45+
# Expose port for Web UI
46+
EXPOSE 3000
47+
48+
# Default command runs the Web UI server
49+
CMD ["node", "webui/server.js"]

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,63 @@ _how it works_
3333
npm install semantic-chunking
3434
```
3535

36+
## Docker Usage
37+
38+
The easiest way to run semantic-chunking is using Docker Compose:
39+
40+
### Docker Compose (Recommended)
41+
42+
```bash
43+
# Start the Web UI server
44+
npm run docker:compose:up
45+
46+
# Access the Web UI at http://localhost:3000
47+
48+
# Stop the server
49+
npm run docker:compose:down
50+
```
51+
52+
The `docker-compose.yml` configuration includes:
53+
- Port mapping: `3000:3000` for the Web UI
54+
- Volume mapping: `./models` directory is mounted to persist downloaded embedding models between container restarts
55+
- Health checks and auto-restart policies
56+
57+
### Alternative Docker Commands
58+
59+
```bash
60+
# Build the Docker image
61+
npm run docker:build
62+
63+
# Run the container with models volume
64+
npm run docker:run
65+
66+
# Or use docker-compose directly
67+
docker-compose up -d
68+
```
69+
70+
### Using the Library in Docker
71+
72+
To use the chunking functions directly (not just the Web UI):
73+
74+
```bash
75+
# Execute chunkit example inside the container
76+
docker-compose exec semantic-chunking node example/example-chunkit.js
77+
78+
# Execute cramit example
79+
docker-compose exec semantic-chunking node example/example-cramit.js
80+
81+
# Execute sentenceit example
82+
docker-compose exec semantic-chunking node example/example-sentenceit.js
83+
```
84+
85+
### About the Models Volume
86+
87+
The `./models` directory is mounted as a volume to persist downloaded ONNX embedding models. Models are automatically downloaded on first use and can range from 23MB to 548MB depending on which model you choose. Persisting this directory means:
88+
- Models are downloaded only once
89+
- Faster container restarts
90+
- Models survive container updates
91+
- You can pre-download models using `npm run download-models` before running Docker
92+
3693
## Usage
3794

3895
Basic usage:

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.8'
2+
3+
services:
4+
semantic-chunking:
5+
build: .
6+
image: semantic-chunking:latest
7+
container_name: semantic-chunking
8+
ports:
9+
- "3000:3000"
10+
volumes:
11+
# Persist downloaded models between container restarts
12+
- ./models:/app/models
13+
environment:
14+
- NODE_ENV=production
15+
- PORT=3000
16+
restart: unless-stopped
17+
healthcheck:
18+
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/"]
19+
interval: 30s
20+
timeout: 10s
21+
retries: 3
22+
start_period: 40s

0 commit comments

Comments
 (0)