Skip to content

Commit e1880c6

Browse files
committed
optimize: size, a bit more.
1 parent 094b6c3 commit e1880c6

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

Dockerfile

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1-
# install and optimize dependencies
2-
FROM zenika/alpine-chrome:with-node AS base
1+
FROM node:22.13.1-alpine3.20 AS base
32

43
WORKDIR /app
54

6-
# copy package files
75
COPY package.json pnpm-lock.yaml ./
86

9-
# install pnpm as root,
10-
# then switch back to chrome user
11-
USER root
12-
RUN npm install -g pnpm@10
7+
RUN npm install -g [email protected] && \
8+
npm install -g modclean
139

14-
# install dependencies as normal user
15-
USER chrome
1610
RUN pnpm install --prod --frozen-lockfile && \
1711
pnpm prune --prod && \
18-
# remove unnecessary files to reduce image size
19-
find /app/node_modules -name "*.md" -delete && \
20-
find /app/node_modules -type d -name "test*" -exec rm -rf {} + 2>/dev/null || true && \
21-
find /app/node_modules -type d -name "doc*" -exec rm -rf {} + 2>/dev/null || true && \
22-
find /app/node_modules -name ".cache" -type d -exec rm -rf {} + 2>/dev/null || true && \
23-
# clean up caches
12+
modclean --patterns default:safe --no-progress --run && \
2413
rm -rf ~/.pnpm ~/.npm /tmp/* /var/cache/apk/*
2514

26-
# production stage
27-
FROM zenika/alpine-chrome:with-node
15+
FROM node:22.13.1-alpine3.20
16+
17+
RUN apk upgrade --no-cache --available && \
18+
apk add --no-cache \
19+
chromium \
20+
ttf-freefont \
21+
font-noto-emoji \
22+
tini && \
23+
apk add --no-cache font-wqy-zenhei --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community && \
24+
# remove unnecessary chromium files to save space
25+
rm -rf /usr/lib/chromium/chrome_crashpad_handler \
26+
/usr/lib/chromium/chrome_200_percent.pak \
27+
/usr/lib/chromium/chrome_100_percent.pak \
28+
/usr/lib/chromium/xdg-mime \
29+
/usr/lib/chromium/xdg-settings \
30+
/usr/lib/chromium/chrome-sandbox
31+
32+
RUN addgroup -S chrome && adduser -S -G chrome chrome
2833

29-
# environment configuration
3034
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
3135
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser \
3236
NODE_ENV=production
3337

3438
WORKDIR /app
3539
USER chrome
3640

37-
# copy application files
3841
COPY package.json ./
3942
COPY --from=base /app/node_modules ./node_modules
40-
COPY src/index.js ./src/
43+
COPY src/ ./src/
4144

42-
# start the application
45+
ENTRYPOINT ["tini", "--"]
4346
CMD ["node", "src/index.js"]

0 commit comments

Comments
 (0)