mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Refactor Dockerfile with multi-stage build for smaller image size
This commit is contained in:
53
Dockerfile
53
Dockerfile
@@ -1,3 +1,31 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM docker.io/library/node:20-slim AS builder
|
||||||
|
|
||||||
|
# Install build dependencies
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
python3 \
|
||||||
|
make \
|
||||||
|
g++ \
|
||||||
|
git \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Set up npm global package folder
|
||||||
|
RUN mkdir -p /usr/local/share/npm-global
|
||||||
|
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
|
||||||
|
ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . /home/node/app
|
||||||
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
|
# Install dependencies and build packages
|
||||||
|
RUN npm ci \
|
||||||
|
&& npm run build --workspaces \
|
||||||
|
&& npm pack -w @qwen-code/qwen-code --pack-destination ./packages/cli/dist \
|
||||||
|
&& npm pack -w @qwen-code/qwen-code-core --pack-destination ./packages/core/dist
|
||||||
|
|
||||||
|
# Runtime stage
|
||||||
FROM docker.io/library/node:20-slim
|
FROM docker.io/library/node:20-slim
|
||||||
|
|
||||||
ARG SANDBOX_NAME="qwen-code-sandbox"
|
ARG SANDBOX_NAME="qwen-code-sandbox"
|
||||||
@@ -5,11 +33,9 @@ ARG CLI_VERSION_ARG
|
|||||||
ENV SANDBOX="$SANDBOX_NAME"
|
ENV SANDBOX="$SANDBOX_NAME"
|
||||||
ENV CLI_VERSION=$CLI_VERSION_ARG
|
ENV CLI_VERSION=$CLI_VERSION_ARG
|
||||||
|
|
||||||
# install minimal set of packages, then clean up
|
# Install runtime dependencies
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
python3 \
|
python3 \
|
||||||
make \
|
|
||||||
g++ \
|
|
||||||
man-db \
|
man-db \
|
||||||
curl \
|
curl \
|
||||||
dnsutils \
|
dnsutils \
|
||||||
@@ -29,22 +55,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# set up npm global package folder under /usr/local/share
|
# Set up npm global package folder
|
||||||
# give it to non-root user node, already set up in base image
|
RUN mkdir -p /usr/local/share/npm-global
|
||||||
RUN mkdir -p /usr/local/share/npm-global \
|
|
||||||
&& chown -R node:node /usr/local/share/npm-global
|
|
||||||
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
|
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
|
||||||
ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
||||||
|
|
||||||
# switch to non-root user node
|
# Copy built packages from builder stage
|
||||||
USER node
|
COPY --from=builder /home/node/app/packages/cli/dist/*.tgz /tmp/
|
||||||
|
COPY --from=builder /home/node/app/packages/core/dist/*.tgz /tmp/
|
||||||
|
|
||||||
# install qwen-code and clean up
|
# Install built packages globally
|
||||||
COPY packages/cli/dist/qwen-code-*.tgz /usr/local/share/npm-global/qwen-code.tgz
|
RUN npm install -g /tmp/*.tgz \
|
||||||
COPY packages/core/dist/qwen-code-qwen-code-core-*.tgz /usr/local/share/npm-global/qwen-code-core.tgz
|
|
||||||
RUN npm install -g /usr/local/share/npm-global/qwen-code.tgz /usr/local/share/npm-global/qwen-code-core.tgz \
|
|
||||||
&& npm cache clean --force \
|
&& npm cache clean --force \
|
||||||
&& rm -f /usr/local/share/npm-global/qwen-{code,code-core}.tgz
|
&& rm -rf /tmp/*.tgz
|
||||||
|
|
||||||
# default entrypoint when none specified
|
# Default entrypoint when none specified
|
||||||
CMD ["qwen"]
|
CMD ["qwen"]
|
||||||
Reference in New Issue
Block a user