@quatrain/app 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Bootloader.d.ts +5 -0
- package/dist/Bootloader.d.ts.map +1 -0
- package/dist/Bootloader.js +110 -0
- package/dist/Bootloader.js.map +1 -0
- package/dist/CodeGenerator.d.ts +10 -0
- package/dist/CodeGenerator.d.ts.map +1 -0
- package/dist/CodeGenerator.js +252 -0
- package/dist/CodeGenerator.js.map +1 -0
- package/dist/Infra.d.ts +7 -0
- package/dist/Infra.d.ts.map +1 -0
- package/dist/Infra.js +81 -0
- package/dist/Infra.js.map +1 -0
- package/dist/InfraBuilder.d.ts +27 -0
- package/dist/InfraBuilder.d.ts.map +1 -0
- package/dist/InfraBuilder.js +132 -0
- package/dist/InfraBuilder.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/src/Bootloader.ts +121 -0
- package/src/CodeGenerator.ts +246 -0
- package/src/Infra.ts +96 -0
- package/src/InfraBuilder.ts +141 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as yaml from 'yaml'
|
|
2
|
+
|
|
3
|
+
export interface ComposeService {
|
|
4
|
+
image?: string
|
|
5
|
+
build?: string | { context: string, dockerfile?: string }
|
|
6
|
+
container_name?: string
|
|
7
|
+
restart?: string
|
|
8
|
+
ports?: string[]
|
|
9
|
+
environment?: Record<string, string>
|
|
10
|
+
volumes?: string[]
|
|
11
|
+
command?: string
|
|
12
|
+
depends_on?: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ComposeFile {
|
|
16
|
+
version?: string
|
|
17
|
+
services: Record<string, ComposeService>
|
|
18
|
+
volumes?: Record<string, any>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class InfraBuilder {
|
|
22
|
+
/**
|
|
23
|
+
* Génère le contenu des fichiers compose.yaml, .env et Containerfile en fonction de la configuration de l'application
|
|
24
|
+
*/
|
|
25
|
+
public static build(config: any, appName: string = 'quatrain-app'): { compose: string, env: string, dockerfile: string } {
|
|
26
|
+
const compose: ComposeFile = {
|
|
27
|
+
services: {},
|
|
28
|
+
volumes: {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const envVars: Record<string, string> = {}
|
|
32
|
+
|
|
33
|
+
// 1. Unified Engine Container (API + Front)
|
|
34
|
+
compose.services['engine'] = {
|
|
35
|
+
build: {
|
|
36
|
+
context: '.',
|
|
37
|
+
dockerfile: 'Containerfile'
|
|
38
|
+
},
|
|
39
|
+
container_name: `${appName}-engine`,
|
|
40
|
+
restart: 'unless-stopped',
|
|
41
|
+
ports: ['3000:3000', '4001:4000'],
|
|
42
|
+
environment: {
|
|
43
|
+
NODE_ENV: 'production'
|
|
44
|
+
},
|
|
45
|
+
volumes: ['./quatrain.json:/app/quatrain.json:ro'],
|
|
46
|
+
depends_on: []
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 2. Backend Infrastructure
|
|
50
|
+
if (config.backend && config.backend.adapter === 'PostgresAdapter') {
|
|
51
|
+
const dbUser = 'quatrain'
|
|
52
|
+
const dbPass = 'quatrain_pass'
|
|
53
|
+
const dbName = 'quatrain_db'
|
|
54
|
+
|
|
55
|
+
compose.services['postgres'] = {
|
|
56
|
+
image: 'postgres:15-alpine',
|
|
57
|
+
container_name: `${appName}-postgres`,
|
|
58
|
+
restart: 'unless-stopped',
|
|
59
|
+
ports: ['5432:5432'],
|
|
60
|
+
environment: {
|
|
61
|
+
POSTGRES_USER: dbUser,
|
|
62
|
+
POSTGRES_PASSWORD: dbPass,
|
|
63
|
+
POSTGRES_DB: dbName
|
|
64
|
+
},
|
|
65
|
+
volumes: ['postgres_data:/var/lib/postgresql/data']
|
|
66
|
+
}
|
|
67
|
+
compose.volumes!['postgres_data'] = {}
|
|
68
|
+
|
|
69
|
+
// Link to Engine
|
|
70
|
+
compose.services['engine'].depends_on!.push('postgres')
|
|
71
|
+
envVars['DATABASE_URL'] = `postgresql://${dbUser}:${dbPass}@postgres:5432/${dbName}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 3. Storage Infrastructure
|
|
75
|
+
if (config.storage && config.storage.adapter === 'S3Adapter') {
|
|
76
|
+
const s3User = 'minioadmin'
|
|
77
|
+
const s3Pass = 'minioadminpassword'
|
|
78
|
+
|
|
79
|
+
compose.services['minio'] = {
|
|
80
|
+
image: 'minio/minio:latest',
|
|
81
|
+
container_name: `${appName}-minio`,
|
|
82
|
+
restart: 'unless-stopped',
|
|
83
|
+
ports: ['9000:9000', '9001:9001'],
|
|
84
|
+
environment: {
|
|
85
|
+
MINIO_ROOT_USER: s3User,
|
|
86
|
+
MINIO_ROOT_PASSWORD: s3Pass
|
|
87
|
+
},
|
|
88
|
+
command: 'server /data --console-address ":9001"',
|
|
89
|
+
volumes: ['minio_data:/data']
|
|
90
|
+
}
|
|
91
|
+
compose.volumes!['minio_data'] = {}
|
|
92
|
+
|
|
93
|
+
// Link to Engine
|
|
94
|
+
compose.services['engine'].depends_on!.push('minio')
|
|
95
|
+
envVars['S3_ENDPOINT'] = `http://minio:9000`
|
|
96
|
+
envVars['S3_ACCESS_KEY'] = s3User
|
|
97
|
+
envVars['S3_SECRET_KEY'] = s3Pass
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 4. Messaging/Queue Infrastructure
|
|
101
|
+
if (config.queue && config.queue.adapter === 'AmqpAdapter') {
|
|
102
|
+
compose.services['rabbitmq'] = {
|
|
103
|
+
image: 'rabbitmq:3-management-alpine',
|
|
104
|
+
container_name: `${appName}-rabbitmq`,
|
|
105
|
+
restart: 'unless-stopped',
|
|
106
|
+
ports: ['5672:5672', '15672:15672']
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Link to Engine
|
|
110
|
+
compose.services['engine'].depends_on!.push('rabbitmq')
|
|
111
|
+
envVars['AMQP_URL'] = `amqp://rabbitmq:5672`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Clean empty dependencies
|
|
115
|
+
if (compose.services['engine'].depends_on?.length === 0) {
|
|
116
|
+
delete compose.services['engine'].depends_on
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Clean empty volumes
|
|
120
|
+
if (Object.keys(compose.volumes!).length === 0) {
|
|
121
|
+
delete compose.volumes
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Generate outputs
|
|
125
|
+
const composeYaml = yaml.stringify(compose)
|
|
126
|
+
const envFile = Object.entries(envVars).map(([k, v]) => `${k}=${v}`).join('\n')
|
|
127
|
+
|
|
128
|
+
const dockerfile = `
|
|
129
|
+
FROM oven/bun:latest
|
|
130
|
+
WORKDIR /app
|
|
131
|
+
COPY package.json tsconfig.json quatrain.json ./
|
|
132
|
+
RUN bun install
|
|
133
|
+
COPY src ./src
|
|
134
|
+
COPY data ./data
|
|
135
|
+
EXPOSE 3000 4001
|
|
136
|
+
CMD ["bun", "run", "src/index.ts"]
|
|
137
|
+
`.trim()
|
|
138
|
+
|
|
139
|
+
return { compose: composeYaml, env: envFile, dockerfile }
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/index.ts
ADDED