Files
music-hub/Dockerfile
T

38 lines
1.4 KiB
Docker

# 声匣 · 多阶段构建:前端用 Vite 打包,运行时只保留生产依赖 + ffmpeg
ARG NODE_IMAGE=node:24-alpine
FROM ${NODE_IMAGE} AS build
ARG NPM_REGISTRY=https://registry.npmmirror.com
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --registry=${NPM_REGISTRY}
COPY . .
RUN npm run build
FROM ${NODE_IMAGE}
ARG NPM_REGISTRY=https://registry.npmmirror.com
ARG ALPINE_MIRROR=mirrors.cloud.tencent.com
RUN if [ -n "${ALPINE_MIRROR}" ]; then sed -i "s#dl-cdn.alpinelinux.org#${ALPINE_MIRROR}#g" /etc/apk/repositories; fi \
&& apk add --no-cache ffmpeg su-exec tzdata
WORKDIR /app
ENV NODE_ENV=production \
PORT=8066 \
MUSIC_DIR=/music \
DATA_DIR=/data \
TZ=Asia/Shanghai
COPY package.json package-lock.json ./
RUN npm ci --omit=dev --registry=${NPM_REGISTRY} && npm cache clean --force
COPY config.json ./
COPY server ./server
COPY --from=build /app/dist ./dist
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# 宿主机文件可能是 0700(如飞牛 NAS),服务以 PUID 运行,需要让 /app 对所有用户可读
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh && chmod -R a+rX /app
EXPOSE 8066
HEALTHCHECK --interval=60s --timeout=5s --start-period=10s CMD wget -qO- "http://127.0.0.1:${PORT}/api/health" >/dev/null || exit 1
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "--disable-warning=ExperimentalWarning", "server/src/main.ts"]