@venturekit/cli 0.0.0-dev.20260329102450 → 0.0.0-dev.20260414153924
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/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +2 -27
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +4 -1
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +241 -138
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/open.d.ts +15 -0
- package/dist/commands/open.d.ts.map +1 -0
- package/dist/commands/open.js +176 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/auto-deps.d.ts.map +1 -1
- package/dist/utils/auto-deps.js +43 -1
- package/dist/utils/auto-deps.js.map +1 -1
- package/dist/utils/config-loader.d.ts.map +1 -1
- package/dist/utils/config-loader.js +9 -4
- package/dist/utils/config-loader.js.map +1 -1
- package/dist/utils/docker-compose.d.ts +16 -11
- package/dist/utils/docker-compose.d.ts.map +1 -1
- package/dist/utils/docker-compose.js +194 -138
- package/dist/utils/docker-compose.js.map +1 -1
- package/dist/utils/docker.d.ts +29 -0
- package/dist/utils/docker.d.ts.map +1 -0
- package/dist/utils/docker.js +132 -0
- package/dist/utils/docker.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,89 +1,168 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Docker Compose Generator
|
|
2
|
+
* Docker Compose Generator — Shared Infrastructure
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Maintains a **single** docker-compose.yml at ~/.vk/ shared by all
|
|
5
|
+
* VentureKit projects on the machine.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Postgres 16 → localhost:5432 (multiple DBs via init script)
|
|
8
|
+
* Redis 7 → localhost:6379 (shared by cache + queue intents)
|
|
9
|
+
* MinIO → localhost:9000 / 9001 (buckets per project)
|
|
10
|
+
* pgweb → localhost:8081 (DB viewer, auto-added with Postgres)
|
|
11
|
+
* Redis Insight → localhost:5540 (queue/cache viewer, auto-added with Redis)
|
|
11
12
|
*/
|
|
12
|
-
import { existsSync, writeFileSync, readFileSync } from 'fs';
|
|
13
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
13
14
|
import { join } from 'path';
|
|
15
|
+
import { homedir } from 'os';
|
|
16
|
+
// ── Shared directory & project registry ───────────────────────────────
|
|
17
|
+
const VK_HOME = join(homedir(), '.vk');
|
|
18
|
+
function loadRegistry() {
|
|
19
|
+
const p = join(VK_HOME, 'projects.json');
|
|
20
|
+
if (!existsSync(p))
|
|
21
|
+
return {};
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(readFileSync(p, 'utf-8'));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function saveRegistry(reg) {
|
|
30
|
+
mkdirSync(VK_HOME, { recursive: true });
|
|
31
|
+
writeFileSync(join(VK_HOME, 'projects.json'), JSON.stringify(reg, null, 2), 'utf-8');
|
|
32
|
+
}
|
|
33
|
+
/** Sanitize project name for Postgres DB names: dashes → underscores */
|
|
34
|
+
export function pgName(project, id) {
|
|
35
|
+
return `${project.replace(/-/g, '_')}_${id.replace(/-/g, '_')}`;
|
|
36
|
+
}
|
|
37
|
+
// ── Compose generation ────────────────────────────────────────────────
|
|
38
|
+
/** Collect all unique DB names across every registered project. */
|
|
39
|
+
function allDatabases(reg) {
|
|
40
|
+
const set = new Set();
|
|
41
|
+
for (const entry of Object.values(reg)) {
|
|
42
|
+
for (const db of entry.databases)
|
|
43
|
+
set.add(db);
|
|
44
|
+
}
|
|
45
|
+
return [...set].sort();
|
|
46
|
+
}
|
|
47
|
+
/** Does any registered project need Redis? */
|
|
48
|
+
function anyNeedsRedis(reg) {
|
|
49
|
+
return Object.values(reg).some((e) => e.needsRedis);
|
|
50
|
+
}
|
|
51
|
+
/** Collect all unique bucket names across every registered project. */
|
|
52
|
+
function allBuckets(reg) {
|
|
53
|
+
const set = new Set();
|
|
54
|
+
for (const entry of Object.values(reg)) {
|
|
55
|
+
for (const b of entry.buckets)
|
|
56
|
+
set.add(b);
|
|
57
|
+
}
|
|
58
|
+
return [...set].sort();
|
|
59
|
+
}
|
|
60
|
+
/** Collect all unique queue names across every registered project. */
|
|
61
|
+
function allQueues(reg) {
|
|
62
|
+
const set = new Set();
|
|
63
|
+
for (const entry of Object.values(reg)) {
|
|
64
|
+
for (const q of (entry.queues || []))
|
|
65
|
+
set.add(q);
|
|
66
|
+
}
|
|
67
|
+
return [...set].sort();
|
|
68
|
+
}
|
|
14
69
|
/**
|
|
15
|
-
* Generate docker-compose.yml
|
|
70
|
+
* Generate the shared docker-compose.yml based on the full registry.
|
|
71
|
+
* Services use standard ports.
|
|
16
72
|
*/
|
|
17
|
-
function
|
|
73
|
+
function generateSharedCompose(reg) {
|
|
18
74
|
const services = [];
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
services.push(` ${serviceName}:
|
|
75
|
+
const volumes = [];
|
|
76
|
+
const dbs = allDatabases(reg);
|
|
77
|
+
const needsRedis = anyNeedsRedis(reg);
|
|
78
|
+
const buckets = allBuckets(reg);
|
|
79
|
+
// ── Postgres ────────────────────────────────────────────────────────
|
|
80
|
+
if (dbs.length > 0) {
|
|
81
|
+
services.push(` postgres:
|
|
27
82
|
image: postgres:16-alpine
|
|
28
83
|
restart: unless-stopped
|
|
29
84
|
ports:
|
|
30
|
-
- "
|
|
85
|
+
- "5432:5432"
|
|
31
86
|
environment:
|
|
32
|
-
POSTGRES_DB: ${
|
|
87
|
+
POSTGRES_DB: ${dbs[0]}
|
|
33
88
|
POSTGRES_USER: postgres
|
|
34
89
|
POSTGRES_PASSWORD: postgres
|
|
35
90
|
volumes:
|
|
36
|
-
-
|
|
91
|
+
- postgres-data:/var/lib/postgresql/data
|
|
37
92
|
healthcheck:
|
|
38
93
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
39
94
|
interval: 5s
|
|
40
95
|
timeout: 5s
|
|
41
96
|
retries: 5`);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
97
|
+
volumes.push(' postgres-data:');
|
|
98
|
+
// postgres-init — ensure all project databases exist on every startup
|
|
99
|
+
// (docker-entrypoint-initdb.d only runs on first volume init)
|
|
100
|
+
if (dbs.length > 0) {
|
|
101
|
+
const createCmds = dbs
|
|
102
|
+
.map((db) => `psql -U postgres -tc \\"SELECT 1 FROM pg_database WHERE datname='${db}'\\" | grep -q 1 || psql -U postgres -c \\"CREATE DATABASE ${db}\\"`)
|
|
103
|
+
.join(' && ');
|
|
104
|
+
services.push(` postgres-init:
|
|
105
|
+
image: postgres:16-alpine
|
|
106
|
+
depends_on:
|
|
107
|
+
postgres:
|
|
108
|
+
condition: service_healthy
|
|
109
|
+
entrypoint: /bin/sh -c "${createCmds}"
|
|
110
|
+
environment:
|
|
111
|
+
PGHOST: postgres
|
|
112
|
+
PGPASSWORD: postgres
|
|
113
|
+
restart: "no"`);
|
|
48
114
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
services.push(`
|
|
52
|
-
image:
|
|
115
|
+
// pgweb — local-only database viewer
|
|
116
|
+
// Connects to the default 'postgres' DB; users can switch DBs in the UI
|
|
117
|
+
services.push(` pgweb:
|
|
118
|
+
image: sosedoff/pgweb:latest
|
|
53
119
|
restart: unless-stopped
|
|
54
120
|
ports:
|
|
55
|
-
- "
|
|
121
|
+
- "8081:8081"
|
|
56
122
|
environment:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const primaryDb = intents.databases[0];
|
|
62
|
-
const primaryPort = 5432;
|
|
63
|
-
const primaryName = primaryDb.name || primaryDb.id;
|
|
64
|
-
envVars['DATABASE_URL'] = `postgresql://postgres:postgres@localhost:${primaryPort}/${primaryName}`;
|
|
123
|
+
PGWEB_DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
|
|
124
|
+
depends_on:
|
|
125
|
+
postgres:
|
|
126
|
+
condition: service_healthy`);
|
|
65
127
|
}
|
|
66
|
-
// Redis
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
const serviceName = `redis-${cache.id}`;
|
|
70
|
-
const port = 6379 + intents.caches.indexOf(cache);
|
|
71
|
-
services.push(` ${serviceName}:
|
|
128
|
+
// ── Redis ───────────────────────────────────────────────────────────
|
|
129
|
+
if (needsRedis) {
|
|
130
|
+
services.push(` redis:
|
|
72
131
|
image: redis:7-alpine
|
|
73
132
|
restart: unless-stopped
|
|
74
133
|
ports:
|
|
75
|
-
- "
|
|
134
|
+
- "6379:6379"
|
|
76
135
|
healthcheck:
|
|
77
136
|
test: ["CMD", "redis-cli", "ping"]
|
|
78
137
|
interval: 5s
|
|
79
138
|
timeout: 5s
|
|
80
139
|
retries: 5`);
|
|
81
|
-
|
|
82
|
-
|
|
140
|
+
// Redis Insight — local queue & cache viewer
|
|
141
|
+
services.push(` redis-insight:
|
|
142
|
+
image: redis/redisinsight:latest
|
|
143
|
+
restart: unless-stopped
|
|
144
|
+
ports:
|
|
145
|
+
- "5540:5540"
|
|
146
|
+
depends_on:
|
|
147
|
+
redis:
|
|
148
|
+
condition: service_healthy`);
|
|
149
|
+
// redis-init — pre-create queue list keys so they appear in Redis Insight
|
|
150
|
+
const queueNames = allQueues(reg);
|
|
151
|
+
if (queueNames.length > 0) {
|
|
152
|
+
const redisCommands = queueNames
|
|
153
|
+
.map((q) => `redis-cli -h redis LPUSH vk:queue:${q}:info init 2>/dev/null; redis-cli -h redis DEL vk:queue:${q}:info 2>/dev/null; redis-cli -h redis SET vk:queue:${q}:registered 1`)
|
|
154
|
+
.join(' && ');
|
|
155
|
+
services.push(` redis-init:
|
|
156
|
+
image: redis:7-alpine
|
|
157
|
+
depends_on:
|
|
158
|
+
redis:
|
|
159
|
+
condition: service_healthy
|
|
160
|
+
entrypoint: /bin/sh -c "${redisCommands}"
|
|
161
|
+
restart: \"no\"`);
|
|
83
162
|
}
|
|
84
163
|
}
|
|
85
|
-
// MinIO
|
|
86
|
-
if (
|
|
164
|
+
// ── MinIO ───────────────────────────────────────────────────────────
|
|
165
|
+
if (buckets.length > 0) {
|
|
87
166
|
services.push(` minio:
|
|
88
167
|
image: minio/minio:latest
|
|
89
168
|
restart: unless-stopped
|
|
@@ -101,65 +180,28 @@ function generateComposeContent(intents, projectName) {
|
|
|
101
180
|
interval: 5s
|
|
102
181
|
timeout: 5s
|
|
103
182
|
retries: 5`);
|
|
104
|
-
for (const storage of intents.storage) {
|
|
105
|
-
envVars[`STORAGE_${storage.id.toUpperCase()}_ENDPOINT`] = 'http://localhost:9000';
|
|
106
|
-
envVars[`STORAGE_${storage.id.toUpperCase()}_BUCKET`] = `${projectName}-${storage.id}`;
|
|
107
|
-
envVars[`STORAGE_${storage.id.toUpperCase()}_ACCESS_KEY`] = 'minioadmin';
|
|
108
|
-
envVars[`STORAGE_${storage.id.toUpperCase()}_SECRET_KEY`] = 'minioadmin';
|
|
109
|
-
}
|
|
110
|
-
// Unified storage env vars for @venturekit/storage client auto-detection
|
|
111
|
-
envVars['VENTURE_MINIO_ENDPOINT'] = 'http://localhost:9000';
|
|
112
|
-
envVars['VENTURE_MINIO_ACCESS_KEY'] = 'minioadmin';
|
|
113
|
-
envVars['VENTURE_MINIO_SECRET_KEY'] = 'minioadmin';
|
|
114
|
-
// Set the primary storage bucket
|
|
115
|
-
envVars['VENTURE_STORAGE_BUCKET'] = `${projectName}-${intents.storage[0].id}`;
|
|
116
|
-
}
|
|
117
|
-
// Redis for queue intents (message broker for local queue processing)
|
|
118
|
-
const needsQueueRedis = intents.queues && intents.queues.length > 0;
|
|
119
|
-
// Avoid duplicate Redis if caches already created one
|
|
120
|
-
const hasCacheRedis = intents.caches && intents.caches.length > 0;
|
|
121
|
-
if (needsQueueRedis && !hasCacheRedis) {
|
|
122
|
-
services.push(` redis-queues:
|
|
123
|
-
image: redis:7-alpine
|
|
124
|
-
restart: unless-stopped
|
|
125
|
-
ports:
|
|
126
|
-
- "6380:6379"
|
|
127
|
-
healthcheck:
|
|
128
|
-
test: ["CMD", "redis-cli", "ping"]
|
|
129
|
-
interval: 5s
|
|
130
|
-
timeout: 5s
|
|
131
|
-
retries: 5`);
|
|
132
|
-
envVars['VENTURE_QUEUE_REDIS_HOST'] = 'localhost';
|
|
133
|
-
envVars['VENTURE_QUEUE_REDIS_PORT'] = '6380';
|
|
134
|
-
}
|
|
135
|
-
else if (needsQueueRedis && hasCacheRedis) {
|
|
136
|
-
// Reuse the first cache Redis for queues
|
|
137
|
-
const port = 6379;
|
|
138
|
-
envVars['VENTURE_QUEUE_REDIS_HOST'] = 'localhost';
|
|
139
|
-
envVars['VENTURE_QUEUE_REDIS_PORT'] = String(port);
|
|
140
|
-
}
|
|
141
|
-
if (services.length === 0) {
|
|
142
|
-
return '';
|
|
143
|
-
}
|
|
144
|
-
// Build volumes section
|
|
145
|
-
const volumes = [];
|
|
146
|
-
if (intents.databases) {
|
|
147
|
-
for (const db of intents.databases) {
|
|
148
|
-
volumes.push(` postgres-${db.id}-data:`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (intents.storage && intents.storage.length > 0) {
|
|
152
183
|
volumes.push(' minio-data:');
|
|
184
|
+
// minio-init — create all registered buckets on startup
|
|
185
|
+
const mcCommands = [
|
|
186
|
+
'/usr/bin/mc alias set vk http://minio:9000 minioadmin minioadmin',
|
|
187
|
+
...buckets.map((b) => `/usr/bin/mc mb --ignore-existing vk/${b}`),
|
|
188
|
+
].join(' && ');
|
|
189
|
+
services.push(` minio-init:
|
|
190
|
+
image: minio/mc:latest
|
|
191
|
+
depends_on:
|
|
192
|
+
minio:
|
|
193
|
+
condition: service_healthy
|
|
194
|
+
entrypoint: /bin/sh -c "${mcCommands}"
|
|
195
|
+
restart: "no"`);
|
|
153
196
|
}
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
}
|
|
197
|
+
if (services.length === 0)
|
|
198
|
+
return '';
|
|
157
199
|
let content = `# Auto-generated by VentureKit CLI — do not edit manually
|
|
158
|
-
#
|
|
200
|
+
# Shared across all VentureKit projects on this machine.
|
|
159
201
|
#
|
|
160
|
-
# Start: docker compose -f
|
|
161
|
-
# Stop: docker compose -f
|
|
162
|
-
# Reset: docker compose -f
|
|
202
|
+
# Start: docker compose -f ~/.vk/docker-compose.yml up -d
|
|
203
|
+
# Stop: docker compose -f ~/.vk/docker-compose.yml down
|
|
204
|
+
# Reset: docker compose -f ~/.vk/docker-compose.yml down -v
|
|
163
205
|
|
|
164
206
|
services:
|
|
165
207
|
${services.join('\n\n')}
|
|
@@ -170,51 +212,75 @@ ${services.join('\n\n')}
|
|
|
170
212
|
return content;
|
|
171
213
|
}
|
|
172
214
|
/**
|
|
173
|
-
*
|
|
215
|
+
* Register the current project's intents in the shared registry,
|
|
216
|
+
* regenerate ~/.vk/docker-compose.yml, and return env vars for this
|
|
217
|
+
* project's dev server.
|
|
174
218
|
*/
|
|
175
|
-
export function ensureDockerCompose(
|
|
219
|
+
export function ensureDockerCompose(_projectDir, intents, projectName) {
|
|
176
220
|
if (!intents) {
|
|
177
221
|
return { composePath: null, envVars: {}, hasServices: false };
|
|
178
222
|
}
|
|
179
|
-
const
|
|
180
|
-
|
|
223
|
+
const hasDatabases = !!(intents.databases && intents.databases.length > 0);
|
|
224
|
+
const hasCaches = !!(intents.caches && intents.caches.length > 0);
|
|
225
|
+
const hasQueues = !!(intents.queues && intents.queues.length > 0);
|
|
226
|
+
const hasStorage = !!(intents.storage && intents.storage.length > 0);
|
|
227
|
+
const needsAnyService = hasDatabases || hasCaches || hasQueues || hasStorage;
|
|
228
|
+
if (!needsAnyService) {
|
|
181
229
|
return { composePath: null, envVars: {}, hasServices: false };
|
|
182
230
|
}
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
231
|
+
// ── Update registry ─────────────────────────────────────────────────
|
|
232
|
+
const reg = loadRegistry();
|
|
233
|
+
const dbNames = hasDatabases
|
|
234
|
+
? intents.databases.map((db) => pgName(projectName, db.name || db.id))
|
|
235
|
+
: [];
|
|
236
|
+
const bucketNames = hasStorage
|
|
237
|
+
? intents.storage.map((s) => `${projectName}-${s.id}`)
|
|
238
|
+
: [];
|
|
239
|
+
const queueNames = hasQueues
|
|
240
|
+
? intents.queues.map((q) => `${projectName}-${q.id}`)
|
|
241
|
+
: [];
|
|
242
|
+
reg[projectName] = {
|
|
243
|
+
databases: dbNames,
|
|
244
|
+
buckets: bucketNames,
|
|
245
|
+
queues: queueNames,
|
|
246
|
+
needsRedis: hasCaches || hasQueues,
|
|
247
|
+
};
|
|
248
|
+
saveRegistry(reg);
|
|
249
|
+
// ── Regenerate shared compose ───────────────────────────────────────
|
|
250
|
+
mkdirSync(VK_HOME, { recursive: true });
|
|
251
|
+
const content = generateSharedCompose(reg);
|
|
252
|
+
const composePath = join(VK_HOME, 'docker-compose.yml');
|
|
186
253
|
const existing = existsSync(composePath) ? readFileSync(composePath, 'utf-8') : '';
|
|
187
254
|
if (existing !== content) {
|
|
188
255
|
writeFileSync(composePath, content, 'utf-8');
|
|
189
256
|
}
|
|
190
|
-
//
|
|
257
|
+
// ── Build project-specific env vars ─────────────────────────────────
|
|
191
258
|
const envVars = {};
|
|
192
|
-
if (
|
|
259
|
+
if (hasDatabases) {
|
|
193
260
|
for (const db of intents.databases) {
|
|
194
|
-
const
|
|
195
|
-
const dbName = db.name || db.id;
|
|
261
|
+
const dbName = pgName(projectName, db.name || db.id);
|
|
196
262
|
envVars[`DATABASE_${db.id.toUpperCase()}_HOST`] = 'localhost';
|
|
197
|
-
envVars[`DATABASE_${db.id.toUpperCase()}_PORT`] =
|
|
263
|
+
envVars[`DATABASE_${db.id.toUpperCase()}_PORT`] = '5432';
|
|
198
264
|
envVars[`DATABASE_${db.id.toUpperCase()}_NAME`] = dbName;
|
|
199
265
|
envVars[`DATABASE_${db.id.toUpperCase()}_USER`] = 'postgres';
|
|
200
266
|
envVars[`DATABASE_${db.id.toUpperCase()}_PASSWORD`] = 'postgres';
|
|
201
|
-
envVars[`DATABASE_${db.id.toUpperCase()}_URL`] = `postgresql://postgres:postgres@localhost
|
|
267
|
+
envVars[`DATABASE_${db.id.toUpperCase()}_URL`] = `postgresql://postgres:postgres@localhost:5432/${dbName}`;
|
|
202
268
|
}
|
|
203
|
-
// Standard DATABASE_URL for primary database
|
|
204
269
|
const primaryDb = intents.databases[0];
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
envVars['DATABASE_URL'] = `postgresql://postgres:postgres@localhost:${primaryPort}/${primaryName}`;
|
|
208
|
-
envVars['ADMINER_URL'] = 'http://localhost:8080';
|
|
270
|
+
const primaryName = pgName(projectName, primaryDb.name || primaryDb.id);
|
|
271
|
+
envVars['DATABASE_URL'] = `postgresql://postgres:postgres@localhost:5432/${primaryName}`;
|
|
209
272
|
}
|
|
210
|
-
if (
|
|
273
|
+
if (hasCaches) {
|
|
211
274
|
for (const cache of intents.caches) {
|
|
212
|
-
const port = 6379 + intents.caches.indexOf(cache);
|
|
213
275
|
envVars[`CACHE_${cache.id.toUpperCase()}_HOST`] = 'localhost';
|
|
214
|
-
envVars[`CACHE_${cache.id.toUpperCase()}_PORT`] =
|
|
276
|
+
envVars[`CACHE_${cache.id.toUpperCase()}_PORT`] = '6379';
|
|
215
277
|
}
|
|
216
278
|
}
|
|
217
|
-
if (
|
|
279
|
+
if (hasQueues) {
|
|
280
|
+
envVars['VENTURE_QUEUE_REDIS_HOST'] = 'localhost';
|
|
281
|
+
envVars['VENTURE_QUEUE_REDIS_PORT'] = '6379';
|
|
282
|
+
}
|
|
283
|
+
if (hasStorage) {
|
|
218
284
|
for (const storage of intents.storage) {
|
|
219
285
|
envVars[`STORAGE_${storage.id.toUpperCase()}_ENDPOINT`] = 'http://localhost:9000';
|
|
220
286
|
envVars[`STORAGE_${storage.id.toUpperCase()}_BUCKET`] = `${projectName}-${storage.id}`;
|
|
@@ -226,16 +292,6 @@ export function ensureDockerCompose(projectDir, intents, projectName) {
|
|
|
226
292
|
envVars['VENTURE_MINIO_SECRET_KEY'] = 'minioadmin';
|
|
227
293
|
envVars['VENTURE_STORAGE_BUCKET'] = `${projectName}-${intents.storage[0].id}`;
|
|
228
294
|
}
|
|
229
|
-
if (intents.queues && intents.queues.length > 0) {
|
|
230
|
-
if (intents.caches && intents.caches.length > 0) {
|
|
231
|
-
envVars['VENTURE_QUEUE_REDIS_HOST'] = 'localhost';
|
|
232
|
-
envVars['VENTURE_QUEUE_REDIS_PORT'] = '6379';
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
envVars['VENTURE_QUEUE_REDIS_HOST'] = 'localhost';
|
|
236
|
-
envVars['VENTURE_QUEUE_REDIS_PORT'] = '6380';
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
295
|
return { composePath, envVars, hasServices: true };
|
|
240
296
|
}
|
|
241
297
|
//# sourceMappingURL=docker-compose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docker-compose.js","sourceRoot":"","sources":["../../src/utils/docker-compose.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"docker-compose.js","sourceRoot":"","sources":["../../src/utils/docker-compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI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C,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC,GAAG,YAAY,CAAC;QAC3E,CAAC;QACD,OAAO,CAAC,wBAAwB,CAAC,GAAG,uBAAuB,CAAC;QAC5D,OAAO,CAAC,0BAA0B,CAAC,GAAG,YAAY,CAAC;QACnD,OAAO,CAAC,0BAA0B,CAAC,GAAG,YAAY,CAAC;QACnD,OAAO,CAAC,wBAAwB,CAAC,GAAG,GAAG,WAAW,IAAI,OAAO,CAAC,OAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACjF,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docker utilities shared across CLI commands.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Path to the shared docker-compose.yml.
|
|
6
|
+
*/
|
|
7
|
+
export declare function composePath(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Check if Docker daemon is available.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDockerAvailable(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Ensure the shared Docker Compose services are running.
|
|
14
|
+
* Starts them silently if they are not.
|
|
15
|
+
*
|
|
16
|
+
* @param quiet - Suppress progress messages (default: false)
|
|
17
|
+
* @returns true if services are running after the call
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureDockerServicesRunning(quiet?: boolean): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Restart pgweb to point at a specific project database.
|
|
22
|
+
* This ensures `vk open db` always shows the current project's DB.
|
|
23
|
+
*/
|
|
24
|
+
export declare function switchPgwebDatabase(dbName: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Open a URL in the default browser (cross-platform).
|
|
27
|
+
*/
|
|
28
|
+
export declare function openBrowser(url: string): void;
|
|
29
|
+
//# sourceMappingURL=docker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../src/utils/docker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAO3C;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,UAAQ,GAAG,OAAO,CAgElE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAgBxD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAS7C"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docker utilities shared across CLI commands.
|
|
3
|
+
*/
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
import { existsSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
import { homedir } from 'os';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
const VK_HOME = join(homedir(), '.vk');
|
|
10
|
+
/**
|
|
11
|
+
* Path to the shared docker-compose.yml.
|
|
12
|
+
*/
|
|
13
|
+
export function composePath() {
|
|
14
|
+
return join(VK_HOME, 'docker-compose.yml');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if Docker daemon is available.
|
|
18
|
+
*/
|
|
19
|
+
export function isDockerAvailable() {
|
|
20
|
+
try {
|
|
21
|
+
execSync('docker info', { stdio: 'pipe' });
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ensure the shared Docker Compose services are running.
|
|
30
|
+
* Starts them silently if they are not.
|
|
31
|
+
*
|
|
32
|
+
* @param quiet - Suppress progress messages (default: false)
|
|
33
|
+
* @returns true if services are running after the call
|
|
34
|
+
*/
|
|
35
|
+
export function ensureDockerServicesRunning(quiet = false) {
|
|
36
|
+
const cp = composePath();
|
|
37
|
+
if (!existsSync(cp)) {
|
|
38
|
+
if (!quiet) {
|
|
39
|
+
console.error(chalk.red('\n❌ No infrastructure configured yet.'));
|
|
40
|
+
console.error(chalk.dim(' Run `vk dev` first to set up local services.\n'));
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!isDockerAvailable()) {
|
|
45
|
+
if (!quiet) {
|
|
46
|
+
console.error(chalk.red('\n❌ Docker is not running.'));
|
|
47
|
+
console.error(chalk.dim(' Start Docker Desktop and try again.\n'));
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// Always reconcile — docker compose up -d is idempotent:
|
|
52
|
+
// already-running containers are left alone, new/changed ones are started.
|
|
53
|
+
// NOTE: we do NOT use --wait because one-shot init containers (minio-init,
|
|
54
|
+
// redis-init) exit after completing, and --wait treats that as a failure.
|
|
55
|
+
if (!quiet) {
|
|
56
|
+
console.log(chalk.gray(' Ensuring infrastructure services are running...'));
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
execSync(`docker compose -f "${cp}" up -d --remove-orphans`, {
|
|
60
|
+
stdio: 'pipe',
|
|
61
|
+
timeout: 120000,
|
|
62
|
+
});
|
|
63
|
+
// Brief wait for health checks on core services
|
|
64
|
+
for (let i = 0; i < 15; i++) {
|
|
65
|
+
try {
|
|
66
|
+
const health = execSync(`docker compose -f "${cp}" ps --format json`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
67
|
+
// Check if core services (non-init) are healthy/running
|
|
68
|
+
const lines = health.trim().split('\n').filter(Boolean);
|
|
69
|
+
const coreServices = lines
|
|
70
|
+
.map((l) => { try {
|
|
71
|
+
return JSON.parse(l);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
} })
|
|
76
|
+
.filter((s) => s && !s.Service?.includes('-init'));
|
|
77
|
+
const allHealthy = coreServices.length > 0 && coreServices.every((s) => s.Health === 'healthy' || s.State === 'running');
|
|
78
|
+
if (allHealthy)
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
catch { /* ignore */ }
|
|
82
|
+
// Sleep 1s between checks
|
|
83
|
+
execSync('sleep 1', { stdio: 'pipe' });
|
|
84
|
+
}
|
|
85
|
+
if (!quiet) {
|
|
86
|
+
console.log(chalk.green(' ✓ Services ready\n'));
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
if (!quiet) {
|
|
92
|
+
console.error(chalk.red('\n❌ Failed to start infrastructure services.'));
|
|
93
|
+
console.error(chalk.dim(` Try manually: docker compose -f ~/.vk/docker-compose.yml up -d\n`));
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Restart pgweb to point at a specific project database.
|
|
100
|
+
* This ensures `vk open db` always shows the current project's DB.
|
|
101
|
+
*/
|
|
102
|
+
export function switchPgwebDatabase(dbName) {
|
|
103
|
+
const cp = composePath();
|
|
104
|
+
const dbUrl = `postgres://postgres:postgres@postgres:5432/${dbName}?sslmode=disable`;
|
|
105
|
+
try {
|
|
106
|
+
// Recreate pgweb with the target database URL via env override.
|
|
107
|
+
// --force-recreate ensures a fresh container even if already running.
|
|
108
|
+
// --remove-orphans cleans up any stale containers from older CLI versions.
|
|
109
|
+
execSync(`PGWEB_DATABASE_URL="${dbUrl}" docker compose -f "${cp}" up -d --force-recreate --remove-orphans pgweb`, { stdio: 'pipe', timeout: 30000 });
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Fallback: start via compose up (uses default DB from compose file)
|
|
113
|
+
try {
|
|
114
|
+
execSync(`docker compose -f "${cp}" up -d --remove-orphans pgweb`, { stdio: 'pipe', timeout: 30000 });
|
|
115
|
+
}
|
|
116
|
+
catch { }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Open a URL in the default browser (cross-platform).
|
|
121
|
+
*/
|
|
122
|
+
export function openBrowser(url) {
|
|
123
|
+
const cmd = process.platform === 'darwin' ? 'open' :
|
|
124
|
+
process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
125
|
+
try {
|
|
126
|
+
execSync(`${cmd} "${url}"`, { stdio: 'ignore' });
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
console.log(chalk.dim(` Open manually: ${url}`));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=docker.js.map
|