Skip to content

Commit acfdc27

Browse files
Improve docker build (#142)
* Improve docker build * Change * Fix
1 parent ff354c9 commit acfdc27

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ yarn-error.log
1313
.next
1414
out
1515

16-
# Python
16+
# Python cache files (but keep api/ directory)
1717
__pycache__/
1818
*.py[cod]
1919
*$py.class
@@ -34,6 +34,9 @@ var/
3434
*.egg-info/
3535
.installed.cfg
3636
*.egg
37+
# Keep api/ directory but exclude cache
38+
api/__pycache__/
39+
api/*.pyc
3740

3841
# Environment variables
3942
# .env is now allowed to be included in the build

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ RUN npm ci --legacy-peer-deps
1010
FROM node_base AS node_builder
1111
WORKDIR /app
1212
COPY --from=node_deps /app/node_modules ./node_modules
13-
COPY --exclude=./api . .
13+
# Copy only necessary files for Next.js build
14+
COPY package.json package-lock.json next.config.ts tsconfig.json tailwind.config.js postcss.config.mjs ./
15+
COPY src/ ./src/
16+
COPY public/ ./public/
17+
# Increase Node.js memory limit for build and disable telemetry
18+
ENV NODE_OPTIONS="--max-old-space-size=4096"
19+
ENV NEXT_TELEMETRY_DISABLED=1
1420
RUN NODE_ENV=production npm run build
1521

1622
FROM python:3.11-slim AS py_deps

api/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
logger.info(f"Starting Streaming API on port {port}")
4949

5050
# Run the FastAPI app with uvicorn
51+
# Disable reload in production/Docker environment
52+
is_development = os.environ.get("NODE_ENV") != "production"
5153
uvicorn.run(
5254
"api.api:app",
5355
host="0.0.0.0",
5456
port=port,
55-
reload=True
57+
reload=is_development
5658
)

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ version: '3.8'
22

33
services:
44
deepwiki:
5-
build: .
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
68
ports:
79
- "${PORT:-8001}:${PORT:-8001}" # API port
810
- "3000:3000" # Next.js port
@@ -12,5 +14,9 @@ services:
1214
- PORT=${PORT:-8001}
1315
- NODE_ENV=production
1416
- SERVER_BASE_URL=http://localhost:${PORT:-8001}
17+
- NEXT_PUBLIC_SERVER_BASE_URL=http://localhost:${PORT:-8001}
1518
volumes:
1619
- ~/.adalflow:/root/.adalflow # Persist repository and embedding data
20+
# Resource limits for docker-compose up (not Swarm mode)
21+
mem_limit: 6g
22+
mem_reservation: 2g

next.config.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:
55
const nextConfig: NextConfig = {
66
/* config options here */
77
output: 'standalone',
8+
// Optimize build for Docker
9+
experimental: {
10+
optimizePackageImports: ['@mermaid-js/mermaid', 'react-syntax-highlighter'],
11+
},
12+
// Reduce memory usage during build
13+
webpack: (config, { isServer }) => {
14+
if (!isServer) {
15+
config.resolve.fallback = {
16+
...config.resolve.fallback,
17+
fs: false,
18+
};
19+
}
20+
// Optimize bundle size
21+
config.optimization = {
22+
...config.optimization,
23+
splitChunks: {
24+
chunks: 'all',
25+
cacheGroups: {
26+
vendor: {
27+
test: /[\\/]node_modules[\\/]/,
28+
name: 'vendors',
29+
chunks: 'all',
30+
},
31+
},
32+
},
33+
};
34+
return config;
35+
},
836
async rewrites() {
937
return [
1038
{

0 commit comments

Comments
 (0)