-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdockerfile
More file actions
51 lines (41 loc) · 1.59 KB
/
dockerfile
File metadata and controls
51 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 阶段一:跑 terser,压缩并移除所有 JS 注释
FROM --platform=$BUILDPLATFORM denoland/deno:alpine AS terser-builder
WORKDIR /app
COPY . /app
RUN echo '{\
"module": true,\
"compress": {},\
"mangle": false,\
"output": {\
"semicolons": false\
},\
"parse": {\
"bare_returns": true\
},\
"rename": {}\
}' > /app/terser.config.json
RUN find . -type f \( -name "*.mjs" -o -name "*.js" \) ! -path "./node_modules/*" -print0 \
| xargs -0 -P $(nproc) -I {} deno run -A npm:terser {} --config-file /app/terser.config.json --output {}
RUN rm -rf /app/node_modules /app/terser.config.json
# 阶段二:跑 minify,压缩并移除所有无用的html、css、json、svg、xml等文件
FROM --platform=$BUILDPLATFORM tdewolff/minify:latest AS minify-builder
WORKDIR /app
COPY --from=terser-builder /app /app
RUN find . -type f \( -name "*.html" -o -name "*.css" -o -name "*.json" -o -name "*.svg" -o -name "*.xml" \) ! -path "./node_modules/*" -print0 \
| xargs -0 -P $(nproc) -I {} sh -c 'minify -o {} {} || echo "Warning: Failed to minify {}, skipping."'
# 阶段三:最终运行时镜像
FROM denoland/deno:alpine
WORKDIR /app
COPY --from=minify-builder /app /app
RUN touch /app/.noupdate && touch /.dockerenv
EXPOSE 8931
EXPOSE 16698
# 给予 *.sh 执行权限
RUN find . -type f \( -name "*.sh" -o -name "*.fish" -o -name "*.zsh" \) -print0 | xargs -0 chmod +x
RUN find ./path -maxdepth 1 -type f -print0 | xargs -0 chmod +x
# 安装依赖并忽略错误
RUN /app/run.sh init || true
RUN rm -rf /.dockerenv
# 使用 run.sh 作为启动脚本,并且传递参数
ENTRYPOINT ["/app/run.sh"]
CMD []