ffc3a76
commit ffc3a76
2 files changed
+110 -0
Showing 2 changed files+110-0
▼opengrammar/backend/Dockerfile
+41-0
| @@ -0,0 +1,41 @@ | ||
1 | +# OpenGrammar Backend Docker Image | |
2 | +FROM node:20-alpine AS builder | |
3 | + | |
4 | +WORKDIR /app | |
5 | + | |
6 | +# Copy package files | |
7 | +COPY package*.json ./ | |
8 | +COPY tsconfig.json ./ | |
9 | + | |
10 | +# Install dependencies | |
11 | +RUN npm ci --only=production | |
12 | + | |
13 | +# Copy source code | |
14 | +COPY src/ ./src/ | |
15 | + | |
16 | +# Build check (optional, for validation) | |
17 | +RUN npx tsc --noEmit | |
18 | + | |
19 | +# Production image | |
20 | +FROM node:20-alpine | |
21 | + | |
22 | +WORKDIR /app | |
23 | + | |
24 | +# Install dumb-init for proper signal handling | |
25 | +RUN apk add --no-cache dumb-init | |
26 | + | |
27 | +# Copy built files from builder | |
28 | +COPY --from=builder /app/node_modules ./node_modules | |
29 | +COPY --from=builder /app/src ./src | |
30 | +COPY --from=builder /app/package.json ./ | |
31 | + | |
32 | +# Expose port | |
33 | +EXPOSE 8787 | |
34 | + | |
35 | +# Health check | |
36 | +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
37 | + CMD wget --no-verbose --tries=1 --spider http://localhost:8787/health || exit 1 | |
38 | + | |
39 | +# Run with dumb-init for proper signal handling | |
40 | +ENTRYPOINT ["dumb-init", "--"] | |
41 | +CMD ["node", "--import", "tsx", "src/index.ts"] | |
0 | 42 | |
▼opengrammar/docker-compose.yml
+69-0
| @@ -0,0 +1,69 @@ | ||
1 | +version: '3.8' | |
2 | + | |
3 | +services: | |
4 | + # OpenGrammar Backend API | |
5 | + opengrammar-backend: | |
6 | + build: | |
7 | + context: ./backend | |
8 | + dockerfile: Dockerfile | |
9 | + ports: | |
10 | + - "8787:8787" | |
11 | + environment: | |
12 | + - NODE_ENV=production | |
13 | + - PORT=8787 | |
14 | + restart: unless-stopped | |
15 | + healthcheck: | |
16 | + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8787/health"] | |
17 | + interval: 30s | |
18 | + timeout: 10s | |
19 | + retries: 3 | |
20 | + start_period: 10s | |
21 | + networks: | |
22 | + - opengrammar-network | |
23 | + | |
24 | + # Ollama for local LLM inference (optional - comment out if using cloud APIs) | |
25 | + ollama: | |
26 | + image: ollama/ollama:latest | |
27 | + ports: | |
28 | + - "11434:11434" | |
29 | + volumes: | |
30 | + - ollama-data:/root/.ollama | |
31 | + restart: unless-stopped | |
32 | + # Uncomment below for GPU support (NVIDIA) | |
33 | + # deploy: | |
34 | + # resources: | |
35 | + # reservations: | |
36 | + # devices: | |
37 | + # - driver: nvidia | |
38 | + # count: 1 | |
39 | + # capabilities: [gpu] | |
40 | + networks: | |
41 | + - opengrammar-network | |
42 | + profiles: | |
43 | + - local-llm | |
44 | + | |
45 | + # Optional: Auto-pull models on startup | |
46 | + ollama-init: | |
47 | + image: ollama/ollama:latest | |
48 | + volumes: | |
49 | + - ollama-data:/root/.ollama | |
50 | + entrypoint: > | |
51 | + sh -c ' | |
52 | + sleep 5 && | |
53 | + ollama pull qwen2.5:0.5b && | |
54 | + ollama pull qwen2.5:1.5b | |
55 | + ' | |
56 | + depends_on: | |
57 | + - ollama | |
58 | + networks: | |
59 | + - opengrammar-network | |
60 | + profiles: | |
61 | + - local-llm | |
62 | + | |
63 | +volumes: | |
64 | + ollama-data: | |
65 | + driver: local | |
66 | + | |
67 | +networks: | |
68 | + opengrammar-network: | |
69 | + driver: bridge | |
0 | 70 | |