mirror of
https://github.com/KwiTsukasa/kt-template-online-api.git
synced 2026-05-27 15:44:54 +08:00
ci: 优化 Jenkins 构建产物打包
This commit is contained in:
parent
cbac76ea3d
commit
e331b26314
@ -1,5 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
|
||||||
coverage
|
coverage
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
12
Jenkinsfile
vendored
12
Jenkinsfile
vendored
@ -156,7 +156,17 @@ pipeline {
|
|||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
runCmd("docker build -f dockerfile -t ${env.DOCKER_IMAGE} .")
|
if (isUnix()) {
|
||||||
|
runCmd("""
|
||||||
|
test -f dist/main.js
|
||||||
|
docker build -f dockerfile -t ${env.DOCKER_IMAGE} .
|
||||||
|
""".stripIndent())
|
||||||
|
} else {
|
||||||
|
runCmd('', """
|
||||||
|
if not exist dist\\main.js exit /b 1
|
||||||
|
docker build -f dockerfile -t ${env.DOCKER_IMAGE} .
|
||||||
|
""".stripIndent())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,7 +67,7 @@ pnpm start:dev
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm start # 普通启动
|
pnpm start # 普通启动
|
||||||
pnpm start:prod # 构建后按 production 环境启动
|
pnpm start:prod # 按 production 环境运行已构建的 dist/main
|
||||||
pnpm run build # Nest 构建
|
pnpm run build # Nest 构建
|
||||||
pnpm run lint # ESLint 检查
|
pnpm run lint # ESLint 检查
|
||||||
pnpm test # 单元测试
|
pnpm test # 单元测试
|
||||||
|
|||||||
16
dockerfile
16
dockerfile
@ -1,21 +1,19 @@
|
|||||||
# 引用 Node 22 官方 Debian slim 镜像,避免非官方 tag 在镜像源里解析失败
|
|
||||||
FROM node:22-bookworm-slim
|
FROM node:22-bookworm-slim
|
||||||
|
|
||||||
# 指定工作目录
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 先拷贝依赖清单,利用 Docker 缓存加速依赖安装
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
COPY package.json pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
|
||||||
# 项目使用 pnpm-lock.yaml,镜像内也统一使用 pnpm 安装依赖
|
# 生产镜像只安装运行依赖,dist 由 Jenkins Build stage 提前产出。
|
||||||
RUN corepack enable \
|
RUN corepack enable \
|
||||||
&& corepack prepare pnpm@9 --activate \
|
&& corepack prepare pnpm@9 --activate \
|
||||||
&& pnpm install --frozen-lockfile
|
&& pnpm install --prod --frozen-lockfile
|
||||||
|
|
||||||
# 拷贝业务代码
|
# dist 由 Jenkins 的 Build stage 生成,这里只打包运行产物。
|
||||||
COPY . .
|
COPY dist ./dist
|
||||||
|
|
||||||
# 声明暴露端口号
|
|
||||||
EXPOSE 48085
|
EXPOSE 48085
|
||||||
|
|
||||||
CMD ["pnpm", "run", "start:prod"]
|
CMD ["node", "dist/main"]
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
"start": "nest start",
|
"start": "nest start",
|
||||||
"start:dev": "nest start --watch",
|
"start:dev": "nest start --watch",
|
||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
"start:prod": "nest build && cross-env NODE_ENV=production node dist/main",
|
"start:prod": "cross-env NODE_ENV=production node dist/main",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
||||||
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user