Files
blog/editor-api/Dockerfile
T

37 lines
1.3 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# editor-api 镜像 —— 零 npm 依赖,所以没有 package.json / 锁文件 / npm ci
#
# 为什么这么小:
# · base 用 alpine
# · 代码只用 node 内置模块(node:http / node:fs / node:crypto),不需要 npm install
# · git 是必须的:发布 = 在仓库工作区里 add + commit + push
#
# 仓库本体不进镜像 —— 挂载进去(compose 里 /blog)。这样 git pull 不用重建镜像。
FROM node:22-alpine
# git:发布用。ca-certificates:https 远端(CNB / GitHub)要它
#
# ★ apk 源默认换成阿里云镜像:国内机器直连 dl-cdn.alpinelinux.org 实测慢到不可用
# (单个包 30~40 秒,12 个包要 7 分钟),换源后几秒装完。
# 境外机器想用官方源就 --build-arg APK_MIRROR= 传空值。
ARG APK_MIRROR=mirrors.aliyun.com
RUN if [ -n "$APK_MIRROR" ]; then \
sed -i "s#dl-cdn.alpinelinux.org#$APK_MIRROR#g" /etc/apk/repositories; \
fi \
&& apk add --no-cache git ca-certificates
WORKDIR /app
ENV NODE_ENV=production
COPY server.mjs ./
COPY src/ ./src/
# 回收目录(删除的文章挪到这里,在仓库外,不进 git)
RUN mkdir -p /app/trash
EXPOSE 8017
# 没配 EDITOR_TOKEN 时 server.mjs 会自己 process.exit(1),容器随即退出 ——
# 这是刻意的:宁可起不来,也不能以无鉴权状态对公网服务
CMD ["node", "server.mjs"]