Skip to content

Commit d6426de

Browse files
authored
Merge pull request #18 from dimetron/main
Docker fixes multi arch build
2 parents 127d33f + 0569934 commit d6426de

File tree

3 files changed

+54
-49
lines changed

3 files changed

+54
-49
lines changed

.github/workflows/tag.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- name: 'Build Images'
3838
env:
3939
DOCKER_BUILD_ARGS: "--push --platform linux/amd64,linux/arm64"
40+
DOCKER_REPO: "${{ github.repository_owner }}/doc2vec"
4041
run: |
4142
# if workflow_dispatch is used, use the version input
4243
if [ -n "${{ github.event.inputs.version }}" ]; then

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LOCALARCH ?= $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
1515
DOCKER_BUILDER ?= docker buildx
1616
DOCKER_BUILD_ARGS ?= --progress=plain --pull --load --platform linux/$(LOCALARCH)
1717

18-
BUILDX_NO_DEFAULT_ATTESTATIONS=1
18+
export BUILDX_NO_DEFAULT_ATTESTATIONS=1
1919
BUILDX_BUILDER_NAME=kagent-builder
2020

2121
.PHONY: create-builder
@@ -33,5 +33,5 @@ build-mcp: create-builder
3333
run-mcp: build-mcp
3434
docker run --rm -t -e OPENAI_API_KEY=$(OPENAI_API_KEY) -e TRANSPORT_TYPE=http --name mcp -p 3001:3001 $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(MCP_IMAGE_NAME):$(VERSION)
3535

36-
## To test the MCP image locally
37-
# docker run --rm -t -e OPENAI_API_KEY=$OPENAI_API_KEY -e TRANSPORT_TYPE=http -p 3001:3001 ghcr.io/kagent-dev/doc2vec/mcp:1.1.6
36+
## To test the MCP image locally
37+
# docker run --rm -t -e OPENAI_API_KEY=$OPENAI_API_KEY -e TRANSPORT_TYPE=http -p 3001:3001 ghcr.io/kagent-dev/doc2vec/mcp:1.1.6

mcp/Dockerfile

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
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

410
ENV LANG=C.UTF-8
511
ENV LC_ALL=C.UTF-8
12+
ENV NODE_ENV=production
13+
ENV NODE_PATH=/app/node_modules
614

15+
# Install only runtime dependencies
716
RUN 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

2321
WORKDIR /app
2422

@@ -27,33 +25,44 @@ COPY package.json package-lock.json tsconfig.json ./
2725
COPY 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

5867
ADD https://doc-sqlite-db.s3.sa-east-1.amazonaws.com/kubernetes.db /app/build/kubernetes.db
5968
ADD 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
7685
RUN 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-
8387
LABEL org.opencontainers.image.source=https://github.com/kagent-dev/doc2vec
8488
LABEL org.opencontainers.image.description="Kagent Doc2Vec MCP"
8589
LABEL org.opencontainers.image.authors="Kagent Creators 🤖"

0 commit comments

Comments
 (0)