@kodus/cli 0.0.8 → 0.0.10
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/index.js +1 -1
- package/package.json +3 -2
- package/readme.md +1 -1
- package/scripts/setup-db.sh +77 -0
- package/src/commands/install.js +15 -1
- package/templates/docker-compose.yml +19 -23
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kodus/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "CLI tool for Kodus installation and management",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"index.js",
|
|
17
17
|
"src/**/*.js",
|
|
18
|
-
"templates/**/*"
|
|
18
|
+
"templates/**/*",
|
|
19
|
+
"scripts/**/*.sh"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/readme.md
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# scripts/setup-db.sh
|
|
3
|
+
|
|
4
|
+
echo "Setting up database..."
|
|
5
|
+
|
|
6
|
+
# Criar arquivo de configuração dentro do container
|
|
7
|
+
docker-compose exec -T kodus-orchestrator bash -c 'cat > /usr/src/app/datasource.js << EOL
|
|
8
|
+
const MainSeeder = require("./dist/config/database/typeorm/seed/main.seeder").default;
|
|
9
|
+
const { DataSource } = require("typeorm");
|
|
10
|
+
module.exports = new DataSource({
|
|
11
|
+
type: "postgres",
|
|
12
|
+
host: process.env.API_PG_DB_HOST,
|
|
13
|
+
port: 5432,
|
|
14
|
+
username: process.env.API_PG_DB_USERNAME,
|
|
15
|
+
password: process.env.API_PG_DB_PASSWORD,
|
|
16
|
+
database: process.env.API_PG_DB_DATABASE,
|
|
17
|
+
ssl: false,
|
|
18
|
+
entities: ["./dist/core/infrastructure/adapters/repositories/typeorm/schema/*.model.js",],
|
|
19
|
+
migrations: ["./dist/config/database/typeorm/migrations/*.js"],
|
|
20
|
+
seeds: [MainSeeder]
|
|
21
|
+
});
|
|
22
|
+
EOL'
|
|
23
|
+
|
|
24
|
+
# Criar arquivo de configuração temporário para o seed
|
|
25
|
+
docker-compose exec -T kodus-orchestrator bash -c 'cat > /usr/src/app/seed-datasource.js << EOL
|
|
26
|
+
const MainSeeder = require("./dist/config/database/typeorm/seed/main.seeder").default;
|
|
27
|
+
const { DataSource } = require("typeorm");
|
|
28
|
+
const dataSourceInstance = new DataSource({
|
|
29
|
+
type: "postgres",
|
|
30
|
+
host: process.env.API_PG_DB_HOST,
|
|
31
|
+
port: 5432,
|
|
32
|
+
username: process.env.API_PG_DB_USERNAME,
|
|
33
|
+
password: process.env.API_PG_DB_PASSWORD,
|
|
34
|
+
database: process.env.API_PG_DB_DATABASE,
|
|
35
|
+
ssl: false,
|
|
36
|
+
entities: ["./dist/core/infrastructure/adapters/repositories/typeorm/schema/*.model.js",],
|
|
37
|
+
seeds: [MainSeeder]
|
|
38
|
+
});
|
|
39
|
+
module.exports = { dataSourceInstance };
|
|
40
|
+
EOL'
|
|
41
|
+
|
|
42
|
+
# Criar extensão vector no banco de dados
|
|
43
|
+
echo "Creating vector extension..."
|
|
44
|
+
docker-compose exec -T kodus-orchestrator bash -c 'cd /usr/src/app && yarn typeorm query "CREATE EXTENSION IF NOT EXISTS vector;" -d datasource.js'
|
|
45
|
+
|
|
46
|
+
# Verificar se a extensão foi criada com sucesso
|
|
47
|
+
echo "Verifying vector extension..."
|
|
48
|
+
docker-compose exec -T kodus-orchestrator bash -c 'cd /usr/src/app && yarn typeorm query "SELECT extname, extversion FROM pg_extension WHERE extname = '\''vector'\'';" -d datasource.js'
|
|
49
|
+
|
|
50
|
+
# Rodar migrations dentro do container
|
|
51
|
+
echo "Running migrations..."
|
|
52
|
+
docker-compose exec -T kodus-orchestrator bash -c 'cd /usr/src/app && yarn typeorm migration:run -d datasource.js'
|
|
53
|
+
|
|
54
|
+
# Rodar seeds dentro do container com o novo arquivo de configuração
|
|
55
|
+
echo "Running seeds..."
|
|
56
|
+
docker-compose exec -T kodus-orchestrator bash -c '
|
|
57
|
+
cd /usr/src/app &&
|
|
58
|
+
export NODE_PATH=/usr/src/app/dist &&
|
|
59
|
+
node -e "
|
|
60
|
+
const { runSeeders } = require('\''typeorm-extension'\'');
|
|
61
|
+
const { dataSourceInstance } = require('\''./seed-datasource.js'\'');
|
|
62
|
+
|
|
63
|
+
async function runSeeds() {
|
|
64
|
+
try {
|
|
65
|
+
await dataSourceInstance.initialize();
|
|
66
|
+
await runSeeders(dataSourceInstance);
|
|
67
|
+
process.exit(0);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('\''Error running seeds:'\'', error);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
runSeeds();
|
|
75
|
+
"'
|
|
76
|
+
|
|
77
|
+
echo "Database setup completed!"
|
package/src/commands/install.js
CHANGED
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
copyTemplates,
|
|
12
12
|
createDockerNetworks,
|
|
13
13
|
} from "../utils/helpers.js";
|
|
14
|
+
import { fileURLToPath } from 'url';
|
|
15
|
+
import { dirname } from 'path';
|
|
16
|
+
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = dirname(__filename);
|
|
14
19
|
|
|
15
20
|
const maxAttempts = 30; // 5 minutes with 10 second intervals
|
|
16
21
|
|
|
@@ -260,7 +265,16 @@ export const setupEnvironment = async () => {
|
|
|
260
265
|
// Setup database
|
|
261
266
|
const dbSpinner = ora("Setting up database").start();
|
|
262
267
|
try {
|
|
263
|
-
|
|
268
|
+
const moduleRoot = dirname(dirname(__dirname)); // Sobe 2 níveis: commands -> src -> root
|
|
269
|
+
const scriptPath = path.join(moduleRoot, 'scripts', 'setup-db.sh');
|
|
270
|
+
|
|
271
|
+
if (!fs.existsSync(scriptPath)) {
|
|
272
|
+
dbSpinner.fail('setup-db.sh script not found!');
|
|
273
|
+
console.error(chalk.red(`\nScript expected at: ${scriptPath}`));
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
execSync(`sh ${scriptPath}`, { stdio: "pipe" });
|
|
264
278
|
dbSpinner.succeed("Database setup completed");
|
|
265
279
|
} catch (error) {
|
|
266
280
|
dbSpinner.fail("Failed to setup database");
|
|
@@ -34,23 +34,39 @@ services:
|
|
|
34
34
|
env_file:
|
|
35
35
|
- .env
|
|
36
36
|
|
|
37
|
+
rabbitmq:
|
|
38
|
+
image: rabbitmq:3.13.4-management-alpine
|
|
39
|
+
container_name: rabbitmq-prod
|
|
40
|
+
hostname: rabbitmq
|
|
41
|
+
ports:
|
|
42
|
+
- "5672:5672"
|
|
43
|
+
- "15672:15672"
|
|
44
|
+
networks:
|
|
45
|
+
- monitoring-network
|
|
46
|
+
- shared-network
|
|
47
|
+
environment:
|
|
48
|
+
- RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbit heartbeat 60
|
|
49
|
+
restart: unless-stopped
|
|
50
|
+
env_file:
|
|
51
|
+
- .env
|
|
52
|
+
|
|
37
53
|
db_kodus_postgres:
|
|
38
|
-
image:
|
|
54
|
+
image: pgvector/pgvector:pg16
|
|
39
55
|
container_name: db_kodus_postgres
|
|
40
56
|
ports:
|
|
41
57
|
- "5432:5432"
|
|
42
58
|
environment:
|
|
43
|
-
# These variables must be defined in the .env file
|
|
44
59
|
POSTGRES_USER: ${API_PG_DB_USERNAME}
|
|
45
60
|
POSTGRES_PASSWORD: ${API_PG_DB_PASSWORD}
|
|
46
61
|
POSTGRES_DB: ${API_PG_DB_DATABASE}
|
|
47
62
|
volumes:
|
|
48
63
|
- pgdata:/var/lib/postgresql/data
|
|
64
|
+
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
|
49
65
|
networks:
|
|
50
66
|
- kodus-backend-services
|
|
51
67
|
|
|
52
68
|
db_kodus_mongodb:
|
|
53
|
-
image: mongo:
|
|
69
|
+
image: mongo:8
|
|
54
70
|
container_name: db_kodus_mongodb
|
|
55
71
|
ports:
|
|
56
72
|
- "27017:27017"
|
|
@@ -64,26 +80,6 @@ services:
|
|
|
64
80
|
networks:
|
|
65
81
|
- kodus-backend-services
|
|
66
82
|
|
|
67
|
-
prometheus:
|
|
68
|
-
container_name: prometheus-prod
|
|
69
|
-
image: prom/prometheus:latest
|
|
70
|
-
environment:
|
|
71
|
-
- ENV=production
|
|
72
|
-
command:
|
|
73
|
-
- "--config.file=/etc/prometheus/prometheus.yml"
|
|
74
|
-
- "--storage.tsdb.retention.time=30d"
|
|
75
|
-
- "--storage.tsdb.retention.size=50GB"
|
|
76
|
-
- "--web.enable-lifecycle"
|
|
77
|
-
- "--web.enable-admin-api"
|
|
78
|
-
deploy:
|
|
79
|
-
resources:
|
|
80
|
-
limits:
|
|
81
|
-
cpus: "1"
|
|
82
|
-
memory: 4G
|
|
83
|
-
reservations:
|
|
84
|
-
cpus: "0.75"
|
|
85
|
-
memory: 2G
|
|
86
|
-
|
|
87
83
|
migration:
|
|
88
84
|
image: ghcr.io/kodustech/kodus-ai:latest
|
|
89
85
|
platform: linux/amd64
|