web-01-api/Dockerfile
2026-06-22 14:36:21 +08:00

45 lines
1.4 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.

# 构建阶段
FROM crpi-jlsdxetsdmy4ckxh.cn-shenzhen.personal.cr.aliyuncs.com/zsq_proxy/node:22-alpine AS build
WORKDIR /app
# 关键:切换 Alpine 软件源到阿里云(大幅提升下载速度)
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装编译工具:使用 build-base 元包gcc/g++/make 等) + python3 + openssl
RUN apk add --no-cache python3 build-base openssl && rm -rf /var/cache/apk/*
RUN yarn config set registry https://registry.npmmirror.com && \
yarn config set network-timeout 60000
COPY package*.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
# 删除这一行(项目使用 TypeORM不需要 Prisma
# RUN npx prisma generate
RUN yarn build
# 生产阶段
FROM crpi-jlsdxetsdmy4ckxh.cn-shenzhen.personal.cr.aliyuncs.com/zsq_proxy/node:22-alpine AS production
WORKDIR /app
# 同样切换源,保证后续如有 apk 操作也能快速下载
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装 dumb-init 和 openssl
RUN apk add --no-cache dumb-init openssl && rm -rf /var/cache/apk/*
# 复制环境变量文件
COPY .env ./
# 直接从构建阶段复制已安装的依赖和构建产物
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY package*.json ./
EXPOSE 3003
ENTRYPOINT ["dumb-init", "--"]
CMD ["sh", "-c", "set -a; . ./.env; node dist/main"]