Skip to content

Commit 6a1eff6

Browse files
committed
Update Dockerfile to support ARM64 architecture for Puppeteer
1 parent cb285d9 commit 6a1eff6

File tree

1 file changed

+54
-64
lines changed

1 file changed

+54
-64
lines changed

Dockerfile

+54-64
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,68 @@
1-
FROM node:18-slim as server
2-
1+
FROM node:18-slim AS base
32
WORKDIR /app
3+
RUN apt update && apt install -y \
4+
g++ make python3 wget gnupg dirmngr unzip
45

5-
RUN apt update && apt -y install g++ make python3
6-
# RUN npm install -g node-gyp
7-
6+
# Server stage
7+
FROM base AS server
88
COPY ./server/ .
9+
RUN yarn config set registry https://registry.npmjs.org/ && \
10+
yarn config set network-timeout 1200000 && \
11+
yarn install --frozen-lockfile && \
12+
yarn build
913

10-
RUN yarn config set registry https://registry.npmjs.org/
11-
RUN yarn config set network-timeout 1200000
12-
RUN yarn install --frozen-lockfile
13-
14-
RUN yarn build
15-
16-
FROM node:18-slim as build
17-
WORKDIR /app
18-
19-
RUN apt update
14+
# Build stage
15+
FROM base AS build
2016
RUN npm --no-update-notifier --no-fund --global install pnpm
21-
2217
COPY . .
23-
RUN pnpm install
24-
25-
RUN pnpm build
18+
RUN pnpm install && pnpm build
2619

20+
# Final stage
2721
FROM node:18-slim
28-
2922
WORKDIR /app
3023

24+
# Set environment variables
3125
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
32-
33-
RUN ARCH=$(dpkg --print-architecture) && \
34-
if [ "$ARCH" = "amd64" ]; then \
35-
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
36-
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
37-
apt-get update && \
38-
apt-get install google-chrome-stable -y --no-install-recommends; \
39-
elif [ "$ARCH" = "arm64" ]; then \
40-
wget -q -O - 'https://playwright.azureedge.net/builds/chromium/1088/chromium-linux-arm64.zip' && \
41-
unzip chromium-linux-arm64.zip && \
42-
mv chrome-linux /usr/bin/chromium-browser && \
43-
ln -s /usr/bin/chromium-browser /usr/bin/google-chrome && \
44-
rm chromium-linux-arm64.zip; \
45-
else \
46-
echo "Unsupported architecture: $ARCH" && exit 1; \
47-
fi && \
48-
rm -rf /var/lib/apt/lists/*
49-
50-
51-
RUN yarn config set registry https://registry.npmjs.org/
52-
RUN yarn config set network-timeout 1200000
53-
54-
RUN apt update && apt -y install --no-install-recommends ca-certificates git git-lfs openssh-client curl jq cmake sqlite3 openssl psmisc python3
55-
56-
57-
RUN apt -y install g++ make
58-
59-
RUN apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/{apt,dpkg,cache,log}/
60-
61-
RUN npm --no-update-notifier --no-fund --global install pnpm
62-
# Copy API
63-
COPY --from=server /app/dist/ .
64-
COPY --from=server /app/prisma/ ./prisma
65-
COPY --from=server /app/package.json .
66-
# Copy UI
67-
COPY --from=build /app/app/ui/dist/ ./public
68-
# Copy widgets
69-
COPY --from=build /app/app/widget/dist/assets/ ./public/assets
70-
COPY --from=build /app/app/widget/dist/index.html ./public/bot.html
71-
# Copy script
72-
COPY --from=build /app/app/script/dist/chat.min.js ./public/chat.min.js
73-
74-
RUN yarn install --production --frozen-lockfile
75-
7626
ENV NODE_ENV=production
7727

28+
# Install dependencies and google chrome based on architecture
29+
RUN apt update && apt install -y wget gnupg dirmngr curl && \
30+
ARCH=$(dpkg --print-architecture) && \
31+
if [ "$ARCH" = "amd64" ]; then \
32+
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
33+
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
34+
apt-get update && \
35+
apt-get install google-chrome-stable -y --no-install-recommends; \
36+
elif [ "$ARCH" = "arm64" ]; then \
37+
wget -q -O chromium-linux-arm64.zip 'https://playwright.azureedge.net/builds/chromium/1088/chromium-linux-arm64.zip' && \
38+
unzip chromium-linux-arm64.zip && \
39+
mv chrome-linux /usr/bin/chromium-browser && \
40+
ln -s /usr/bin/chromium-browser /usr/bin/google-chrome && \
41+
rm chromium-linux-arm64.zip; \
42+
else \
43+
echo "Unsupported architecture: $ARCH" && exit 1; \
44+
fi && \
45+
rm -rf /var/lib/apt/lists/* \
46+
&& apt-get clean && rm -rf /var/lib/{apt,dpkg,cache,log}/
47+
48+
# Install other dependencies
49+
RUN apt update && apt install -y --no-install-recommends \
50+
ca-certificates git git-lfs openssh-client curl jq cmake sqlite3 openssl psmisc python3 g++ make && \
51+
apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/{apt,dpkg,cache,log}/
52+
53+
# Copying build artifacts
54+
COPY --from=server /app/dist/ .
55+
COPY --from=server /app/prisma/ ./prisma
56+
COPY --from=server /app/package.json .
57+
COPY --from=build /app/app/ui/dist/ ./public
58+
COPY --from=build /app/app/widget/dist/assets/ ./public/assets
59+
COPY --from=build /app/app/widget/dist/index.html ./public/bot.html
60+
COPY --from=build /app/app/script/dist/chat.min.js ./public/chat.min.js
61+
62+
# Install production dependencies
63+
RUN yarn config set registry https://registry.npmjs.org/ && \
64+
yarn config set network-timeout 1200000 && \
65+
yarn install --production --frozen-lockfile
66+
67+
# Start the application
7868
CMD ["yarn", "start"]

0 commit comments

Comments
 (0)