Spaces:
Running
Running
Create Dockerfile
Browse files- Dockerfile +197 -0
Dockerfile
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:22-bookworm AS dep-builder
|
2 |
+
# Here we use the non-slim image to provide build-time deps (compilers and python), thus no need to install later.
|
3 |
+
# This effectively speeds up qemu-based cross-build.
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# place ARG statement before RUN statement which need it to avoid cache miss
|
8 |
+
ARG USE_CHINA_NPM_REGISTRY=0
|
9 |
+
RUN \
|
10 |
+
set -ex && \
|
11 |
+
corepack enable pnpm && \
|
12 |
+
if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
|
13 |
+
echo 'use npm mirror' && \
|
14 |
+
npm config set registry https://registry.npmmirror.com && \
|
15 |
+
yarn config set registry https://registry.npmmirror.com && \
|
16 |
+
pnpm config set registry https://registry.npmmirror.com ; \
|
17 |
+
fi;
|
18 |
+
|
19 |
+
COPY ./tsconfig.json /app/
|
20 |
+
COPY ./patches /app/patches
|
21 |
+
COPY ./pnpm-lock.yaml /app/
|
22 |
+
COPY ./package.json /app/
|
23 |
+
|
24 |
+
# lazy install Chromium to avoid cache miss, only install production dependencies to minimize the image size
|
25 |
+
RUN \
|
26 |
+
set -ex && \
|
27 |
+
export PUPPETEER_SKIP_DOWNLOAD=true && \
|
28 |
+
pnpm install --frozen-lockfile && \
|
29 |
+
pnpm rb
|
30 |
+
|
31 |
+
# ---------------------------------------------------------------------------------------------------------------------
|
32 |
+
|
33 |
+
FROM debian:bookworm-slim AS dep-version-parser
|
34 |
+
# This stage is necessary to limit the cache miss scope.
|
35 |
+
# With this stage, any modification to package.json won't break the build cache of the next two stages as long as the
|
36 |
+
# version unchanged.
|
37 |
+
# node:22-bookworm-slim is based on debian:bookworm-slim so this stage would not cause any additional download.
|
38 |
+
|
39 |
+
WORKDIR /ver
|
40 |
+
COPY ./package.json /app/
|
41 |
+
RUN \
|
42 |
+
set -ex && \
|
43 |
+
grep -Po '(?<="rebrowser-puppeteer": ")[^\s"]*(?=")' /app/package.json | tee /ver/.puppeteer_version
|
44 |
+
# grep -Po '(?<="@vercel/nft": ")[^\s"]*(?=")' /app/package.json | tee /ver/.nft_version && \
|
45 |
+
# grep -Po '(?<="fs-extra": ")[^\s"]*(?=")' /app/package.json | tee /ver/.fs_extra_version
|
46 |
+
|
47 |
+
# ---------------------------------------------------------------------------------------------------------------------
|
48 |
+
|
49 |
+
FROM node:22-bookworm-slim AS docker-minifier
|
50 |
+
# The stage is used to further reduce the image size by removing unused files.
|
51 |
+
|
52 |
+
WORKDIR /app
|
53 |
+
# COPY --from=dep-version-parser /ver/* /minifier/
|
54 |
+
|
55 |
+
# ARG USE_CHINA_NPM_REGISTRY=0
|
56 |
+
# RUN \
|
57 |
+
# set -ex && \
|
58 |
+
# if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
|
59 |
+
# npm config set registry https://registry.npmmirror.com && \
|
60 |
+
# yarn config set registry https://registry.npmmirror.com && \
|
61 |
+
# pnpm config set registry https://registry.npmmirror.com ; \
|
62 |
+
# fi; \
|
63 |
+
# corepack enable pnpm && \
|
64 |
+
# pnpm add @vercel/nft@$(cat .nft_version) fs-extra@$(cat .fs_extra_version) --save-prod
|
65 |
+
|
66 |
+
COPY . /app
|
67 |
+
COPY --from=dep-builder /app /app
|
68 |
+
|
69 |
+
RUN \
|
70 |
+
set -ex && \
|
71 |
+
# cp /app/scripts/docker/minify-docker.js /minifier/ && \
|
72 |
+
# export PROJECT_ROOT=/app && \
|
73 |
+
# node /minifier/minify-docker.js && \
|
74 |
+
# rm -rf /app/node_modules /app/scripts && \
|
75 |
+
# mv /app/app-minimal/node_modules /app/ && \
|
76 |
+
# rm -rf /app/app-minimal && \
|
77 |
+
npm run build && \
|
78 |
+
ls -la /app && \
|
79 |
+
du -hd1 /app
|
80 |
+
|
81 |
+
# ---------------------------------------------------------------------------------------------------------------------
|
82 |
+
|
83 |
+
FROM node:22-bookworm-slim AS chromium-downloader
|
84 |
+
# This stage is necessary to improve build concurrency and minimize the image size.
|
85 |
+
# Yeah, downloading Chromium never needs those dependencies below.
|
86 |
+
|
87 |
+
WORKDIR /app
|
88 |
+
COPY ./.puppeteerrc.cjs /app/
|
89 |
+
COPY --from=dep-version-parser /ver/.puppeteer_version /app/.puppeteer_version
|
90 |
+
|
91 |
+
ARG TARGETPLATFORM
|
92 |
+
ARG USE_CHINA_NPM_REGISTRY=0
|
93 |
+
ARG PUPPETEER_SKIP_DOWNLOAD=1
|
94 |
+
# The official recommended way to use Puppeteer on x86(_64) is to use the bundled Chromium from Puppeteer:
|
95 |
+
# https://pptr.dev/faq#q-why-doesnt-puppeteer-vxxx-workwith-chromium-vyyy
|
96 |
+
RUN \
|
97 |
+
set -ex ; \
|
98 |
+
if [ "$PUPPETEER_SKIP_DOWNLOAD" = 0 ] && [ "$TARGETPLATFORM" = 'linux/amd64' ]; then \
|
99 |
+
if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
|
100 |
+
npm config set registry https://registry.npmmirror.com && \
|
101 |
+
yarn config set registry https://registry.npmmirror.com && \
|
102 |
+
pnpm config set registry https://registry.npmmirror.com ; \
|
103 |
+
fi; \
|
104 |
+
echo 'Downloading Chromium...' && \
|
105 |
+
unset PUPPETEER_SKIP_DOWNLOAD && \
|
106 |
+
corepack enable pnpm && \
|
107 |
+
pnpm --allow-build=rebrowser-puppeteer add rebrowser-puppeteer@$(cat /app/.puppeteer_version) --save-prod && \
|
108 |
+
pnpm rb && \
|
109 |
+
pnpx rebrowser-puppeteer browsers install chrome ; \
|
110 |
+
else \
|
111 |
+
mkdir -p /app/node_modules/.cache/puppeteer ; \
|
112 |
+
fi;
|
113 |
+
|
114 |
+
# ---------------------------------------------------------------------------------------------------------------------
|
115 |
+
|
116 |
+
FROM node:22-bookworm-slim AS app
|
117 |
+
|
118 |
+
LABEL org.opencontainers.image.authors="https://github.com/DIYgod/RSSHub"
|
119 |
+
|
120 |
+
ENV NODE_ENV=production
|
121 |
+
ENV TZ=Asia/Shanghai
|
122 |
+
|
123 |
+
WORKDIR /app
|
124 |
+
|
125 |
+
# install deps first to avoid cache miss or disturbing buildkit to build concurrently
|
126 |
+
ARG TARGETPLATFORM
|
127 |
+
ARG PUPPETEER_SKIP_DOWNLOAD=1
|
128 |
+
# https://pptr.dev/troubleshooting#chrome-headless-doesnt-launch-on-unix
|
129 |
+
# https://github.com/puppeteer/puppeteer/issues/7822
|
130 |
+
# https://www.debian.org/releases/bookworm/amd64/release-notes/ch-information.en.html#noteworthy-obsolete-packages
|
131 |
+
# The official recommended way to use Puppeteer on arm/arm64 is to install Chromium from the distribution repositories:
|
132 |
+
# https://github.com/puppeteer/puppeteer/blob/07391bbf5feaf85c191e1aa8aa78138dce84008d/packages/puppeteer-core/src/node/BrowserFetcher.ts#L128-L131
|
133 |
+
RUN \
|
134 |
+
set -ex && \
|
135 |
+
apt-get update && \
|
136 |
+
apt-get install -yq --no-install-recommends \
|
137 |
+
dumb-init git curl \
|
138 |
+
; \
|
139 |
+
if [ "$PUPPETEER_SKIP_DOWNLOAD" = 0 ]; then \
|
140 |
+
if [ "$TARGETPLATFORM" = 'linux/amd64' ]; then \
|
141 |
+
apt-get install -yq --no-install-recommends \
|
142 |
+
ca-certificates fonts-liberation wget xdg-utils \
|
143 |
+
libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libdbus-1-3 libdrm2 \
|
144 |
+
libexpat1 libgbm1 libglib2.0-0 libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcb1 libxcomposite1 \
|
145 |
+
libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 \
|
146 |
+
; \
|
147 |
+
else \
|
148 |
+
apt-get install -yq --no-install-recommends \
|
149 |
+
chromium \
|
150 |
+
&& \
|
151 |
+
echo "CHROMIUM_EXECUTABLE_PATH=$(which chromium)" | tee /app/.env ; \
|
152 |
+
fi; \
|
153 |
+
fi; \
|
154 |
+
rm -rf /var/lib/apt/lists/*
|
155 |
+
|
156 |
+
COPY --from=chromium-downloader /app/node_modules/.cache/puppeteer /app/node_modules/.cache/puppeteer
|
157 |
+
|
158 |
+
RUN \
|
159 |
+
set -ex && \
|
160 |
+
if [ "$PUPPETEER_SKIP_DOWNLOAD" = 0 ] && [ "$TARGETPLATFORM" = 'linux/amd64' ]; then \
|
161 |
+
echo 'Verifying Chromium installation...' && \
|
162 |
+
if ldd $(find /app/node_modules/.cache/puppeteer/ -name chrome -type f) | grep "not found"; then \
|
163 |
+
echo "!!! Chromium has unmet shared libs !!!" && \
|
164 |
+
exit 1 ; \
|
165 |
+
else \
|
166 |
+
echo "Awesome! All shared libs are met!" ; \
|
167 |
+
fi; \
|
168 |
+
fi;
|
169 |
+
|
170 |
+
COPY --from=docker-minifier /app /app
|
171 |
+
|
172 |
+
EXPOSE 1200
|
173 |
+
ENTRYPOINT ["dumb-init", "--"]
|
174 |
+
|
175 |
+
CMD ["npm", "run", "start"]
|
176 |
+
|
177 |
+
# ---------------------------------------------------------------------------------------------------------------------
|
178 |
+
|
179 |
+
# In case Chromium has unmet shared libs, here is some magic to find and install the packages they belong to:
|
180 |
+
# In most case you can just stop at `grep ^lib` and add those packages to the above stage.
|
181 |
+
#
|
182 |
+
# set -ex && \
|
183 |
+
# apt-get update && \
|
184 |
+
# apt install -yq --no-install-recommends \
|
185 |
+
# apt-file \
|
186 |
+
# && \
|
187 |
+
# apt-file update && \
|
188 |
+
# ldd $(find /app/node_modules/.cache/puppeteer/ -name chrome -type f) | grep -Po "\S+(?= => not found)" | \
|
189 |
+
# sed 's/\./\\./g' | awk '{print $1"$"}' | apt-file search -xlf - | grep ^lib | \
|
190 |
+
# xargs -d '\n' -- \
|
191 |
+
# apt-get install -yq --no-install-recommends \
|
192 |
+
# && \
|
193 |
+
# apt purge -yq --auto-remove \
|
194 |
+
# apt-file \
|
195 |
+
# rm -rf /tmp/.chromium_path /var/lib/apt/lists/*
|
196 |
+
|
197 |
+
# !!! If you manually build Docker image but with buildx/BuildKit disabled, set TARGETPLATFORM yourself !!!
|