suthep 1.0.0

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.
Files changed (83) hide show
  1. package/.editorconfig +17 -0
  2. package/.github/workflows/publish.yml +42 -0
  3. package/.prettierignore +6 -0
  4. package/.prettierrc +7 -0
  5. package/.scannerwork/.sonar_lock +0 -0
  6. package/.scannerwork/report-task.txt +6 -0
  7. package/.vscode/settings.json +19 -0
  8. package/LICENSE +21 -0
  9. package/README.md +317 -0
  10. package/dist/commands/deploy.js +371 -0
  11. package/dist/commands/deploy.js.map +1 -0
  12. package/dist/commands/down.js +179 -0
  13. package/dist/commands/down.js.map +1 -0
  14. package/dist/commands/init.js +188 -0
  15. package/dist/commands/init.js.map +1 -0
  16. package/dist/commands/setup.js +90 -0
  17. package/dist/commands/setup.js.map +1 -0
  18. package/dist/commands/up.js +213 -0
  19. package/dist/commands/up.js.map +1 -0
  20. package/dist/index.js +66 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/utils/certbot.js +64 -0
  23. package/dist/utils/certbot.js.map +1 -0
  24. package/dist/utils/config-loader.js +127 -0
  25. package/dist/utils/config-loader.js.map +1 -0
  26. package/dist/utils/deployment.js +85 -0
  27. package/dist/utils/deployment.js.map +1 -0
  28. package/dist/utils/docker.js +425 -0
  29. package/dist/utils/docker.js.map +1 -0
  30. package/dist/utils/env-loader.js +53 -0
  31. package/dist/utils/env-loader.js.map +1 -0
  32. package/dist/utils/nginx.js +378 -0
  33. package/dist/utils/nginx.js.map +1 -0
  34. package/docs/README.md +38 -0
  35. package/docs/english/01-introduction.md +84 -0
  36. package/docs/english/02-installation.md +200 -0
  37. package/docs/english/03-quick-start.md +258 -0
  38. package/docs/english/04-configuration.md +433 -0
  39. package/docs/english/05-commands.md +336 -0
  40. package/docs/english/06-examples.md +456 -0
  41. package/docs/english/07-troubleshooting.md +417 -0
  42. package/docs/english/08-advanced.md +411 -0
  43. package/docs/english/README.md +48 -0
  44. package/docs/thai/01-introduction.md +84 -0
  45. package/docs/thai/02-installation.md +200 -0
  46. package/docs/thai/03-quick-start.md +258 -0
  47. package/docs/thai/04-configuration.md +433 -0
  48. package/docs/thai/05-commands.md +336 -0
  49. package/docs/thai/06-examples.md +456 -0
  50. package/docs/thai/07-troubleshooting.md +417 -0
  51. package/docs/thai/08-advanced.md +411 -0
  52. package/docs/thai/README.md +48 -0
  53. package/example/suthep-complete.yml +103 -0
  54. package/example/suthep-docker-only.yml +71 -0
  55. package/example/suthep-env-example.yml +113 -0
  56. package/example/suthep-no-docker.yml +51 -0
  57. package/example/suthep-path-routing.yml +62 -0
  58. package/example/suthep.example.yml +88 -0
  59. package/package.json +51 -0
  60. package/src/commands/deploy.ts +488 -0
  61. package/src/commands/down.ts +240 -0
  62. package/src/commands/init.ts +214 -0
  63. package/src/commands/setup.ts +112 -0
  64. package/src/commands/up.ts +271 -0
  65. package/src/index.ts +109 -0
  66. package/src/types/config.ts +52 -0
  67. package/src/utils/__tests__/certbot.test.ts +222 -0
  68. package/src/utils/__tests__/config-loader.test.ts +419 -0
  69. package/src/utils/__tests__/deployment.test.ts +243 -0
  70. package/src/utils/__tests__/nginx.test.ts +412 -0
  71. package/src/utils/certbot.ts +144 -0
  72. package/src/utils/config-loader.ts +184 -0
  73. package/src/utils/deployment.ts +157 -0
  74. package/src/utils/docker.ts +768 -0
  75. package/src/utils/env-loader.ts +135 -0
  76. package/src/utils/nginx.ts +443 -0
  77. package/suthep-1.0.0.tgz +0 -0
  78. package/suthep.example.yml +98 -0
  79. package/suthep.yml +39 -0
  80. package/todo.md +6 -0
  81. package/tsconfig.json +26 -0
  82. package/vite.config.ts +46 -0
  83. package/vitest.config.ts +21 -0
