Skip to content

Commit 2b79e9d

Browse files
committed
chore: improve Dockerfile
1 parent 568b411 commit 2b79e9d

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

docker/zero-ui/Dockerfile

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,68 @@
1-
FROM --platform=$BUILDPLATFORM node:lts-alpine as frontend-build
1+
# Stage 1: Build frontend
2+
FROM --platform=$BUILDPLATFORM node:lts-alpine AS frontend-build
23

34
ENV GENERATE_SOURCEMAP=false
45

5-
RUN corepack enable
6-
RUN mkdir -p /app/frontend
7-
WORKDIR /app/
6+
# Enable corepack and create necessary directories in one layer
7+
RUN corepack enable && mkdir -p /app/frontend
8+
9+
WORKDIR /app
10+
11+
# Copy package-related files and install dependencies
812
COPY tsconfig.json package.json yarn.lock* .yarnrc.yml ./
913
COPY .yarn/ ./.yarn
10-
WORKDIR /app/frontend/
11-
COPY ./frontend/package*.json /app/frontend
14+
15+
# Set working directory to frontend and copy package files
16+
WORKDIR /app/frontend
17+
COPY ./frontend/package*.json /app/frontend/
18+
19+
# Install frontend dependencies and build the frontend
1220
RUN yarn workspaces focus frontend
13-
COPY ./frontend /app/frontend
21+
COPY ./frontend /app/frontend/
1422
RUN yarn build
1523

24+
# Stage 2: Build backend
25+
FROM node:lts-alpine AS backend-build
1626

17-
FROM node:lts-alpine
27+
# Enable corepack and create necessary directories in one layer
28+
RUN corepack enable && mkdir -p /app/backend
1829

19-
WORKDIR /app/frontend/build
20-
COPY --from=frontend-build /app/frontend/build /app/frontend/build/
30+
WORKDIR /app
2131

22-
RUN corepack enable
23-
RUN mkdir -p /app/backend
24-
WORKDIR /app/
32+
# Copy package-related files and install dependencies
2533
COPY package.json yarn.lock* .yarnrc.yml ./
2634
COPY .yarn/ ./.yarn
27-
WORKDIR /app/backend/
28-
COPY ./backend/package*.json /app/backend
35+
36+
# Set working directory to backend and copy package files
37+
WORKDIR /app/backend
38+
COPY ./backend/package*.json /app/backend/
39+
40+
# Install backend dependencies
2941
RUN yarn workspaces focus --production backend && yarn cache clean
3042

43+
# Copy the backend source files
3144
COPY ./backend /app/backend
3245

33-
EXPOSE 4000
46+
# Final Stage: Production
47+
FROM node:lts-alpine
48+
49+
# Set the working directory to /app/backend
50+
WORKDIR /app/backend
51+
52+
# Copy the built frontend from the frontend-build stage
53+
COPY --from=frontend-build /app/frontend/build /app/frontend/build
54+
55+
# Copy the backend files from the backend-build stage
56+
COPY --from=backend-build /app/backend /app/backend
57+
COPY --from=backend-build /app/node_modules /app/backend/node_modules
58+
59+
# Environment variables
3460
ENV NODE_ENV=production
3561
ENV ZU_SECURE_HEADERS=true
3662
ENV ZU_SERVE_FRONTEND=true
3763

38-
CMD [ "node", "./bin/www" ]
64+
# Expose the application port
65+
EXPOSE 4000
66+
67+
# Start the application
68+
CMD ["node", "bin/www.js"]

0 commit comments

Comments
 (0)