feat: 增加 pipeline和 deployment
This commit is contained in:
7
apps/server/README.md
Normal file
7
apps/server/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
## 表
|
||||||
|
- user
|
||||||
|
- project
|
||||||
|
- pipeline
|
||||||
|
- deployment
|
||||||
|
- runner
|
||||||
45
apps/server/controllers/deployment/index.ts
Normal file
45
apps/server/controllers/deployment/index.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Controller, Get, Post } from '../../decorators/route.ts';
|
||||||
|
import type { Prisma } from '../../generated/prisma/index.js';
|
||||||
|
import prisma from '../../libs/db.ts';
|
||||||
|
import type { Context } from 'koa';
|
||||||
|
|
||||||
|
@Controller('/deployments')
|
||||||
|
export class DeploymentController {
|
||||||
|
@Get('')
|
||||||
|
async list(ctx: Context) {
|
||||||
|
const { page = 1, pageSize = 10 } = ctx.query;
|
||||||
|
const result = await prisma.deployment.findMany({
|
||||||
|
where: {
|
||||||
|
valid: 1,
|
||||||
|
},
|
||||||
|
take: Number(pageSize),
|
||||||
|
skip: (Number(page) - 1) * Number(pageSize),
|
||||||
|
orderBy: {
|
||||||
|
createdAt: 'desc',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const total = await prisma.deployment.count();
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: result,
|
||||||
|
page: Number(page),
|
||||||
|
pageSize: Number(pageSize),
|
||||||
|
total: total,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('')
|
||||||
|
async create(ctx: Context) {
|
||||||
|
const body = ctx.request.body as Prisma.DeploymentCreateInput;
|
||||||
|
|
||||||
|
prisma.deployment.create({
|
||||||
|
data: {
|
||||||
|
branch: body.branch,
|
||||||
|
commitHash: body.commitHash,
|
||||||
|
commitMessage: body.commitMessage,
|
||||||
|
|
||||||
|
valid: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
0
apps/server/controllers/deployment/types.ts
Normal file
0
apps/server/controllers/deployment/types.ts
Normal file
@@ -2,3 +2,5 @@
|
|||||||
export { ProjectController } from './project/index.ts';
|
export { ProjectController } from './project/index.ts';
|
||||||
export { UserController } from './user/index.ts';
|
export { UserController } from './user/index.ts';
|
||||||
export { AuthController } from './auth/index.ts';
|
export { AuthController } from './auth/index.ts';
|
||||||
|
export { DeploymentController } from './deployment/index.ts';
|
||||||
|
export { PipelineController } from './pipeline/index.ts'
|
||||||
|
|||||||
22
apps/server/controllers/pipeline/index.ts
Normal file
22
apps/server/controllers/pipeline/index.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import type { Context } from 'koa';
|
||||||
|
import { Controller, Get, Post } from '../../decorators/route.ts';
|
||||||
|
import prisma from '../../libs/db.ts';
|
||||||
|
|
||||||
|
@Controller('/pipelines')
|
||||||
|
export class PipelineController {
|
||||||
|
@Get('/:id')
|
||||||
|
async get(ctx: Context) {
|
||||||
|
const id = ctx.params.id;
|
||||||
|
const pipeline = await prisma.pipeline.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('')
|
||||||
|
async create(ctx: Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
ProjectController,
|
ProjectController,
|
||||||
UserController,
|
UserController,
|
||||||
AuthController,
|
AuthController,
|
||||||
|
DeploymentController,
|
||||||
|
PipelineController
|
||||||
} from '../controllers/index.ts';
|
} from '../controllers/index.ts';
|
||||||
import { log } from '../libs/logger.ts';
|
import { log } from '../libs/logger.ts';
|
||||||
|
|
||||||
@@ -38,6 +40,8 @@ export class Router implements Middleware {
|
|||||||
ProjectController,
|
ProjectController,
|
||||||
UserController,
|
UserController,
|
||||||
AuthController,
|
AuthController,
|
||||||
|
DeploymentController,
|
||||||
|
PipelineController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 输出注册的路由信息
|
// 输出注册的路由信息
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
"koa-session": "^7.0.2",
|
"koa-session": "^7.0.2",
|
||||||
"pino": "^9.9.1",
|
"pino": "^9.9.1",
|
||||||
"pino-pretty": "^13.1.1",
|
"pino-pretty": "^13.1.1",
|
||||||
"zod": "^4.1.5"
|
"zod": "^4.1.5",
|
||||||
|
"zx": "^8.8.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node-ts": "^23.6.1",
|
"@tsconfig/node-ts": "^23.6.1",
|
||||||
|
|||||||
Binary file not shown.
@@ -12,26 +12,19 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Project {
|
model Project {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String
|
name String
|
||||||
description String?
|
description String?
|
||||||
repository String
|
repository String
|
||||||
valid Int @default(1)
|
// Relations
|
||||||
createdAt DateTime @default(now())
|
deployments Deployment[]
|
||||||
updatedAt DateTime @updatedAt
|
pipelines Pipeline[]
|
||||||
createdBy String
|
|
||||||
updatedBy String
|
|
||||||
}
|
|
||||||
|
|
||||||
model Environment {
|
valid Int @default(1)
|
||||||
id Int @id @default(autoincrement())
|
createdAt DateTime @default(now())
|
||||||
name String
|
updatedAt DateTime @updatedAt
|
||||||
description String?
|
createdBy String
|
||||||
valid Int @default(1)
|
updatedBy String
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
createdBy String
|
|
||||||
updatedBy String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
@@ -47,3 +40,56 @@ model User {
|
|||||||
createdBy String @default("system")
|
createdBy String @default("system")
|
||||||
updatedBy String @default("system")
|
updatedBy String @default("system")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Pipeline {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
name String
|
||||||
|
description String?
|
||||||
|
valid Int @default(1)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
createdBy String
|
||||||
|
updatedBy String
|
||||||
|
|
||||||
|
// Relations
|
||||||
|
projectId Int?
|
||||||
|
Project Project? @relation(fields: [projectId], references: [id])
|
||||||
|
steps Step[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model Step {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
name String
|
||||||
|
description String?
|
||||||
|
order Int
|
||||||
|
status String?
|
||||||
|
valid Int @default(1)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
createdBy String
|
||||||
|
updatedBy String
|
||||||
|
|
||||||
|
pipelineId Int
|
||||||
|
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Deployment {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
branch String
|
||||||
|
env String?
|
||||||
|
status String // pending, running, success, failed, cancelled
|
||||||
|
commitHash String?
|
||||||
|
commitMessage String?
|
||||||
|
buildLog String?
|
||||||
|
startedAt DateTime @default(now())
|
||||||
|
finishedAt DateTime?
|
||||||
|
valid Int @default(1)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
createdBy String
|
||||||
|
updatedBy String
|
||||||
|
|
||||||
|
projectId Int
|
||||||
|
Project Project? @relation(fields: [projectId], references: [id])
|
||||||
|
pipelineId Int
|
||||||
|
}
|
||||||
|
|||||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -41,6 +41,9 @@ importers:
|
|||||||
zod:
|
zod:
|
||||||
specifier: ^4.1.5
|
specifier: ^4.1.5
|
||||||
version: 4.1.5
|
version: 4.1.5
|
||||||
|
zx:
|
||||||
|
specifier: ^8.8.2
|
||||||
|
version: 8.8.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@tsconfig/node-ts':
|
'@tsconfig/node-ts':
|
||||||
specifier: ^23.6.1
|
specifier: ^23.6.1
|
||||||
@@ -1970,6 +1973,11 @@ packages:
|
|||||||
use-sync-external-store:
|
use-sync-external-store:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
zx@8.8.2:
|
||||||
|
resolution: {integrity: sha512-JuCw+diiuDihAtDC/ClDjaP3spsOxfFAMWrSa+esdU+YnBwYGuFef+B127zQ3x2FHOFULQ4NbaX/95d5260eYQ==}
|
||||||
|
engines: {node: '>= 12.17.0'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
snapshots:
|
snapshots:
|
||||||
|
|
||||||
'@alloc/quick-lru@5.2.0': {}
|
'@alloc/quick-lru@5.2.0': {}
|
||||||
@@ -3752,3 +3760,5 @@ snapshots:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/react': 18.3.24
|
'@types/react': 18.3.24
|
||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
|
|
||||||
|
zx@8.8.2: {}
|
||||||
|
|||||||
Reference in New Issue
Block a user