-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #782 from Phala-Network/optimize-docker
refactor: refactor dockerfile to reduce image and build time
- Loading branch information
Showing
1 changed file
with
46 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,55 @@ | ||
FROM node:23.3.0 | ||
RUN npm install -g pnpm@9.4.0 | ||
# Use a specific Node.js version for better reproducibility | ||
FROM node:23.3.0-slim AS builder | ||
|
||
# Install pnpm globally and install necessary build tools | ||
RUN npm install -g pnpm@9.4.0 && \ | ||
apt-get update && \ | ||
apt-get install -y git python3 make g++ && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Set Python 3 as the default python | ||
RUN ln -s /usr/bin/python3 /usr/bin/python | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Add configuration files and install dependencies | ||
ADD pnpm-workspace.yaml /app/pnpm-workspace.yaml | ||
ADD package.json /app/package.json | ||
ADD .npmrc /app/.npmrc | ||
ADD tsconfig.json /app/tsconfig.json | ||
ADD turbo.json /app/turbo.json | ||
# Copy package.json and other configuration files | ||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc turbo.json ./ | ||
|
||
# Copy the rest of the application code | ||
COPY agent ./agent | ||
COPY packages ./packages | ||
COPY scripts ./scripts | ||
COPY characters ./characters | ||
|
||
# Add the documentation | ||
ADD docs /app/docs | ||
# Install dependencies and build the project | ||
RUN pnpm install \ | ||
&& pnpm build \ | ||
&& pnpm prune --prod | ||
|
||
# Add the rest of the application code | ||
ADD agent /app/agent | ||
ADD packages /app/packages | ||
# Create a new stage for the final image | ||
FROM node:23.3.0-slim | ||
|
||
# Add the environment variables | ||
ADD scripts /app/scripts | ||
ADD characters /app/characters | ||
ADD .env /app/.env | ||
# Install runtime dependencies if needed | ||
RUN npm install -g pnpm@9.4.0 && \ | ||
apt-get update && \ | ||
apt-get install -y git python3 && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
|
||
RUN pnpm i | ||
RUN pnpm build | ||
# Copy built artifacts and production dependencies from the builder stage | ||
COPY --from=builder /app/package.json ./ | ||
COPY --from=builder /app/pnpm-workspace.yaml ./ | ||
COPY --from=builder /app/.npmrc ./ | ||
COPY --from=builder /app/turbo.json ./ | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/agent ./agent | ||
COPY --from=builder /app/packages ./packages | ||
COPY --from=builder /app/scripts ./scripts | ||
COPY --from=builder /app/characters ./characters | ||
|
||
# Command to run the container | ||
CMD ["tail", "-f", "/dev/null"] | ||
# Set the command to run the application | ||
CMD ["pnpm", "start"] |