Skip to content

Commit 3803f0d

Browse files
authored
Merge pull request #782 from Phala-Network/optimize-docker
refactor: refactor dockerfile to reduce image and build time
2 parents 1ae26c3 + 10215bb commit 3803f0d

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

Dockerfile

+46-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
1-
FROM node:23.3.0
2-
RUN npm install -g [email protected]
1+
# Use a specific Node.js version for better reproducibility
2+
FROM node:23.3.0-slim AS builder
3+
4+
# Install pnpm globally and install necessary build tools
5+
RUN npm install -g [email protected] && \
6+
apt-get update && \
7+
apt-get install -y git python3 make g++ && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Set Python 3 as the default python
12+
RUN ln -s /usr/bin/python3 /usr/bin/python
313

414
# Set the working directory
515
WORKDIR /app
616

7-
# Add configuration files and install dependencies
8-
ADD pnpm-workspace.yaml /app/pnpm-workspace.yaml
9-
ADD package.json /app/package.json
10-
ADD .npmrc /app/.npmrc
11-
ADD tsconfig.json /app/tsconfig.json
12-
ADD turbo.json /app/turbo.json
17+
# Copy package.json and other configuration files
18+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc turbo.json ./
19+
20+
# Copy the rest of the application code
21+
COPY agent ./agent
22+
COPY packages ./packages
23+
COPY scripts ./scripts
24+
COPY characters ./characters
1325

14-
# Add the documentation
15-
ADD docs /app/docs
26+
# Install dependencies and build the project
27+
RUN pnpm install \
28+
&& pnpm build \
29+
&& pnpm prune --prod
1630

17-
# Add the rest of the application code
18-
ADD agent /app/agent
19-
ADD packages /app/packages
31+
# Create a new stage for the final image
32+
FROM node:23.3.0-slim
2033

21-
# Add the environment variables
22-
ADD scripts /app/scripts
23-
ADD characters /app/characters
24-
ADD .env /app/.env
34+
# Install runtime dependencies if needed
35+
RUN npm install -g [email protected] && \
36+
apt-get update && \
37+
apt-get install -y git python3 && \
38+
apt-get clean && \
39+
rm -rf /var/lib/apt/lists/*
40+
41+
WORKDIR /app
2542

26-
RUN pnpm i
27-
RUN pnpm build
43+
# Copy built artifacts and production dependencies from the builder stage
44+
COPY --from=builder /app/package.json ./
45+
COPY --from=builder /app/pnpm-workspace.yaml ./
46+
COPY --from=builder /app/.npmrc ./
47+
COPY --from=builder /app/turbo.json ./
48+
COPY --from=builder /app/node_modules ./node_modules
49+
COPY --from=builder /app/agent ./agent
50+
COPY --from=builder /app/packages ./packages
51+
COPY --from=builder /app/scripts ./scripts
52+
COPY --from=builder /app/characters ./characters
2853

29-
# Command to run the container
30-
CMD ["tail", "-f", "/dev/null"]
54+
# Set the command to run the application
55+
CMD ["pnpm", "start"]

0 commit comments

Comments
 (0)