feat: add Dockerfiles and MySQL TypeORM wiring for center/guild backends
This commit is contained in:
19
Fabric.Backend.Center/Dockerfile
Normal file
19
Fabric.Backend.Center/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
FROM node:22-alpine AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
FROM node:22-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM node:22-alpine AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
COPY --from=build /app/dist ./dist
|
||||||
|
EXPOSE 7001
|
||||||
|
CMD ["node", "dist/main.js"]
|
||||||
1265
Fabric.Backend.Center/package-lock.json
generated
1265
Fabric.Backend.Center/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -12,8 +12,11 @@
|
|||||||
"@nestjs/common": "^10.4.8",
|
"@nestjs/common": "^10.4.8",
|
||||||
"@nestjs/core": "^10.4.8",
|
"@nestjs/core": "^10.4.8",
|
||||||
"@nestjs/platform-express": "^10.4.8",
|
"@nestjs/platform-express": "^10.4.8",
|
||||||
|
"@nestjs/typeorm": "^11.0.1",
|
||||||
|
"mysql2": "^3.22.3",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1",
|
||||||
|
"typeorm": "^0.3.29"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.10.1",
|
"@types/node": "^22.10.1",
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { buildTypeOrmConfig } from './database.config';
|
||||||
import { HealthController } from './common/health.controller';
|
import { HealthController } from './common/health.controller';
|
||||||
import { AuthModule } from './auth/auth.module';
|
import { AuthModule } from './auth/auth.module';
|
||||||
import { NodesModule } from './nodes/nodes.module';
|
import { NodesModule } from './nodes/nodes.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [AuthModule, NodesModule],
|
imports: [TypeOrmModule.forRoot(buildTypeOrmConfig()), AuthModule, NodesModule],
|
||||||
controllers: [HealthController],
|
controllers: [HealthController],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
15
Fabric.Backend.Center/src/database.config.ts
Normal file
15
Fabric.Backend.Center/src/database.config.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||||
|
import { User } from './entities/user.entity';
|
||||||
|
import { GuildNode } from './entities/guild-node.entity';
|
||||||
|
|
||||||
|
export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||||
|
type: 'mysql',
|
||||||
|
host: process.env.DB_HOST ?? 'mysql-center',
|
||||||
|
port: Number(process.env.DB_PORT ?? 3306),
|
||||||
|
username: process.env.DB_USER ?? 'fabric',
|
||||||
|
password: process.env.DB_PASSWORD ?? 'fabric',
|
||||||
|
database: process.env.DB_NAME ?? 'fabric_center',
|
||||||
|
entities: [User, GuildNode],
|
||||||
|
synchronize: (process.env.DB_SYNC ?? 'true') === 'true',
|
||||||
|
logging: (process.env.DB_LOGGING ?? 'false') === 'true',
|
||||||
|
});
|
||||||
22
Fabric.Backend.Center/src/entities/guild-node.entity.ts
Normal file
22
Fabric.Backend.Center/src/entities/guild-node.entity.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('guild_nodes')
|
||||||
|
export class GuildNode {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Column({ unique: true })
|
||||||
|
nodeId!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
endpoint!: string;
|
||||||
|
|
||||||
|
@Column({ default: 'active' })
|
||||||
|
status!: string;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
16
Fabric.Backend.Center/src/entities/user.entity.ts
Normal file
16
Fabric.Backend.Center/src/entities/user.entity.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('users')
|
||||||
|
export class User {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Column({ unique: true })
|
||||||
|
email!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
passwordHash!: string;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
19
Fabric.Backend.Guild/Dockerfile
Normal file
19
Fabric.Backend.Guild/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
FROM node:22-alpine AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
FROM node:22-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM node:22-alpine AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
COPY --from=build /app/dist ./dist
|
||||||
|
EXPOSE 7002
|
||||||
|
CMD ["node", "dist/main.js"]
|
||||||
1265
Fabric.Backend.Guild/package-lock.json
generated
1265
Fabric.Backend.Guild/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -12,8 +12,11 @@
|
|||||||
"@nestjs/common": "^10.4.8",
|
"@nestjs/common": "^10.4.8",
|
||||||
"@nestjs/core": "^10.4.8",
|
"@nestjs/core": "^10.4.8",
|
||||||
"@nestjs/platform-express": "^10.4.8",
|
"@nestjs/platform-express": "^10.4.8",
|
||||||
|
"@nestjs/typeorm": "^11.0.1",
|
||||||
|
"mysql2": "^3.22.3",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1",
|
||||||
|
"typeorm": "^0.3.29"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.10.1",
|
"@types/node": "^22.10.1",
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { buildTypeOrmConfig } from './database.config';
|
||||||
import { HealthController } from './common/health.controller';
|
import { HealthController } from './common/health.controller';
|
||||||
import { GuildsModule } from './guilds/guilds.module';
|
import { GuildsModule } from './guilds/guilds.module';
|
||||||
import { ChannelsModule } from './channels/channels.module';
|
import { ChannelsModule } from './channels/channels.module';
|
||||||
import { MessagingModule } from './messaging/messaging.module';
|
import { MessagingModule } from './messaging/messaging.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [GuildsModule, ChannelsModule, MessagingModule],
|
imports: [TypeOrmModule.forRoot(buildTypeOrmConfig()), GuildsModule, ChannelsModule, MessagingModule],
|
||||||
controllers: [HealthController],
|
controllers: [HealthController],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
16
Fabric.Backend.Guild/src/database.config.ts
Normal file
16
Fabric.Backend.Guild/src/database.config.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||||
|
import { Guild } from './entities/guild.entity';
|
||||||
|
import { Channel } from './entities/channel.entity';
|
||||||
|
import { Message } from './entities/message.entity';
|
||||||
|
|
||||||
|
export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||||
|
type: 'mysql',
|
||||||
|
host: process.env.DB_HOST ?? 'mysql-guild',
|
||||||
|
port: Number(process.env.DB_PORT ?? 3306),
|
||||||
|
username: process.env.DB_USER ?? 'fabric',
|
||||||
|
password: process.env.DB_PASSWORD ?? 'fabric',
|
||||||
|
database: process.env.DB_NAME ?? 'fabric_guild',
|
||||||
|
entities: [Guild, Channel, Message],
|
||||||
|
synchronize: (process.env.DB_SYNC ?? 'true') === 'true',
|
||||||
|
logging: (process.env.DB_LOGGING ?? 'false') === 'true',
|
||||||
|
});
|
||||||
20
Fabric.Backend.Guild/src/entities/channel.entity.ts
Normal file
20
Fabric.Backend.Guild/src/entities/channel.entity.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('channels')
|
||||||
|
export class Channel {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
guildId!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
|
@Column({ default: 0 })
|
||||||
|
lastSeq!: number;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
13
Fabric.Backend.Guild/src/entities/guild.entity.ts
Normal file
13
Fabric.Backend.Guild/src/entities/guild.entity.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('guilds')
|
||||||
|
export class Guild {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name!: string;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
21
Fabric.Backend.Guild/src/entities/message.entity.ts
Normal file
21
Fabric.Backend.Guild/src/entities/message.entity.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('messages')
|
||||||
|
@Index(['channelId', 'seq'], { unique: true })
|
||||||
|
export class Message {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
|
@Column()
|
||||||
|
channelId!: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
seq!: number;
|
||||||
|
|
||||||
|
@Column({ type: 'text' })
|
||||||
|
content!: string;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user