Skip to content

Commit 50d082c

Browse files
committed
refactor: optimize Dockerfile for improved build process
- Replace ADD with COPY for package.json and pnpm-lock.yaml to enhance clarity. - Ensure consistent use of corepack commands across stages. - Add ownership settings for copied files to improve security. - Change CMD to run the application using 'node server.ts' instead of 'pnpm start'.
1 parent b98c5cb commit 50d082c

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Dockerfile

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ FROM base as deps
99

1010
WORKDIR /remixapp
1111

12-
RUN corepack enable && corepack prepare pnpm@latest --activate
13-
ADD package.json pnpm-lock.yaml ./
14-
RUN pnpm install --frozen-lockfile
12+
COPY package.json pnpm-lock.yaml ./
13+
RUN corepack enable && pnpm install --frozen-lockfile
1514

1615
# Setup production node_modules
1716
FROM base as production-deps
1817

1918
WORKDIR /remixapp
2019

2120
COPY --from=deps /remixapp/node_modules /remixapp/node_modules
22-
ADD package.json pnpm-lock.yaml ./
23-
RUN corepack enable && corepack prepare pnpm@latest --activate && pnpm prune --prod
21+
COPY package.json pnpm-lock.yaml ./
22+
RUN corepack enable && pnpm prune --prod
2423

2524
# Build the app
2625
FROM base as build
@@ -29,8 +28,8 @@ WORKDIR /remixapp
2928

3029
COPY --from=deps /remixapp/node_modules /remixapp/node_modules
3130

32-
ADD . .
33-
RUN corepack enable && corepack prepare pnpm@latest --activate && pnpm run build
31+
COPY . .
32+
RUN corepack enable && pnpm run build
3433

3534
# Finally, build the production image with minimal footprint
3635
FROM base
@@ -40,13 +39,14 @@ ENV NODE_ENV="production"
4039

4140
WORKDIR /remixapp
4241

43-
COPY --from=production-deps /remixapp/node_modules /remixapp/node_modules
44-
COPY --from=build /remixapp/build /remixapp/build
45-
COPY --from=build /remixapp/server.ts /remixapp/server.ts
46-
COPY --from=build /remixapp/server /remixapp/server
47-
COPY --from=build /remixapp/shared /remixapp/shared
48-
COPY --from=build /remixapp/data /remixapp/data
49-
COPY --from=build /remixapp/package.json /remixapp/package.json
50-
COPY --from=build /remixapp/start.sh /remixapp/start.sh
51-
52-
CMD ["pnpm", "start"]
42+
COPY --chown=node:node --from=production-deps /remixapp/node_modules /remixapp/node_modules
43+
COPY --chown=node:node --from=build /remixapp/build /remixapp/build
44+
COPY --chown=node:node --from=build /remixapp/server.ts /remixapp/server.ts
45+
COPY --chown=node:node --from=build /remixapp/server /remixapp/server
46+
COPY --chown=node:node --from=build /remixapp/shared /remixapp/shared
47+
COPY --chown=node:node --from=build /remixapp/data /remixapp/data
48+
COPY --chown=node:node --from=build /remixapp/package.json /remixapp/package.json
49+
COPY --chown=node:node --from=build /remixapp/start.sh /remixapp/start.sh
50+
51+
USER node
52+
CMD ["node", "server.ts"]

0 commit comments

Comments
 (0)