Skip to content

Commit

Permalink
docker: 调整 Dockerfile 构建
Browse files Browse the repository at this point in the history
  • Loading branch information
SALTWOOD committed Dec 8, 2024
1 parent bc5f046 commit 18a3162
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# 使用Alpine Linux作为基础镜像
FROM alpine:latest
# 构建阶段
FROM alpine:latest AS build

# 更改apk软件源为清华大学镜像并更新软件包
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk update && \
apk add --no-cache \
build-base \
python3 \
git \
npm \
openssh \
nodejs
build-base \
python3 \
git \
npm \
openssh \
nodejs

# 设置镜像源
# RUN npm config set registry https://registry.npmmirror.com
Expand All @@ -19,12 +17,24 @@ RUN apk update && \
WORKDIR /app
COPY . .

RUN rm -rf node_modules && \
rm -rf dist && \
npm install
# 安装依赖并构建项目
RUN npm ci && \
npm run build

# 运行阶段
FROM alpine:latest

# 仅安装运行时所需的包
RUN apk add --no-cache \
nodejs \
npm

WORKDIR /app

# 安装TypeScript以及其他依赖包
RUN npm install -g typescript && npm install && npm run build
# 从构建阶段复制构建输出和依赖
COPY --from=build /app/dist /app/dist
COPY --from=build /app/node_modules /app/node_modules
COPY --from=build /app/package.json /app/package.json

# 启动应用程序
CMD ["node", "--enable-source-maps", "dist/index.js"]

0 comments on commit 18a3162

Please sign in to comment.