@@ -9,22 +9,11 @@ ARG TARGETARCH
99
1010ENV LANG=C.UTF-8
1111ENV LC_ALL=C.UTF-8
12-
12+ # Install only runtime dependencies
1313RUN apk update && apk add --no-cache \
14- bash \
15- build-base \
16- ca-certificates \
17- curl \
18- make \
19- node-gyp \
2014 nodejs \
21- npm \
22- openssl \
23- python3 \
24- sqlite-dev \
25- unzip \
15+ ca-certificates \
2616 && update-ca-certificates \
27- && rm -rf /var/cache/apk/*
2817
2918WORKDIR /app
3019
@@ -33,30 +22,39 @@ COPY package.json package-lock.json tsconfig.json ./
3322COPY src/ ./src/
3423
3524# Install dependencies and build
36- RUN --mount=type=cache,target=/root/.npm \
37- npm install typescript && \
38- npm ci --only=production && \
39- npm install --save-dev typescript && \
40- npm run build
41-
42- # Production stage
43- FROM cgr.dev/chainguard/wolfi-base:latest AS production
44-
45- # Import build arguments for target platform
46- ARG TARGETPLATFORM
47- ARG TARGETOS
48- ARG TARGETARCH
49-
50- ENV LANG=C.UTF-8
51- ENV LC_ALL=C.UTF-8
52- ENV NODE_ENV=production
53-
54- # Install only runtime dependencies
55- RUN apk update && apk add --no-cache \
56- nodejs \
57- ca-certificates \
58- sqlite \
59- && update-ca-certificates
25+ RUN echo "Building for platform: $TARGETPLATFORM" && \
26+ apk update && apk add --no-cache \
27+ bash \
28+ build-base \
29+ ca-certificates \
30+ curl \
31+ make \
32+ node-gyp \
33+ nodejs \
34+ npm \
35+ openssl \
36+ python3 \
37+ sqlite-dev \
38+ unzip && \
39+ echo "Installing dependencies" && \
40+ npm ci && \
41+ echo "Building application" && \
42+ npm run build && \
43+ echo "Cleaning up build... " && \
44+ npm prune --production && \
45+ apk del \
46+ bash \
47+ build-base \
48+ curl \
49+ make \
50+ node-gyp \
51+ openssl \
52+ python3 \
53+ sqlite-dev \
54+ unzip && \
55+ rm -rf /root/.npm /root/.node-gyp /root/.cache /tmp/* /var/tmp/* && \
56+ rm -rf /app/src /app/package.json /app/package-lock.json /app/tsconfig.json \
57+ echo "Build completed successfully"
6058
6159# Create non-root user
6260RUN addgroup -g 1001 -S nodejs && \
@@ -85,11 +83,6 @@ RUN for file in /app/build/*.db; do echo "Checksum for $file:";sha256sum "$file"
8583# Ensure the app directory is owned by the non-root user
8684RUN chown -R kagent:nodejs /app
8785
88- # Copy built application and production dependencies from builder stage
89- COPY --from=builder --chown=kagent:nodejs /app/build ./build
90- COPY --from=builder --chown=kagent:nodejs /app/node_modules ./node_modules
91- COPY --from=builder --chown=kagent:nodejs /app/package.json ./
92-
9386LABEL org.opencontainers.image.source=https://github.com/kagent-dev/doc2vec
9487LABEL org.opencontainers.image.description="Kagent Doc2Vec MCP"
9588LABEL org.opencontainers.image.authors="Kagent Creators 🤖"
0 commit comments