11# Build stage
2- FROM --platform=linux/$BUILDARCH cgr.dev/chainguard/wolfi-base:latest AS builder
2+ FROM --platform=$BUILDPLATFORM cgr.dev/chainguard/wolfi-base:latest AS builder
3+
4+ # Import build arguments for cross-compilation
5+ ARG BUILDPLATFORM
6+ ARG TARGETPLATFORM
7+ ARG TARGETOS
8+ ARG TARGETARCH
39
410ENV LANG=C.UTF-8
511ENV LC_ALL=C.UTF-8
12+ ENV NODE_ENV=production
13+ ENV NODE_PATH=/app/node_modules
614
15+ # Install only runtime dependencies
716RUN apk update && apk add --no-cache \
8- bash \
9- build-base \
10- ca-certificates \
11- curl \
12- make \
13- node-gyp \
1417 nodejs \
15- npm \
16- openssl \
17- python3 \
18- sqlite-dev \
19- unzip \
20- && update-ca-certificates \
21- && rm -rf /var/cache/apk/*
18+ ca-certificates \
19+ && update-ca-certificates
2220
2321WORKDIR /app
2422
@@ -27,33 +25,44 @@ COPY package.json package-lock.json tsconfig.json ./
2725COPY src/ ./src/
2826
2927# Install dependencies and build
30- RUN --mount=type=cache,target=/root/.npm \
31- npm install typescript && \
32- npm ci --only=production && \
33- npm install --save-dev typescript && \
34- npm run build
35-
36- # Production stage
37- FROM cgr.dev/chainguard/wolfi-base:latest AS production
38-
39- ENV LANG=C.UTF-8
40- ENV LC_ALL=C.UTF-8
41- ENV NODE_ENV=production
42-
43- # Install only runtime dependencies
44- RUN apk update && apk add --no-cache \
45- nodejs \
46- ca-certificates \
47- sqlite \
48- && update-ca-certificates \
49- && rm -rf /var/cache/apk/*
50-
51- # Create non-root user
52- RUN addgroup -g 1001 -S nodejs && \
53- adduser -S kagent -u 1001 -G nodejs && \
54- mkdir -p /app/build
55-
56- WORKDIR /app
28+ RUN echo "Building for platform: $TARGETPLATFORM" && \
29+ apk update && apk add --no-cache \
30+ bash \
31+ build-base \
32+ ca-certificates \
33+ curl \
34+ make \
35+ node-gyp \
36+ nodejs \
37+ npm \
38+ openssl \
39+ python3 \
40+ sqlite-dev \
41+ unzip && \
42+ echo "🤖 Installing ..." && \
43+ npm ci --include=dev && \
44+ echo "🤖 Building ..." && \
45+ npm run build && \
46+ echo "🤖 Cleaning up..." && \
47+ npm prune --production && \
48+ apk del \
49+ bash \
50+ build-base \
51+ curl \
52+ make \
53+ node-gyp \
54+ openssl \
55+ python3 \
56+ sqlite-dev \
57+ unzip && \
58+ rm -rf /root/.npm /root/.node-gyp /root/.cache /tmp/* /var/tmp/* && \
59+ rm -rf /app/src /app/package.json /app/package-lock.json /app/tsconfig.json && \
60+ find /app/build/ && \
61+ echo "🤖 Build completed !!!"
62+
63+ # Create non-root user and verify build directory
64+ RUN addgroup -g 1001 -S nodejs && \
65+ adduser -S kagent -u 1001 -G nodejs
5766
5867ADD https://doc-sqlite-db.s3.sa-east-1.amazonaws.com/kubernetes.db /app/build/kubernetes.db
5968ADD https://doc-sqlite-db.s3.sa-east-1.amazonaws.com/istio.db /app/build/istio.db
@@ -75,11 +84,6 @@ RUN for file in /app/build/*.db; do echo "Checksum for $file:";sha256sum "$file"
7584# Ensure the app directory is owned by the non-root user
7685RUN chown -R kagent:nodejs /app
7786
78- # Copy built application and production dependencies from builder stage
79- COPY --from=builder --chown=kagent:nodejs /app/build ./build
80- COPY --from=builder --chown=kagent:nodejs /app/node_modules ./node_modules
81- COPY --from=builder --chown=kagent:nodejs /app/package.json ./
82-
8387LABEL org.opencontainers.image.source=https://github.com/kagent-dev/doc2vec
8488LABEL org.opencontainers.image.description="Kagent Doc2Vec MCP"
8589LABEL org.opencontainers.image.authors="Kagent Creators 🤖"
0 commit comments