diff --git a/.dockerignore b/.dockerignore index 90afc23..014a4ff 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,5 @@ node_modules -dist +# ⚠️ 不要忽略 dist:本地预构建时 Dockerfile.prebuilt 需要 COPY 它 .git .github .gitea diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c7e3fb1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Dockerfile 必须 LF:CRLF 会让续行符 `\` 后面多出一个 \r,被当成指令参数 +Dockerfile text eol=lf +Dockerfile.* text eol=lf + +# 脚本与配置统一 LF +*.sh text eol=lf +*.yml text eol=lf +*.conf text eol=lf diff --git a/Dockerfile.prebuilt b/Dockerfile.prebuilt new file mode 100644 index 0000000..0808859 --- /dev/null +++ b/Dockerfile.prebuilt @@ -0,0 +1,23 @@ +# 预构建镜像:dist/ 在本机 build 好(构建期 SSG 数据经 SSH 隧道取自线上), +# 服务器只装运行时依赖并打层,不跑 astro build。 +# 由 backend/scripts/push-build.sh 与 backend/deploy.sh --prebuilt 使用。 + +FROM node:22-alpine +WORKDIR /app + +ENV NODE_ENV=production \ + HOST=0.0.0.0 \ + PORT=3000 + +# 运行时依赖层:只在 package-lock 变化时重装,日常发布命中缓存 +COPY package*.json ./ +RUN npm ci --omit=dev && npm cache clean --force + +COPY dist ./dist + +EXPOSE 3000 + +HEALTHCHECK --interval=15s --timeout=3s --start-period=15s --retries=3 \ + CMD nc -z 127.0.0.1 3000 || exit 1 + +CMD ["node", "./dist/server/entry.mjs"]