@@ -0,0 +1,371 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs-extra";
3
+ import { certificateExists, requestCertificate } from "../utils/certbot.js";
4
+ import { loadConfig } from "../utils/config-loader.js";
5
+ import { deployService, performHealthCheck } from "../utils/deployment.js";
6
+ import { startDockerContainerZeroDowntime, startDockerContainer, swapContainersForZeroDowntime, cleanupTempContainer } from "../utils/docker.js";
7
+ import { getCanonicalDomain, generateNginxConfig, generateMultiServiceNginxConfig, writeNginxConfig, enableSite, reloadNginx } from "../utils/nginx.js";
8
+ async function deployCommand(options) {
9
+ console.log(chalk.blue.bold("\nšŸš€ Deploying Services\n"));
10
+ try {
11
+ if (!await fs.pathExists(options.file)) {
12
+ throw new Error(`Configuration file not found: ${options.file}`);
13
+ }
14
+ console.log(chalk.cyan(`šŸ“„ Loading configuration from ${options.file}...`));
15
+ const config = await loadConfig(options.file);
16
+ let servicesToDeploy = [];
17
+ if (options.serviceName) {
18
+ const service = config.services.find((s) => s.name === options.serviceName);
19
+ if (!service) {
20
+ throw new Error(
21
+ `Service "${options.serviceName}" not found in configuration. Available services: ${config.services.map((s) => s.name).join(", ")}`
22
+ );
23
+ }
24
+ servicesToDeploy = [service];
25
+ console.log(chalk.green(`āœ… Configuration loaded for project: ${config.project.name}`));
26
+ console.log(chalk.cyan(`šŸ“‹ Deploying service: ${options.serviceName}
27
+ `));
28
+ } else {
29
+ servicesToDeploy = config.services;
30
+ console.log(chalk.green(`āœ… Configuration loaded for project: ${config.project.name}`));
31
+ console.log(
32
+ chalk.cyan(`šŸ“‹ Deploying all services: ${servicesToDeploy.map((s) => s.name).join(", ")}
33
+ `)
34
+ );
35
+ }
36
+ const domainToServices = /* @__PURE__ */ new Map();
37
+ const allDomains = /* @__PURE__ */ new Set();
38
+ for (const service of servicesToDeploy) {
39
+ for (const domain of service.domains) {
40
+ allDomains.add(domain);
41
+ }
42
+ }
43
+ const servicesForNginx = options.serviceName ? config.services.filter((service) => {
44
+ return service.domains.some((domain) => allDomains.has(domain));
45
+ }) : servicesToDeploy;
46
+ if (options.serviceName && servicesForNginx.length > servicesToDeploy.length) {
47
+ const additionalServices = servicesForNginx.filter(
48
+ (s) => !servicesToDeploy.some((d) => d.name === s.name)
49
+ );
50
+ console.log(
51
+ chalk.cyan(
52
+ ` šŸ“‹ Including ${additionalServices.length} additional service(s) in nginx config: ${additionalServices.map((s) => s.name).join(", ")}`
53
+ )
54
+ );
55
+ }
56
+ const canonicalDomains = /* @__PURE__ */ new Set();
57
+ for (const service of servicesForNginx) {
58
+ for (const domain of service.domains) {
59
+ if (allDomains.has(domain)) {
60
+ const canonicalDomain = getCanonicalDomain(domain, allDomains);
61
+ canonicalDomains.add(canonicalDomain);
62
+ if (!domainToServices.has(canonicalDomain)) {
63
+ domainToServices.set(canonicalDomain, []);
64
+ }
65
+ if (!domainToServices.get(canonicalDomain).some((s) => s.name === service.name)) {
66
+ domainToServices.get(canonicalDomain).push(service);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ const serviceTempInfo = /* @__PURE__ */ new Map();
72
+ for (const service of servicesToDeploy) {
73
+ console.log(chalk.cyan(`
74
+ šŸ“¦ Deploying service: ${service.name}`));
75
+ try {
76
+ if (service.docker) {
77
+ console.log(chalk.dim(" 🐳 Managing Docker container..."));
78
+ if (config.deployment.strategy === "blue-green" || config.deployment.strategy === "rolling") {
79
+ const tempInfo2 = await startDockerContainerZeroDowntime(service, options.cliEnvVars);
80
+ serviceTempInfo.set(service.name, tempInfo2);
81
+ if (tempInfo2 && tempInfo2.oldContainerExists) {
82
+ console.log(
83
+ chalk.cyan(
84
+ ` šŸ”„ Zero-downtime deployment: new container on port ${tempInfo2.tempPort}`
85
+ )
86
+ );
87
+ }
88
+ } else {
89
+ await startDockerContainer(service, options.cliEnvVars);
90
+ serviceTempInfo.set(service.name, null);
91
+ }
92
+ } else {
93
+ serviceTempInfo.set(service.name, null);
94
+ }
95
+ const tempInfo = serviceTempInfo.get(service.name) || null;
96
+ await deployService(service, config.deployment, tempInfo);
97
+ if (service.healthCheck) {
98
+ console.log(chalk.dim(` šŸ„ Performing health check...`));
99
+ const checkPort = tempInfo && tempInfo.oldContainerExists ? tempInfo.tempPort : service.port;
100
+ const isHealthy = await performHealthCheck(
101
+ `http://localhost:${checkPort}${service.healthCheck.path}`,
102
+ config.deployment.healthCheckTimeout
103
+ );
104
+ if (isHealthy) {
105
+ console.log(chalk.green(` āœ… Service ${service.name} is healthy`));
106
+ } else {
107
+ throw new Error(`Health check failed for service ${service.name}`);
108
+ }
109
+ }
110
+ console.log(chalk.green.bold(`✨ Service ${service.name} deployed successfully!`));
111
+ } catch (error) {
112
+ console.error(
113
+ chalk.red(`
114
+ āŒ Failed to deploy service ${service.name}:`),
115
+ error instanceof Error ? error.message : error
116
+ );
117
+ throw error;
118
+ }
119
+ }
120
+ const generateNginxConfigsForDomain = (domain, withHttps, portOverrides) => {
121
+ const servicesForDomain = domainToServices.get(domain);
122
+ if (servicesForDomain.length === 1) {
123
+ const service = servicesForDomain[0];
124
+ const portOverride = portOverrides?.get(service.name);
125
+ return generateNginxConfig(service, withHttps, portOverride);
126
+ } else {
127
+ return generateMultiServiceNginxConfig(servicesForDomain, domain, withHttps, portOverrides);
128
+ }
129
+ };
130
+ const needsZeroDowntimeNginx = Array.from(serviceTempInfo.values()).some(
131
+ (info) => info !== null && info.oldContainerExists
132
+ );
133
+ if (options.nginx) {
134
+ if (needsZeroDowntimeNginx) {
135
+ console.log(chalk.cyan(`
136
+ āš™ļø Updating Nginx for zero-downtime deployment...`));
137
+ const tempPortOverrides = /* @__PURE__ */ new Map();
138
+ for (const service of servicesToDeploy) {
139
+ const tempInfo = serviceTempInfo.get(service.name);
140
+ if (tempInfo && tempInfo.oldContainerExists) {
141
+ tempPortOverrides.set(service.name, tempInfo.tempPort);
142
+ }
143
+ }
144
+ for (const canonicalDomain of canonicalDomains) {
145
+ const configName = canonicalDomain.replace(/\./g, "_");
146
+ try {
147
+ const nginxConfigContent = generateNginxConfigsForDomain(
148
+ canonicalDomain,
149
+ false,
150
+ tempPortOverrides
151
+ );
152
+ await writeNginxConfig(configName, config.nginx.configPath, nginxConfigContent);
153
+ await enableSite(configName, config.nginx.configPath);
154
+ console.log(chalk.green(` āœ… Nginx updated for ${canonicalDomain} (temporary ports)`));
155
+ } catch (error) {
156
+ console.error(
157
+ chalk.red(` āŒ Failed to update Nginx for ${canonicalDomain}:`),
158
+ error instanceof Error ? error.message : error
159
+ );
160
+ throw error;
161
+ }
162
+ }
163
+ console.log(chalk.cyan(`
164
+ šŸ”„ Reloading Nginx to switch to new containers...`));
165
+ await reloadNginx(config.nginx.reloadCommand);
166
+ console.log(chalk.green(` āœ… Nginx reloaded, traffic now routed to new containers`));
167
+ console.log(chalk.cyan(`
168
+ šŸ”„ Swapping containers for zero-downtime...`));
169
+ for (const service of servicesToDeploy) {
170
+ const tempInfo = serviceTempInfo.get(service.name);
171
+ if (tempInfo && tempInfo.oldContainerExists && service.docker) {
172
+ try {
173
+ await swapContainersForZeroDowntime(service, tempInfo, options.cliEnvVars);
174
+ console.log(chalk.green(` āœ… Container swapped for ${service.name}`));
175
+ } catch (error) {
176
+ console.error(
177
+ chalk.red(` āŒ Failed to swap container for ${service.name}:`),
178
+ error instanceof Error ? error.message : error
179
+ );
180
+ throw error;
181
+ }
182
+ }
183
+ }
184
+ console.log(chalk.cyan(`
185
+ āš™ļø Updating Nginx back to production ports...`));
186
+ for (const canonicalDomain of canonicalDomains) {
187
+ const configName = canonicalDomain.replace(/\./g, "_");
188
+ try {
189
+ const nginxConfigContent = generateNginxConfigsForDomain(canonicalDomain, false);
190
+ await writeNginxConfig(configName, config.nginx.configPath, nginxConfigContent);
191
+ await enableSite(configName, config.nginx.configPath);
192
+ console.log(chalk.green(` āœ… Nginx updated for ${canonicalDomain} (production ports)`));
193
+ } catch (error) {
194
+ console.error(
195
+ chalk.red(` āŒ Failed to update Nginx for ${canonicalDomain}:`),
196
+ error instanceof Error ? error.message : error
197
+ );
198
+ throw error;
199
+ }
200
+ }
201
+ console.log(chalk.cyan(`
202
+ šŸ”„ Reloading Nginx to switch to production ports...`));
203
+ await reloadNginx(config.nginx.reloadCommand);
204
+ console.log(chalk.green(` āœ… Nginx reloaded, traffic now routed to production containers`));
205
+ console.log(chalk.cyan(`
206
+ 🧹 Cleaning up temporary containers...`));
207
+ for (const service of servicesToDeploy) {
208
+ const tempInfo = serviceTempInfo.get(service.name);
209
+ if (tempInfo && tempInfo.oldContainerExists) {
210
+ await cleanupTempContainer(tempInfo.tempContainerName);
211
+ }
212
+ }
213
+ } else {
214
+ console.log(chalk.cyan(`
215
+ āš™ļø Configuring Nginx reverse proxy...`));
216
+ for (const canonicalDomain of canonicalDomains) {
217
+ const servicesForDomain = domainToServices.get(canonicalDomain);
218
+ const configName = canonicalDomain.replace(/\./g, "_");
219
+ try {
220
+ if (servicesForDomain.length > 1) {
221
+ console.log(
222
+ chalk.cyan(
223
+ ` šŸ“‹ Configuring ${canonicalDomain} with ${servicesForDomain.length} services: ${servicesForDomain.map((s) => s.name).join(", ")}`
224
+ )
225
+ );
226
+ console.log(
227
+ chalk.dim(
228
+ ` All services will share the same nginx config file: ${configName}.conf`
229
+ )
230
+ );
231
+ } else {
232
+ console.log(
233
+ chalk.cyan(
234
+ ` šŸ“‹ Configuring ${canonicalDomain} with service: ${servicesForDomain[0].name}`
235
+ )
236
+ );
237
+ }
238
+ const nginxConfigContent = generateNginxConfigsForDomain(canonicalDomain, false);
239
+ const wasOverridden = await writeNginxConfig(
240
+ configName,
241
+ config.nginx.configPath,
242
+ nginxConfigContent
243
+ );
244
+ if (wasOverridden) {
245
+ console.log(
246
+ chalk.yellow(
247
+ ` šŸ”„ Nginx config "${configName}.conf" already exists, deleting and recreating with new configuration...`
248
+ )
249
+ );
250
+ }
251
+ await enableSite(configName, config.nginx.configPath);
252
+ console.log(chalk.green(` āœ… Nginx configured for ${canonicalDomain}`));
253
+ } catch (error) {
254
+ console.error(
255
+ chalk.red(` āŒ Failed to configure Nginx for ${canonicalDomain}:`),
256
+ error instanceof Error ? error.message : error
257
+ );
258
+ throw error;
259
+ }
260
+ }
261
+ }
262
+ }
263
+ if (options.https && canonicalDomains.size > 0) {
264
+ console.log(chalk.cyan(`
265
+ šŸ” Setting up HTTPS certificates...`));
266
+ for (const canonicalDomain of canonicalDomains) {
267
+ try {
268
+ const exists = await certificateExists(canonicalDomain);
269
+ if (exists) {
270
+ console.log(
271
+ chalk.green(
272
+ ` āœ… SSL certificate already exists for ${canonicalDomain}, skipping certificate creation`
273
+ )
274
+ );
275
+ console.log(
276
+ chalk.dim(
277
+ ` Using existing certificate from /etc/letsencrypt/live/${canonicalDomain}/`
278
+ )
279
+ );
280
+ } else {
281
+ console.log(chalk.cyan(` šŸ“œ Requesting SSL certificate for ${canonicalDomain}...`));
282
+ try {
283
+ await requestCertificate(
284
+ canonicalDomain,
285
+ config.certbot.email,
286
+ config.certbot.staging
287
+ );
288
+ console.log(chalk.green(` āœ… SSL certificate obtained for ${canonicalDomain}`));
289
+ } catch (error) {
290
+ const errorMessage = error?.message || String(error) || "";
291
+ if (errorMessage.includes("already exists") || errorMessage.includes("Skipping certificate creation")) {
292
+ console.log(
293
+ chalk.green(
294
+ ` āœ… SSL certificate already exists for ${canonicalDomain} (detected during request), skipping...`
295
+ )
296
+ );
297
+ } else {
298
+ throw error;
299
+ }
300
+ }
301
+ }
302
+ } catch (error) {
303
+ console.log(
304
+ chalk.yellow(
305
+ ` āš ļø Failed to obtain SSL for ${canonicalDomain}: ${error instanceof Error ? error.message : error}`
306
+ )
307
+ );
308
+ }
309
+ }
310
+ if (options.nginx) {
311
+ console.log(chalk.cyan(`
312
+ šŸ”„ Updating Nginx configs with HTTPS...`));
313
+ for (const canonicalDomain of canonicalDomains) {
314
+ const configName = canonicalDomain.replace(/\./g, "_");
315
+ try {
316
+ const nginxConfigContent = generateNginxConfigsForDomain(canonicalDomain, true);
317
+ const wasOverridden = await writeNginxConfig(
318
+ configName,
319
+ config.nginx.configPath,
320
+ nginxConfigContent
321
+ );
322
+ if (wasOverridden) {
323
+ console.log(
324
+ chalk.yellow(
325
+ ` šŸ”„ Nginx config "${configName}.conf" already exists, deleting and recreating with new HTTPS configuration...`
326
+ )
327
+ );
328
+ }
329
+ console.log(chalk.green(` āœ… HTTPS config updated for ${canonicalDomain}`));
330
+ } catch (error) {
331
+ console.error(
332
+ chalk.red(` āŒ Failed to update HTTPS config for ${canonicalDomain}:`),
333
+ error instanceof Error ? error.message : error
334
+ );
335
+ throw error;
336
+ }
337
+ }
338
+ }
339
+ }
340
+ if (options.nginx && !needsZeroDowntimeNginx) {
341
+ console.log(chalk.cyan(`
342
+ šŸ”„ Reloading Nginx...`));
343
+ await reloadNginx(config.nginx.reloadCommand);
344
+ } else if (options.nginx && needsZeroDowntimeNginx) {
345
+ console.log(chalk.cyan(`
346
+ šŸ”„ Final Nginx reload with HTTPS...`));
347
+ await reloadNginx(config.nginx.reloadCommand);
348
+ }
349
+ console.log(chalk.green.bold("\nšŸŽ‰ All services deployed successfully!\n"));
350
+ console.log(chalk.cyan("šŸ“‹ Service URLs:"));
351
+ for (const service of servicesToDeploy) {
352
+ for (const domain of service.domains) {
353
+ const protocol = options.https ? "https" : "http";
354
+ const servicePath = service.path || "/";
355
+ const fullPath = servicePath === "/" ? "" : servicePath;
356
+ console.log(chalk.dim(` ${service.name}: ${protocol}://${domain}${fullPath}`));
357
+ }
358
+ }
359
+ console.log();
360
+ } catch (error) {
361
+ console.error(
362
+ chalk.red("\nāŒ Deployment failed:"),
363
+ error instanceof Error ? error.message : error
364
+ );
365
+ process.exit(1);
366
+ }
367
+ }
368
+ export {
369
+ deployCommand
370
+ };
371
+ //# sourceMappingURL=deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.js","sources":["../../src/commands/deploy.ts"],"sourcesContent":["import chalk from 'chalk'\nimport fs from 'fs-extra'\nimport type { ServiceConfig } from '../types/config'\nimport { certificateExists, requestCertificate } from '../utils/certbot'\nimport { loadConfig } from '../utils/config-loader'\nimport { deployService, performHealthCheck } from '../utils/deployment'\nimport {\n cleanupTempContainer,\n startDockerContainer,\n startDockerContainerZeroDowntime,\n swapContainersForZeroDowntime,\n type ZeroDowntimeContainerInfo,\n} from '../utils/docker'\nimport {\n enableSite,\n generateMultiServiceNginxConfig,\n generateNginxConfig,\n getCanonicalDomain,\n reloadNginx,\n writeNginxConfig,\n} from '../utils/nginx'\n\ninterface DeployOptions {\n file: string\n https: boolean\n nginx: boolean\n serviceName?: string\n cliEnvVars?: Record<string, string>\n}\n\nexport async function deployCommand(options: DeployOptions): Promise<void> {\n console.log(chalk.blue.bold('\\nšŸš€ Deploying Services\\n'))\n\n try {\n // Load configuration (this will also load .env files for variable substitution)\n if (!(await fs.pathExists(options.file))) {\n throw new Error(`Configuration file not found: ${options.file}`)\n }\n\n console.log(chalk.cyan(`šŸ“„ Loading configuration from ${options.file}...`))\n const config = await loadConfig(options.file)\n\n // Filter services based on serviceName if provided\n let servicesToDeploy: ServiceConfig[] = []\n if (options.serviceName) {\n const service = config.services.find((s) => s.name === options.serviceName)\n if (!service) {\n throw new Error(\n `Service \"${\n options.serviceName\n }\" not found in configuration. Available services: ${config.services\n .map((s) => s.name)\n .join(', ')}`\n )\n }\n servicesToDeploy = [service]\n console.log(chalk.green(`āœ… Configuration loaded for project: ${config.project.name}`))\n console.log(chalk.cyan(`šŸ“‹ Deploying service: ${options.serviceName}\\n`))\n } else {\n servicesToDeploy = config.services\n console.log(chalk.green(`āœ… Configuration loaded for project: ${config.project.name}`))\n console.log(\n chalk.cyan(`šŸ“‹ Deploying all services: ${servicesToDeploy.map((s) => s.name).join(', ')}\\n`)\n )\n }\n\n // Group services by domain\n // When deploying a single service, include ALL services from config that share the same domain(s)\n // This ensures nginx config includes both old and new services\n const domainToServices = new Map<string, ServiceConfig[]>()\n const allDomains = new Set<string>()\n\n // Collect all domains from services being deployed\n for (const service of servicesToDeploy) {\n for (const domain of service.domains) {\n allDomains.add(domain)\n }\n }\n\n // If deploying a single service, include all services that share the same domain(s)\n // Otherwise, use only services being deployed\n const servicesForNginx = options.serviceName\n ? config.services.filter((service) => {\n // Include service if it shares any domain with services being deployed\n return service.domains.some((domain) => allDomains.has(domain))\n })\n : servicesToDeploy\n\n // Log when additional services are included in nginx config\n if (options.serviceName && servicesForNginx.length > servicesToDeploy.length) {\n const additionalServices = servicesForNginx.filter(\n (s) => !servicesToDeploy.some((d) => d.name === s.name)\n )\n console.log(\n chalk.cyan(\n ` šŸ“‹ Including ${\n additionalServices.length\n } additional service(s) in nginx config: ${additionalServices\n .map((s) => s.name)\n .join(', ')}`\n )\n )\n }\n\n // Group services by canonical domain for nginx configuration\n // This ensures www and non-www root domains use the same config file\n const canonicalDomains = new Set<string>()\n for (const service of servicesForNginx) {\n for (const domain of service.domains) {\n if (allDomains.has(domain)) {\n // Get canonical domain (www if both exist, otherwise the domain itself)\n const canonicalDomain = getCanonicalDomain(domain, allDomains)\n canonicalDomains.add(canonicalDomain)\n\n // Group services by canonical domain\n if (!domainToServices.has(canonicalDomain)) {\n domainToServices.set(canonicalDomain, [])\n }\n // Only add service if not already added for this canonical domain\n if (!domainToServices.get(canonicalDomain)!.some((s) => s.name === service.name)) {\n domainToServices.get(canonicalDomain)!.push(service)\n }\n }\n }\n }\n\n // Deploy each service (Docker, health checks, etc.)\n // Track zero-downtime info for services that need it\n const serviceTempInfo = new Map<string, ZeroDowntimeContainerInfo | null>()\n\n for (const service of servicesToDeploy) {\n console.log(chalk.cyan(`\\nšŸ“¦ Deploying service: ${service.name}`))\n\n try {\n // Start Docker container if configured\n if (service.docker) {\n console.log(chalk.dim(' 🐳 Managing Docker container...'))\n\n // Use zero-downtime deployment if strategy is blue-green or rolling\n if (\n config.deployment.strategy === 'blue-green' ||\n config.deployment.strategy === 'rolling'\n ) {\n const tempInfo = await startDockerContainerZeroDowntime(service, options.cliEnvVars)\n serviceTempInfo.set(service.name, tempInfo)\n\n if (tempInfo && tempInfo.oldContainerExists) {\n console.log(\n chalk.cyan(\n ` šŸ”„ Zero-downtime deployment: new container on port ${tempInfo.tempPort}`\n )\n )\n }\n } else {\n // Fallback to regular deployment\n await startDockerContainer(service, options.cliEnvVars)\n serviceTempInfo.set(service.name, null)\n }\n } else {\n serviceTempInfo.set(service.name, null)\n }\n\n // Deploy the service (with temp info for zero-downtime)\n const tempInfo = serviceTempInfo.get(service.name) || null\n await deployService(service, config.deployment, tempInfo)\n\n // Perform health check on appropriate port\n if (service.healthCheck) {\n console.log(chalk.dim(` šŸ„ Performing health check...`))\n const checkPort =\n tempInfo && tempInfo.oldContainerExists ? tempInfo.tempPort : service.port\n const isHealthy = await performHealthCheck(\n `http://localhost:${checkPort}${service.healthCheck.path}`,\n config.deployment.healthCheckTimeout\n )\n\n if (isHealthy) {\n console.log(chalk.green(` āœ… Service ${service.name} is healthy`))\n } else {\n throw new Error(`Health check failed for service ${service.name}`)\n }\n }\n\n console.log(chalk.green.bold(`✨ Service ${service.name} deployed successfully!`))\n } catch (error) {\n console.error(\n chalk.red(`\\nāŒ Failed to deploy service ${service.name}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n\n // Helper function to generate nginx configs with optional port overrides\n const generateNginxConfigsForDomain = (\n domain: string,\n withHttps: boolean,\n portOverrides?: Map<string, number>\n ): string => {\n const servicesForDomain = domainToServices.get(domain)!\n if (servicesForDomain.length === 1) {\n const service = servicesForDomain[0]\n const portOverride = portOverrides?.get(service.name)\n return generateNginxConfig(service, withHttps, portOverride)\n } else {\n return generateMultiServiceNginxConfig(servicesForDomain, domain, withHttps, portOverrides)\n }\n }\n\n // Check if we need zero-downtime nginx updates (any service has temp container)\n const needsZeroDowntimeNginx = Array.from(serviceTempInfo.values()).some(\n (info) => info !== null && info.oldContainerExists\n )\n\n // Configure Nginx per domain\n if (options.nginx) {\n // If zero-downtime, first update nginx to point to temp ports\n if (needsZeroDowntimeNginx) {\n console.log(chalk.cyan(`\\nāš™ļø Updating Nginx for zero-downtime deployment...`))\n\n // Build port override map for temp ports\n const tempPortOverrides = new Map<string, number>()\n for (const service of servicesToDeploy) {\n const tempInfo = serviceTempInfo.get(service.name)\n if (tempInfo && tempInfo.oldContainerExists) {\n tempPortOverrides.set(service.name, tempInfo.tempPort)\n }\n }\n\n for (const canonicalDomain of canonicalDomains) {\n const configName = canonicalDomain.replace(/\\./g, '_')\n try {\n const nginxConfigContent = generateNginxConfigsForDomain(\n canonicalDomain,\n false,\n tempPortOverrides\n )\n await writeNginxConfig(configName, config.nginx.configPath, nginxConfigContent)\n await enableSite(configName, config.nginx.configPath)\n console.log(chalk.green(` āœ… Nginx updated for ${canonicalDomain} (temporary ports)`))\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to update Nginx for ${canonicalDomain}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n\n // Reload nginx to switch to temp ports (graceful reload, no connection drops)\n console.log(chalk.cyan(`\\nšŸ”„ Reloading Nginx to switch to new containers...`))\n await reloadNginx(config.nginx.reloadCommand)\n console.log(chalk.green(` āœ… Nginx reloaded, traffic now routed to new containers`))\n\n // Now swap containers (stop old, promote new)\n console.log(chalk.cyan(`\\nšŸ”„ Swapping containers for zero-downtime...`))\n for (const service of servicesToDeploy) {\n const tempInfo = serviceTempInfo.get(service.name)\n if (tempInfo && tempInfo.oldContainerExists && service.docker) {\n try {\n await swapContainersForZeroDowntime(service, tempInfo, options.cliEnvVars)\n console.log(chalk.green(` āœ… Container swapped for ${service.name}`))\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to swap container for ${service.name}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n }\n\n // Update nginx back to original ports (before stopping temp containers)\n console.log(chalk.cyan(`\\nāš™ļø Updating Nginx back to production ports...`))\n for (const canonicalDomain of canonicalDomains) {\n const configName = canonicalDomain.replace(/\\./g, '_')\n try {\n const nginxConfigContent = generateNginxConfigsForDomain(canonicalDomain, false)\n await writeNginxConfig(configName, config.nginx.configPath, nginxConfigContent)\n await enableSite(configName, config.nginx.configPath)\n console.log(chalk.green(` āœ… Nginx updated for ${canonicalDomain} (production ports)`))\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to update Nginx for ${canonicalDomain}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n\n // Reload nginx to switch to production ports (graceful reload)\n console.log(chalk.cyan(`\\nšŸ”„ Reloading Nginx to switch to production ports...`))\n await reloadNginx(config.nginx.reloadCommand)\n console.log(chalk.green(` āœ… Nginx reloaded, traffic now routed to production containers`))\n\n // Clean up temp containers (nginx already pointing to production, so safe to remove)\n console.log(chalk.cyan(`\\n🧹 Cleaning up temporary containers...`))\n for (const service of servicesToDeploy) {\n const tempInfo = serviceTempInfo.get(service.name)\n if (tempInfo && tempInfo.oldContainerExists) {\n await cleanupTempContainer(tempInfo.tempContainerName)\n }\n }\n } else {\n // Regular nginx configuration (no zero-downtime needed)\n console.log(chalk.cyan(`\\nāš™ļø Configuring Nginx reverse proxy...`))\n\n for (const canonicalDomain of canonicalDomains) {\n const servicesForDomain = domainToServices.get(canonicalDomain)!\n const configName = canonicalDomain.replace(/\\./g, '_')\n\n try {\n // Log domain and services configuration\n if (servicesForDomain.length > 1) {\n console.log(\n chalk.cyan(\n ` šŸ“‹ Configuring ${canonicalDomain} with ${\n servicesForDomain.length\n } services: ${servicesForDomain.map((s) => s.name).join(', ')}`\n )\n )\n console.log(\n chalk.dim(\n ` All services will share the same nginx config file: ${configName}.conf`\n )\n )\n } else {\n // Single service, but log it anyway for clarity\n console.log(\n chalk.cyan(\n ` šŸ“‹ Configuring ${canonicalDomain} with service: ${servicesForDomain[0].name}`\n )\n )\n }\n\n // Generate Nginx config\n const nginxConfigContent = generateNginxConfigsForDomain(canonicalDomain, false)\n\n // Check if config file already exists and write/override it\n const wasOverridden = await writeNginxConfig(\n configName,\n config.nginx.configPath,\n nginxConfigContent\n )\n\n if (wasOverridden) {\n console.log(\n chalk.yellow(\n ` šŸ”„ Nginx config \"${configName}.conf\" already exists, deleting and recreating with new configuration...`\n )\n )\n }\n\n await enableSite(configName, config.nginx.configPath)\n\n console.log(chalk.green(` āœ… Nginx configured for ${canonicalDomain}`))\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to configure Nginx for ${canonicalDomain}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n }\n }\n\n // Setup HTTPS with Certbot (per canonical domain, not per service)\n if (options.https && canonicalDomains.size > 0) {\n console.log(chalk.cyan(`\\nšŸ” Setting up HTTPS certificates...`))\n\n for (const canonicalDomain of canonicalDomains) {\n try {\n // Check if certificate already exists\n const exists = await certificateExists(canonicalDomain)\n if (exists) {\n console.log(\n chalk.green(\n ` āœ… SSL certificate already exists for ${canonicalDomain}, skipping certificate creation`\n )\n )\n console.log(\n chalk.dim(\n ` Using existing certificate from /etc/letsencrypt/live/${canonicalDomain}/`\n )\n )\n } else {\n // Request new certificate\n console.log(chalk.cyan(` šŸ“œ Requesting SSL certificate for ${canonicalDomain}...`))\n try {\n await requestCertificate(\n canonicalDomain,\n config.certbot.email,\n config.certbot.staging\n )\n console.log(chalk.green(` āœ… SSL certificate obtained for ${canonicalDomain}`))\n } catch (error: any) {\n // Check if error is because certificate already exists (race condition or check missed it)\n const errorMessage = error?.message || String(error) || ''\n if (\n errorMessage.includes('already exists') ||\n errorMessage.includes('Skipping certificate creation')\n ) {\n console.log(\n chalk.green(\n ` āœ… SSL certificate already exists for ${canonicalDomain} (detected during request), skipping...`\n )\n )\n } else {\n throw error // Re-throw if it's a different error\n }\n }\n }\n } catch (error) {\n console.log(\n chalk.yellow(\n ` āš ļø Failed to obtain SSL for ${canonicalDomain}: ${\n error instanceof Error ? error.message : error\n }`\n )\n )\n }\n }\n\n // Update Nginx configs with HTTPS\n if (options.nginx) {\n console.log(chalk.cyan(`\\nšŸ”„ Updating Nginx configs with HTTPS...`))\n for (const canonicalDomain of canonicalDomains) {\n const configName = canonicalDomain.replace(/\\./g, '_')\n\n try {\n const nginxConfigContent = generateNginxConfigsForDomain(canonicalDomain, true)\n const wasOverridden = await writeNginxConfig(\n configName,\n config.nginx.configPath,\n nginxConfigContent\n )\n\n if (wasOverridden) {\n console.log(\n chalk.yellow(\n ` šŸ”„ Nginx config \"${configName}.conf\" already exists, deleting and recreating with new HTTPS configuration...`\n )\n )\n }\n console.log(chalk.green(` āœ… HTTPS config updated for ${canonicalDomain}`))\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to update HTTPS config for ${canonicalDomain}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n }\n }\n\n // Final reload Nginx after all configurations (only if we didn't already reload for zero-downtime)\n if (options.nginx && !needsZeroDowntimeNginx) {\n console.log(chalk.cyan(`\\nšŸ”„ Reloading Nginx...`))\n await reloadNginx(config.nginx.reloadCommand)\n } else if (options.nginx && needsZeroDowntimeNginx) {\n // Final reload after HTTPS update\n console.log(chalk.cyan(`\\nšŸ”„ Final Nginx reload with HTTPS...`))\n await reloadNginx(config.nginx.reloadCommand)\n }\n\n console.log(chalk.green.bold('\\nšŸŽ‰ All services deployed successfully!\\n'))\n\n // Print service URLs\n console.log(chalk.cyan('šŸ“‹ Service URLs:'))\n for (const service of servicesToDeploy) {\n for (const domain of service.domains) {\n const protocol = options.https ? 'https' : 'http'\n const servicePath = service.path || '/'\n const fullPath = servicePath === '/' ? '' : servicePath\n console.log(chalk.dim(` ${service.name}: ${protocol}://${domain}${fullPath}`))\n }\n }\n console.log()\n } catch (error) {\n console.error(\n chalk.red('\\nāŒ Deployment failed:'),\n error instanceof Error ? error.message : error\n )\n process.exit(1)\n }\n}\n"],"names":["tempInfo"],"mappings":";;;;;;;AA8BA,eAAsB,cAAc,SAAuC;AACzE,UAAQ,IAAI,MAAM,KAAK,KAAK,2BAA2B,CAAC;AAExD,MAAI;AAEF,QAAI,CAAE,MAAM,GAAG,WAAW,QAAQ,IAAI,GAAI;AACxC,YAAM,IAAI,MAAM,iCAAiC,QAAQ,IAAI,EAAE;AAAA,IACjE;AAEA,YAAQ,IAAI,MAAM,KAAK,iCAAiC,QAAQ,IAAI,KAAK,CAAC;AAC1E,UAAM,SAAS,MAAM,WAAW,QAAQ,IAAI;AAG5C,QAAI,mBAAoC,CAAA;AACxC,QAAI,QAAQ,aAAa;AACvB,YAAM,UAAU,OAAO,SAAS,KAAK,CAAC,MAAM,EA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AAAA,YAEJ;AACA,oBAAQ,IAAI,MAAM,MAAM,gCAAgC,eAAe,EAAE,CAAC;AAAA,UAC5E,SAAS,OAAO;AACd,oBAAQ;AAAA,cACN,MAAM,IAAI,yCAAyC,eAAe,GAAG;AAAA,cACrE,iBAAiB,QAAQ,MAAM,UAAU;AAAA,YAAA;AAE3C,kBAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,QAAI,QAAQ,SAAS,CAAC,wBAAwB;AAC5C,cAAQ,IAAI,MAAM,KAAK;AAAA,sBAAyB,CAAC;AACjD,YAAM,YAAY,OAAO,MAAM,aAAa;AAAA,IAC9C,WAAW,QAAQ,SAAS,wBAAwB;AAElD,cAAQ,IAAI,MAAM,KAAK;AAAA,oCAAuC,CAAC;AAC/D,YAAM,YAAY,OAAO,MAAM,aAAa;AAAA,IAC9C;AAEA,YAAQ,IAAI,MAAM,MAAM,KAAK,4CAA4C,CAAC;AAG1E,YAAQ,IAAI,MAAM,KAAK,kBAAkB,CAAC;AAC1C,eAAW,WAAW,kBAAkB;AACtC,iBAAW,UAAU,QAAQ,SAAS;AACpC,cAAM,WAAW,QAAQ,QAAQ,UAAU;AAC3C,cAAM,cAAc,QAAQ,QAAQ;AACpC,cAAM,WAAW,gBAAgB,MAAM,KAAK;AAC5C,gBAAQ,IAAI,MAAM,IAAI,MAAM,QAAQ,IAAI,KAAK,QAAQ,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;AAAA,MACjF;AAAA,IACF;AACA,YAAQ,IAAA;AAAA,EACV,SAAS,OAAO;AACd,YAAQ;AAAA,MACN,MAAM,IAAI,wBAAwB;AAAA,MAClC,iBAAiB,QAAQ,MAAM,UAAU;AAAA,IAAA;AAE3C,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;"}
@@ -0,0 +1,179 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs-extra";
3
+ import { loadConfig } from "../utils/config-loader.js";
4
+ import { stopDockerContainer, removeDockerContainer, isContainerRunning } from "../utils/docker.js";
5
+ import { disableSite, generateNginxConfig, generateMultiServiceNginxConfig, writeNginxConfig, enableSite, reloadNginx } from "../utils/nginx.js";
6
+ async function downCommand(options) {
7
+ console.log(chalk.blue.bold("\nšŸ›‘ Bringing Down Services\n"));
8
+ try {
9
+ if (!await fs.pathExists(options.file)) {
10
+ throw new Error(`Configuration file not found: ${options.file}`);
11
+ }
12
+ console.log(chalk.cyan(`šŸ“„ Loading configuration from ${options.file}...`));
13
+ const config = await loadConfig(options.file);
14
+ console.log(chalk.green(`āœ… Configuration loaded for project: ${config.project.name}`));
15
+ let servicesToDown = [];
16
+ if (options.all) {
17
+ servicesToDown = config.services;
18
+ console.log(
19
+ chalk.cyan(
20
+ `šŸ“‹ Bringing down all services: ${servicesToDown.map((s) => s.name).join(", ")}
21
+ `
22
+ )
23
+ );
24
+ } else if (options.serviceName) {
25
+ const service = config.services.find((s) => s.name === options.serviceName);
26
+ if (!service) {
27
+ throw new Error(
28
+ `Service "${options.serviceName}" not found in configuration. Available services: ${config.services.map((s) => s.name).join(", ")}`
29
+ );
30
+ }
31
+ servicesToDown = [service];
32
+ console.log(chalk.cyan(`šŸ“‹ Bringing down service: ${options.serviceName}
33
+ `));
34
+ } else {
35
+ throw new Error("Either specify a service name or use --all flag");
36
+ }
37
+ const domainToServices = /* @__PURE__ */ new Map();
38
+ const allDomains = /* @__PURE__ */ new Set();
39
+ for (const service of servicesToDown) {
40
+ for (const domain of service.domains) {
41
+ allDomains.add(domain);
42
+ if (!domainToServices.has(domain)) {
43
+ domainToServices.set(domain, []);
44
+ }
45
+ domainToServices.get(domain).push(service);
46
+ }
47
+ }
48
+ for (const service of servicesToDown) {
49
+ if (service.docker) {
50
+ console.log(chalk.cyan(`
51
+ 🐳 Stopping Docker container for service: ${service.name}`));
52
+ try {
53
+ const containerName = service.docker.container;
54
+ try {
55
+ await stopDockerContainer(containerName);
56
+ console.log(chalk.green(` āœ… Stopped container: ${containerName}`));
57
+ } catch (error) {
58
+ const errorMessage = error?.message || String(error) || "Unknown error";
59
+ if (errorMessage.toLowerCase().includes("no such container") || errorMessage.toLowerCase().includes("container not found")) {
60
+ console.log(
61
+ chalk.yellow(` āš ļø Container ${containerName} not found (already stopped)`)
62
+ );
63
+ } else {
64
+ throw error;
65
+ }
66
+ }
67
+ try {
68
+ await removeDockerContainer(containerName);
69
+ console.log(chalk.green(` āœ… Removed container: ${containerName}`));
70
+ } catch (error) {
71
+ const errorMessage = error?.message || String(error) || "Unknown error";
72
+ if (errorMessage.toLowerCase().includes("no such container") || errorMessage.toLowerCase().includes("container not found")) {
73
+ console.log(
74
+ chalk.yellow(` āš ļø Container ${containerName} not found (already removed)`)
75
+ );
76
+ } else {
77
+ throw error;
78
+ }
79
+ }
80
+ } catch (error) {
81
+ console.error(
82
+ chalk.red(` āŒ Failed to stop/remove container for service ${service.name}:`),
83
+ error instanceof Error ? error.message : error
84
+ );
85
+ throw error;
86
+ }
87
+ }
88
+ }
89
+ if (allDomains.size > 0) {
90
+ console.log(chalk.cyan(`
91
+ āš™ļø Updating Nginx configurations...`));
92
+ const servicesBeingDowned = new Set(servicesToDown.map((s) => s.name));
93
+ for (const domain of allDomains) {
94
+ const configName = domain.replace(/\./g, "_");
95
+ const allServicesForDomain = config.services.filter((s) => s.domains.includes(domain));
96
+ const remainingServices = allServicesForDomain.filter(
97
+ (s) => !servicesBeingDowned.has(s.name)
98
+ );
99
+ const activeServices = [];
100
+ for (const service of remainingServices) {
101
+ if (service.docker) {
102
+ const isRunning = await isContainerRunning(service.docker.container);
103
+ if (isRunning) {
104
+ activeServices.push(service);
105
+ }
106
+ } else {
107
+ activeServices.push(service);
108
+ }
109
+ }
110
+ try {
111
+ if (activeServices.length === 0) {
112
+ console.log(
113
+ chalk.cyan(` šŸ“‹ No active services on ${domain}, disabling Nginx config...`)
114
+ );
115
+ await disableSite(configName, config.nginx.configPath);
116
+ console.log(chalk.green(` āœ… Disabled Nginx config for ${domain}`));
117
+ } else {
118
+ console.log(
119
+ chalk.cyan(
120
+ ` šŸ“‹ Regenerating Nginx config for ${domain} with ${activeServices.length} active service(s): ${activeServices.map((s) => s.name).join(", ")}`
121
+ )
122
+ );
123
+ let nginxConfigContent;
124
+ if (activeServices.length === 1) {
125
+ nginxConfigContent = generateNginxConfig(activeServices[0], false);
126
+ } else {
127
+ nginxConfigContent = generateMultiServiceNginxConfig(activeServices, domain, false);
128
+ }
129
+ const { certificateExists } = await import("../utils/certbot.js");
130
+ const hasHttps = await certificateExists(domain);
131
+ if (hasHttps) {
132
+ if (activeServices.length === 1) {
133
+ nginxConfigContent = generateNginxConfig(activeServices[0], true);
134
+ } else {
135
+ nginxConfigContent = generateMultiServiceNginxConfig(activeServices, domain, true);
136
+ }
137
+ }
138
+ await writeNginxConfig(configName, config.nginx.configPath, nginxConfigContent);
139
+ await enableSite(configName, config.nginx.configPath);
140
+ console.log(
141
+ chalk.green(
142
+ ` āœ… Updated Nginx config for ${domain} (${activeServices.length} service(s) active)`
143
+ )
144
+ );
145
+ }
146
+ } catch (error) {
147
+ console.error(
148
+ chalk.red(` āŒ Failed to update Nginx config for ${domain}:`),
149
+ error instanceof Error ? error.message : error
150
+ );
151
+ throw error;
152
+ }
153
+ }
154
+ console.log(chalk.cyan(`
155
+ šŸ”„ Reloading Nginx...`));
156
+ try {
157
+ await reloadNginx(config.nginx.reloadCommand);
158
+ console.log(chalk.green(` āœ… Nginx reloaded`));
159
+ } catch (error) {
160
+ console.error(
161
+ chalk.red(` āŒ Failed to reload Nginx:`),
162
+ error instanceof Error ? error.message : error
163
+ );
164
+ throw error;
165
+ }
166
+ }
167
+ console.log(chalk.green.bold("\nāœ… Services brought down successfully!\n"));
168
+ } catch (error) {
169
+ console.error(
170
+ chalk.red("\nāŒ Failed to bring down services:"),
171
+ error instanceof Error ? error.message : error
172
+ );
173
+ process.exit(1);
174
+ }
175
+ }
176
+ export {
177
+ downCommand
178
+ };
179
+ //# sourceMappingURL=down.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"down.js","sources":["../../src/commands/down.ts"],"sourcesContent":["import chalk from 'chalk'\nimport fs from 'fs-extra'\nimport type { ServiceConfig } from '../types/config'\nimport { loadConfig } from '../utils/config-loader'\nimport { isContainerRunning, removeDockerContainer, stopDockerContainer } from '../utils/docker'\nimport {\n disableSite,\n enableSite,\n generateMultiServiceNginxConfig,\n generateNginxConfig,\n reloadNginx,\n writeNginxConfig,\n} from '../utils/nginx'\n\ninterface DownOptions {\n file: string\n all: boolean\n serviceName?: string\n}\n\nexport async function downCommand(options: DownOptions): Promise<void> {\n console.log(chalk.blue.bold('\\nšŸ›‘ Bringing Down Services\\n'))\n\n try {\n // Load configuration\n if (!(await fs.pathExists(options.file))) {\n throw new Error(`Configuration file not found: ${options.file}`)\n }\n\n console.log(chalk.cyan(`šŸ“„ Loading configuration from ${options.file}...`))\n const config = await loadConfig(options.file)\n\n console.log(chalk.green(`āœ… Configuration loaded for project: ${config.project.name}`))\n\n // Determine which services to bring down\n let servicesToDown: ServiceConfig[] = []\n\n if (options.all) {\n servicesToDown = config.services\n console.log(\n chalk.cyan(\n `šŸ“‹ Bringing down all services: ${servicesToDown.map((s) => s.name).join(', ')}\\n`\n )\n )\n } else if (options.serviceName) {\n const service = config.services.find((s) => s.name === options.serviceName)\n if (!service) {\n throw new Error(\n `Service \"${\n options.serviceName\n }\" not found in configuration. Available services: ${config.services\n .map((s) => s.name)\n .join(', ')}`\n )\n }\n servicesToDown = [service]\n console.log(chalk.cyan(`šŸ“‹ Bringing down service: ${options.serviceName}\\n`))\n } else {\n throw new Error('Either specify a service name or use --all flag')\n }\n\n // Group services by domain for nginx config management\n const domainToServices = new Map<string, ServiceConfig[]>()\n const allDomains = new Set<string>()\n\n for (const service of servicesToDown) {\n for (const domain of service.domains) {\n allDomains.add(domain)\n if (!domainToServices.has(domain)) {\n domainToServices.set(domain, [])\n }\n domainToServices.get(domain)!.push(service)\n }\n }\n\n // Stop and remove Docker containers\n for (const service of servicesToDown) {\n if (service.docker) {\n console.log(chalk.cyan(`\\n🐳 Stopping Docker container for service: ${service.name}`))\n try {\n const containerName = service.docker.container\n\n // Stop container\n try {\n await stopDockerContainer(containerName)\n console.log(chalk.green(` āœ… Stopped container: ${containerName}`))\n } catch (error: any) {\n const errorMessage = error?.message || String(error) || 'Unknown error'\n if (\n errorMessage.toLowerCase().includes('no such container') ||\n errorMessage.toLowerCase().includes('container not found')\n ) {\n console.log(\n chalk.yellow(` āš ļø Container ${containerName} not found (already stopped)`)\n )\n } else {\n throw error\n }\n }\n\n // Remove container\n try {\n await removeDockerContainer(containerName)\n console.log(chalk.green(` āœ… Removed container: ${containerName}`))\n } catch (error: any) {\n const errorMessage = error?.message || String(error) || 'Unknown error'\n if (\n errorMessage.toLowerCase().includes('no such container') ||\n errorMessage.toLowerCase().includes('container not found')\n ) {\n console.log(\n chalk.yellow(` āš ļø Container ${containerName} not found (already removed)`)\n )\n } else {\n throw error\n }\n }\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to stop/remove container for service ${service.name}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n }\n\n // Handle Nginx configs by domain\n // Check which services remain active for each domain\n if (allDomains.size > 0) {\n console.log(chalk.cyan(`\\nāš™ļø Updating Nginx configurations...`))\n\n // Create a set of service names being brought down for quick lookup\n const servicesBeingDowned = new Set(servicesToDown.map((s) => s.name))\n\n // For each domain, find all services that use it (from all config services)\n // and determine which ones remain active\n for (const domain of allDomains) {\n const configName = domain.replace(/\\./g, '_')\n\n // Find all services that use this domain (from entire config)\n const allServicesForDomain = config.services.filter((s) => s.domains.includes(domain))\n\n // Filter out services being brought down\n const remainingServices = allServicesForDomain.filter(\n (s) => !servicesBeingDowned.has(s.name)\n )\n\n // Check if remaining services are actually running (have active containers)\n const activeServices: ServiceConfig[] = []\n for (const service of remainingServices) {\n if (service.docker) {\n const isRunning = await isContainerRunning(service.docker.container)\n if (isRunning) {\n activeServices.push(service)\n }\n } else {\n // Service without docker - assume it's running if not being brought down\n activeServices.push(service)\n }\n }\n\n try {\n if (activeServices.length === 0) {\n // No active services on this domain, disable the config\n console.log(\n chalk.cyan(` šŸ“‹ No active services on ${domain}, disabling Nginx config...`)\n )\n await disableSite(configName, config.nginx.configPath)\n console.log(chalk.green(` āœ… Disabled Nginx config for ${domain}`))\n } else {\n // Regenerate config with remaining active services\n console.log(\n chalk.cyan(\n ` šŸ“‹ Regenerating Nginx config for ${domain} with ${\n activeServices.length\n } active service(s): ${activeServices.map((s) => s.name).join(', ')}`\n )\n )\n\n // Generate config for remaining services\n let nginxConfigContent: string\n if (activeServices.length === 1) {\n nginxConfigContent = generateNginxConfig(activeServices[0], false)\n } else {\n nginxConfigContent = generateMultiServiceNginxConfig(activeServices, domain, false)\n }\n\n // Check if HTTPS is enabled (check if certificate exists)\n const { certificateExists } = await import('../utils/certbot')\n const hasHttps = await certificateExists(domain)\n if (hasHttps) {\n // Regenerate with HTTPS\n if (activeServices.length === 1) {\n nginxConfigContent = generateNginxConfig(activeServices[0], true)\n } else {\n nginxConfigContent = generateMultiServiceNginxConfig(activeServices, domain, true)\n }\n }\n\n await writeNginxConfig(configName, config.nginx.configPath, nginxConfigContent)\n await enableSite(configName, config.nginx.configPath)\n console.log(\n chalk.green(\n ` āœ… Updated Nginx config for ${domain} (${activeServices.length} service(s) active)`\n )\n )\n }\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to update Nginx config for ${domain}:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n\n // Reload Nginx to apply changes\n console.log(chalk.cyan(`\\nšŸ”„ Reloading Nginx...`))\n try {\n await reloadNginx(config.nginx.reloadCommand)\n console.log(chalk.green(` āœ… Nginx reloaded`))\n } catch (error) {\n console.error(\n chalk.red(` āŒ Failed to reload Nginx:`),\n error instanceof Error ? error.message : error\n )\n throw error\n }\n }\n\n console.log(chalk.green.bold('\\nāœ… Services brought down successfully!\\n'))\n } catch (error) {\n console.error(\n chalk.red('\\nāŒ Failed to bring down services:'),\n error instan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