buncargo 1.0.29 → 3.2.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.
- package/dist/bin.d.ts +1 -12
- package/dist/bin.js +261 -253
- package/dist/cli/bin.d.ts +13 -0
- package/dist/cli/bin.js +317 -0
- package/dist/cli/commands/help.d.ts +1 -0
- package/dist/cli/commands/runtime.d.ts +5 -0
- package/dist/cli/commands/version.d.ts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +14 -0
- package/dist/cli/run-cli.d.ts +30 -0
- package/dist/cli.d.ts +1 -22
- package/dist/cli.js +5 -13
- package/dist/config/config.d.ts +1 -0
- package/dist/config/define-config.d.ts +13 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +15 -0
- package/dist/config/merge-configs.d.ts +3 -0
- package/dist/config/validate-config.d.ts +3 -0
- package/dist/config.d.ts +1 -72
- package/dist/config.js +12 -12
- package/dist/core/docker.d.ts +1 -83
- package/dist/core/docker.js +35 -32
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +123 -118
- package/dist/core/network.js +2 -2
- package/dist/core/ports.js +1 -1
- package/dist/core/process.js +1 -1
- package/dist/core/quick-tunnel/cloudflared-process.d.ts +10 -0
- package/dist/core/quick-tunnel/constants.d.ts +9 -0
- package/dist/core/quick-tunnel/index.d.ts +17 -0
- package/dist/core/quick-tunnel/install.d.ts +1 -0
- package/dist/core/tunnel.d.ts +34 -0
- package/dist/core/utils.js +2 -2
- package/dist/core/watchdog-runner.js +45 -42
- package/dist/core/watchdog.d.ts +1 -0
- package/dist/core/watchdog.js +4 -2
- package/dist/docker/index.d.ts +1 -0
- package/dist/docker/index.js +38 -0
- package/dist/docker/runtime.d.ts +87 -0
- package/dist/docker/runtime.js +37 -0
- package/dist/docker-compose/compose.d.ts +1 -0
- package/dist/docker-compose/generated-file.d.ts +7 -0
- package/dist/docker-compose/index.d.ts +3 -0
- package/dist/docker-compose/index.js +15 -0
- package/dist/docker-compose/model.d.ts +6 -0
- package/dist/docker-compose/services/clickhouse.d.ts +16 -0
- package/dist/docker-compose/services/define-docker-service.d.ts +41 -0
- package/dist/docker-compose/services/index.d.ts +23 -0
- package/dist/docker-compose/services/index.js +17 -0
- package/dist/docker-compose/services/postgres.d.ts +12 -0
- package/dist/docker-compose/services/redis.d.ts +12 -0
- package/dist/docker-compose/services/shared.d.ts +7 -0
- package/dist/docker-compose/yaml.d.ts +2 -0
- package/dist/environment/create-dev-environment.d.ts +23 -0
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.js +15 -0
- package/dist/environment/logging.d.ts +17 -0
- package/dist/environment/only-apps.d.ts +10 -0
- package/dist/environment/seeding.d.ts +9 -0
- package/dist/environment.d.ts +1 -23
- package/dist/environment.js +12 -14
- package/dist/index-045jksh5.js +147 -0
- package/dist/index-08wa79cs.js +125 -117
- package/dist/index-0kxnae3z.js +335 -0
- package/dist/index-1mdrf7nz.js +51 -43
- package/dist/index-1yvbwj4k.js +262 -242
- package/dist/index-23ev345g.js +475 -0
- package/dist/index-2ckr49sf.js +228 -0
- package/dist/index-2f47khe5.js +376 -369
- package/dist/index-2fr3g85b.js +220 -183
- package/dist/index-38xnzpa6.js +450 -0
- package/dist/index-3eyrdxw9.js +577 -0
- package/dist/index-3h3dhtf2.js +51 -43
- package/dist/index-42x95209.js +51 -43
- package/dist/index-4gp0az1g.js +145 -0
- package/dist/index-4xrxh8yv.js +72 -0
- package/dist/index-5aq985p4.js +250 -0
- package/dist/index-5gmws6ah.js +181 -0
- package/dist/index-5hka0tff.js +78 -76
- package/dist/index-5rfqps4b.js +3 -0
- package/dist/index-5t9jxqm0.js +428 -0
- package/dist/index-6c1w1xk5.js +101 -0
- package/dist/index-6cmex7m5.js +72 -0
- package/dist/index-6d6x175r.js +572 -0
- package/dist/index-6fm7mvwj.js +118 -97
- package/dist/index-6srpc523.js +127 -128
- package/dist/index-731rzzfp.js +157 -142
- package/dist/index-75y4cg2z.js +51 -43
- package/dist/index-7ja4ywyj.js +126 -127
- package/dist/index-7v19es2e.js +666 -0
- package/dist/index-8bw1cmz4.js +531 -0
- package/dist/index-8hbbj1mp.js +120 -121
- package/dist/index-8xj2p5n5.js +118 -97
- package/dist/index-9wyhzw0h.js +574 -0
- package/dist/index-ag90ry8t.js +576 -0
- package/dist/index-bj79tw5w.js +0 -0
- package/dist/index-bnk6nr0g.js +73 -0
- package/dist/index-brbbzyks.js +72 -0
- package/dist/index-byeqyjrz.js +72 -0
- package/dist/index-c0dr6mcv.js +123 -0
- package/dist/index-cty0bcry.js +235 -218
- package/dist/index-d8tyv5se.js +228 -0
- package/dist/index-d9efy0n4.js +176 -150
- package/dist/index-enj4zdma.js +574 -0
- package/dist/index-etfmqjjf.js +427 -0
- package/dist/index-fb29934k.js +172 -0
- package/dist/index-g50jw1yf.js +72 -0
- package/dist/index-g6eb5wdw.js +118 -117
- package/dist/index-ggq3yryx.js +99 -95
- package/dist/index-h70tce00.js +177 -0
- package/dist/index-hkxtfqtc.js +333 -0
- package/dist/index-k370bech.js +72 -0
- package/dist/index-kf3dhser.js +146 -143
- package/dist/index-ma6tgdb2.js +500 -0
- package/dist/index-mam0bcyz.js +123 -0
- package/dist/index-mm412dkp.js +274 -0
- package/dist/index-n8v18aeb.js +0 -0
- package/dist/index-ndnmnsej.js +378 -371
- package/dist/index-p8wty0e2.js +389 -379
- package/dist/index-qa8akv6y.js +666 -0
- package/dist/index-qfphr2fd.js +78 -76
- package/dist/index-qqmms8rs.js +51 -43
- package/dist/index-qw4093g2.js +51 -43
- package/dist/index-qzwpzjbx.js +121 -122
- package/dist/index-segbnm0h.js +146 -143
- package/dist/index-t0fj6gg1.js +112 -0
- package/dist/index-thdkwnv7.js +122 -0
- package/dist/index-tjbx2r2t.js +270 -0
- package/dist/index-tjqw9vtj.js +62 -54
- package/dist/index-vbpb89jy.js +248 -0
- package/dist/index-vg55rq0y.js +250 -0
- package/dist/index-vhs88xhe.js +99 -95
- package/dist/index-vs81yaks.js +244 -0
- package/dist/index-w8zxnjka.js +249 -0
- package/dist/index-wk2na3t9.js +385 -375
- package/dist/index-wz9x8g7z.js +383 -373
- package/dist/index-x249gyde.js +388 -378
- package/dist/index-x54nbgs7.js +355 -0
- package/dist/index-xkvd0nsd.js +187 -0
- package/dist/index-yedqxm1z.js +80 -0
- package/dist/index-yz4jfz7z.js +338 -0
- package/dist/index-zfjzzjkf.js +240 -199
- package/dist/index.d.ts +12 -8
- package/dist/index.js +56 -34
- package/dist/lint.d.ts +1 -46
- package/dist/lint.js +3 -7
- package/dist/loader/cache.d.ts +4 -0
- package/dist/loader/find-config-file.d.ts +2 -0
- package/dist/loader/index.d.ts +5 -0
- package/dist/loader/index.js +24 -0
- package/dist/loader/load-dev-env.d.ts +5 -0
- package/dist/loader/loader.d.ts +1 -0
- package/dist/loader.d.ts +1 -45
- package/dist/loader.js +22 -20
- package/dist/prisma/index.d.ts +1 -0
- package/dist/prisma/prisma.d.ts +29 -0
- package/dist/prisma.d.ts +1 -29
- package/dist/prisma.js +6 -10
- package/dist/src/bin.js +309 -0
- package/dist/src/cli.js +5 -0
- package/dist/src/config.js +15 -0
- package/dist/src/core/docker.js +38 -0
- package/dist/src/core/index.js +130 -0
- package/dist/src/core/network.js +9 -0
- package/dist/src/core/ports.js +23 -0
- package/dist/src/core/process.js +31 -0
- package/dist/src/core/utils.js +11 -0
- package/dist/src/core/watchdog-runner.js +69 -0
- package/dist/src/core/watchdog.js +28 -0
- package/dist/src/docker/runtime.js +37 -0
- package/dist/src/docker-compose/index.js +16 -0
- package/dist/src/docker-compose/services/index.js +17 -0
- package/dist/src/environment.js +12 -0
- package/dist/src/index.js +122 -0
- package/dist/src/lint.js +3 -0
- package/dist/src/loader.js +25 -0
- package/dist/src/prisma.js +6 -0
- package/dist/src/types.js +0 -0
- package/dist/typecheck/index.d.ts +1 -0
- package/dist/typecheck/index.js +7 -0
- package/dist/typecheck/typecheck.d.ts +46 -0
- package/dist/types/all-types.d.ts +544 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config.d.ts +6 -0
- package/dist/types/docker.d.ts +15 -0
- package/dist/types/environment.d.ts +8 -0
- package/dist/types/hooks.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +0 -0
- package/dist/types/prisma.d.ts +1 -0
- package/dist/types.d.ts +1 -399
- package/package.json +55 -48
- package/readme.md +365 -109
- package/src/cli/bin.ts +77 -0
- package/src/cli/commands/help.ts +39 -0
- package/src/cli/commands/runtime.ts +72 -0
- package/src/cli/commands/version.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/{cli.ts → src/cli/run-cli.ts} +114 -10
- package/src/config/define-config.ts +30 -0
- package/src/config/index.ts +3 -0
- package/src/config/merge-configs.ts +33 -0
- package/src/config/validate-config.ts +136 -0
- package/{core → src/core}/index.ts +2 -2
- package/{core → src/core}/ports.ts +5 -2
- package/{core → src/core}/process.ts +6 -2
- package/src/core/quick-tunnel/cloudflared-process.ts +83 -0
- package/src/core/quick-tunnel/constants.ts +31 -0
- package/src/core/quick-tunnel/index.ts +96 -0
- package/src/core/quick-tunnel/install.ts +160 -0
- package/src/core/tunnel.ts +165 -0
- package/{core → src/core}/utils.ts +1 -0
- package/{core → src/core}/watchdog.ts +5 -1
- package/src/docker/index.ts +1 -0
- package/{core/docker.ts → src/docker/runtime.ts} +11 -4
- package/src/docker-compose/generated-file.ts +45 -0
- package/src/docker-compose/index.ts +7 -0
- package/src/docker-compose/model.ts +197 -0
- package/src/docker-compose/services/clickhouse.ts +79 -0
- package/src/docker-compose/services/define-docker-service.ts +109 -0
- package/src/docker-compose/services/index.ts +67 -0
- package/src/docker-compose/services/postgres.ts +60 -0
- package/src/docker-compose/services/redis.ts +48 -0
- package/src/docker-compose/services/shared.ts +79 -0
- package/src/docker-compose/yaml.ts +88 -0
- package/{environment.ts → src/environment/create-dev-environment.ts} +214 -141
- package/src/environment/index.ts +1 -0
- package/src/environment/logging.ts +115 -0
- package/src/environment/only-apps.ts +34 -0
- package/src/environment/seeding.ts +57 -0
- package/{index.ts → src/index.ts} +52 -20
- package/src/loader/cache.ts +23 -0
- package/src/loader/find-config-file.ts +29 -0
- package/src/loader/index.ts +17 -0
- package/src/loader/load-dev-env.ts +38 -0
- package/src/prisma/index.ts +1 -0
- package/{prisma.ts → src/prisma/prisma.ts} +4 -2
- package/src/typecheck/index.ts +1 -0
- package/{types.ts → src/types/all-types.ts} +186 -8
- package/src/types/index.ts +1 -0
- package/bin.ts +0 -192
- package/config.ts +0 -194
- package/loader.ts +0 -126
- /package/{core → src/core}/network.ts +0 -0
- /package/{core → src/core}/watchdog-runner.ts +0 -0
- /package/{lint.ts → src/typecheck/typecheck.ts} +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths and release metadata for the cloudflared binary.
|
|
3
|
+
* Derived from unjs/untun (MIT), originally forked from node-cloudflared.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
export const CLOUDFLARED_VERSION =
|
|
10
|
+
process.env.CLOUDFLARED_VERSION || "2023.10.0";
|
|
11
|
+
|
|
12
|
+
export const RELEASE_BASE =
|
|
13
|
+
"https://github.com/cloudflare/cloudflared/releases/";
|
|
14
|
+
|
|
15
|
+
/** Directory for buncargo-managed cloudflared (avoid clashing with untun's node-untun). */
|
|
16
|
+
export const cloudflaredBinPath = path.join(
|
|
17
|
+
tmpdir(),
|
|
18
|
+
"buncargo-cloudflared",
|
|
19
|
+
process.platform === "win32"
|
|
20
|
+
? `cloudflared.${CLOUDFLARED_VERSION}.exe`
|
|
21
|
+
: `cloudflared.${CLOUDFLARED_VERSION}`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const cloudflaredNotice = `
|
|
25
|
+
🔥 Your installation of cloudflared software constitutes a symbol of your signature
|
|
26
|
+
indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
|
|
27
|
+
|
|
28
|
+
❯ License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
|
|
29
|
+
❯ Terms: \`https://www.cloudflare.com/terms/\`
|
|
30
|
+
❯ Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
|
|
31
|
+
`;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Quick Tunnel via the cloudflared CLI (same approach as unjs/untun).
|
|
3
|
+
* License / download flow adapted from unjs/untun (MIT).
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { createInterface } from "node:readline";
|
|
7
|
+
import { startCloudflaredTunnel } from "./cloudflared-process";
|
|
8
|
+
import { cloudflaredBinPath, cloudflaredNotice } from "./constants";
|
|
9
|
+
import { installCloudflared } from "./install";
|
|
10
|
+
|
|
11
|
+
export interface QuickTunnelOptions {
|
|
12
|
+
url?: string;
|
|
13
|
+
port?: number | string;
|
|
14
|
+
hostname?: string;
|
|
15
|
+
protocol?: "http" | "https";
|
|
16
|
+
verifyTLS?: boolean;
|
|
17
|
+
acceptCloudflareNotice?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface QuickTunnel {
|
|
21
|
+
getURL: () => Promise<string>;
|
|
22
|
+
close: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function resolvedLocalUrl(opts: QuickTunnelOptions): string {
|
|
26
|
+
return (
|
|
27
|
+
opts.url ??
|
|
28
|
+
`${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3000}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function envAcceptsCloudflareNotice(): boolean {
|
|
33
|
+
const v = process.env.BUNCARGO_ACCEPT_CLOUDFLARE_NOTICE;
|
|
34
|
+
const u = process.env.UNTUN_ACCEPT_CLOUDFLARE_NOTICE;
|
|
35
|
+
return v === "1" || v === "true" || u === "1" || u === "true";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function promptInstallCloudflared(): Promise<boolean> {
|
|
39
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
const rl = createInterface({
|
|
44
|
+
input: process.stdin,
|
|
45
|
+
output: process.stdout,
|
|
46
|
+
});
|
|
47
|
+
rl.question(
|
|
48
|
+
"Do you agree with the above terms and wish to install the binary from GitHub? (y/N) ",
|
|
49
|
+
(answer) => {
|
|
50
|
+
rl.close();
|
|
51
|
+
resolve(/^y(es)?$/i.test(answer.trim()));
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Start a Cloudflare quick tunnel to a local HTTP(S) URL.
|
|
59
|
+
* Returns undefined if the user declines the cloudflared install (when binary is missing).
|
|
60
|
+
*/
|
|
61
|
+
export async function startQuickTunnel(
|
|
62
|
+
opts: QuickTunnelOptions,
|
|
63
|
+
): Promise<QuickTunnel | undefined> {
|
|
64
|
+
const url = resolvedLocalUrl(opts);
|
|
65
|
+
|
|
66
|
+
console.log(`Starting cloudflared tunnel to ${url}`);
|
|
67
|
+
|
|
68
|
+
if (!existsSync(cloudflaredBinPath)) {
|
|
69
|
+
console.log(cloudflaredNotice);
|
|
70
|
+
const canInstall =
|
|
71
|
+
opts.acceptCloudflareNotice ||
|
|
72
|
+
envAcceptsCloudflareNotice() ||
|
|
73
|
+
(await promptInstallCloudflared());
|
|
74
|
+
if (!canInstall) {
|
|
75
|
+
console.error("Skipping tunnel setup.");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
await installCloudflared();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const cfArgs: Record<string, string | number | null> = { "--url": url };
|
|
82
|
+
// Boolean flag: use `null` value so spawn does not pass a stray empty argv (see cloudflared-process).
|
|
83
|
+
if (!opts.verifyTLS) {
|
|
84
|
+
cfArgs["--no-tls-verify"] = null;
|
|
85
|
+
}
|
|
86
|
+
const tunnel = startCloudflaredTunnel(cfArgs);
|
|
87
|
+
|
|
88
|
+
const cleanup = async () => {
|
|
89
|
+
tunnel.stop();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
getURL: async () => await tunnel.url,
|
|
94
|
+
close: cleanup,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download cloudflared from GitHub releases.
|
|
3
|
+
* Derived from unjs/untun (MIT), originally forked from node-cloudflared.
|
|
4
|
+
*/
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import https from "node:https";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import {
|
|
10
|
+
CLOUDFLARED_VERSION,
|
|
11
|
+
cloudflaredBinPath,
|
|
12
|
+
RELEASE_BASE,
|
|
13
|
+
} from "./constants";
|
|
14
|
+
|
|
15
|
+
const LINUX_URL: Partial<Record<NodeJS.Architecture, string>> = {
|
|
16
|
+
arm64: "cloudflared-linux-arm64",
|
|
17
|
+
arm: "cloudflared-linux-arm",
|
|
18
|
+
x64: "cloudflared-linux-amd64",
|
|
19
|
+
ia32: "cloudflared-linux-386",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const MACOS_URL: Partial<Record<NodeJS.Architecture, string>> = {
|
|
23
|
+
arm64: "cloudflared-darwin-amd64.tgz",
|
|
24
|
+
x64: "cloudflared-darwin-amd64.tgz",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const WINDOWS_URL: Partial<Record<NodeJS.Architecture, string>> = {
|
|
28
|
+
x64: "cloudflared-windows-amd64.exe",
|
|
29
|
+
ia32: "cloudflared-windows-386.exe",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function resolveBase(version: string): string {
|
|
33
|
+
if (version === "latest") {
|
|
34
|
+
return `${RELEASE_BASE}latest/download/`;
|
|
35
|
+
}
|
|
36
|
+
return `${RELEASE_BASE}download/${version}/`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function installCloudflared(
|
|
40
|
+
to: string = cloudflaredBinPath,
|
|
41
|
+
version = CLOUDFLARED_VERSION,
|
|
42
|
+
): Promise<string> {
|
|
43
|
+
switch (process.platform) {
|
|
44
|
+
case "linux": {
|
|
45
|
+
return installLinux(to, version);
|
|
46
|
+
}
|
|
47
|
+
case "darwin": {
|
|
48
|
+
return installMacos(to, version);
|
|
49
|
+
}
|
|
50
|
+
case "win32": {
|
|
51
|
+
return installWindows(to, version);
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function installLinux(
|
|
60
|
+
to: string,
|
|
61
|
+
version = CLOUDFLARED_VERSION,
|
|
62
|
+
): Promise<string> {
|
|
63
|
+
const file = LINUX_URL[process.arch];
|
|
64
|
+
|
|
65
|
+
if (file === undefined) {
|
|
66
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
await download(resolveBase(version) + file, to);
|
|
70
|
+
fs.chmodSync(to, 0o755);
|
|
71
|
+
return to;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function installMacos(
|
|
75
|
+
to: string,
|
|
76
|
+
version = CLOUDFLARED_VERSION,
|
|
77
|
+
): Promise<string> {
|
|
78
|
+
const file = MACOS_URL[process.arch];
|
|
79
|
+
|
|
80
|
+
if (file === undefined) {
|
|
81
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await download(resolveBase(version) + file, `${to}.tgz`);
|
|
85
|
+
if (process.env.DEBUG) {
|
|
86
|
+
console.log(`Extracting to ${to}`);
|
|
87
|
+
}
|
|
88
|
+
execSync(`tar -xzf ${path.basename(`${to}.tgz`)}`, {
|
|
89
|
+
cwd: path.dirname(to),
|
|
90
|
+
});
|
|
91
|
+
fs.unlinkSync(`${to}.tgz`);
|
|
92
|
+
fs.renameSync(`${path.dirname(to)}/cloudflared`, to);
|
|
93
|
+
return to;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function installWindows(
|
|
97
|
+
to: string,
|
|
98
|
+
version = CLOUDFLARED_VERSION,
|
|
99
|
+
): Promise<string> {
|
|
100
|
+
const file = WINDOWS_URL[process.arch];
|
|
101
|
+
|
|
102
|
+
if (file === undefined) {
|
|
103
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await download(resolveBase(version) + file, to);
|
|
107
|
+
return to;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function download(url: string, to: string, redirect = 0): Promise<string> {
|
|
111
|
+
if (redirect === 0) {
|
|
112
|
+
if (process.env.DEBUG) {
|
|
113
|
+
console.log(`Downloading ${url} to ${to}`);
|
|
114
|
+
}
|
|
115
|
+
} else if (process.env.DEBUG) {
|
|
116
|
+
console.log(`Redirecting to ${url}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
if (!fs.existsSync(path.dirname(to))) {
|
|
121
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let done = true;
|
|
125
|
+
const file = fs.createWriteStream(to);
|
|
126
|
+
const request = https.get(url, (res) => {
|
|
127
|
+
if (res.statusCode === 302 && res.headers.location !== undefined) {
|
|
128
|
+
const redirection = res.headers.location;
|
|
129
|
+
done = false;
|
|
130
|
+
file.close(() => {
|
|
131
|
+
void download(redirection, to, redirect + 1).then(resolve, reject);
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
res.pipe(file);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
file.on("finish", () => {
|
|
139
|
+
if (done) {
|
|
140
|
+
file.close(() => {
|
|
141
|
+
resolve(to);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
request.on("error", (err) => {
|
|
147
|
+
fs.unlink(to, () => {
|
|
148
|
+
reject(err);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
file.on("error", (err) => {
|
|
153
|
+
fs.unlink(to, () => {
|
|
154
|
+
reject(err);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
request.end();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { AppConfig, DevEnvironment, ServiceConfig } from "../types";
|
|
2
|
+
import { startQuickTunnel } from "./quick-tunnel";
|
|
3
|
+
|
|
4
|
+
export interface PublicExposeTarget {
|
|
5
|
+
kind: "service" | "app";
|
|
6
|
+
name: string;
|
|
7
|
+
port: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface PublicTunnel {
|
|
11
|
+
kind: "service" | "app";
|
|
12
|
+
name: string;
|
|
13
|
+
localUrl: string;
|
|
14
|
+
publicUrl: string;
|
|
15
|
+
close: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface TunnelBackendResult {
|
|
19
|
+
getURL?: () => Promise<string>;
|
|
20
|
+
url?: string;
|
|
21
|
+
publicUrl?: string;
|
|
22
|
+
tunnelUrl?: string;
|
|
23
|
+
close?: () => void | Promise<void>;
|
|
24
|
+
stop?: () => void | Promise<void>;
|
|
25
|
+
destroy?: () => void | Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function parseExposeNames(exposeValue?: string): Set<string> | null {
|
|
29
|
+
if (exposeValue === undefined) return null;
|
|
30
|
+
const names = exposeValue
|
|
31
|
+
.split(",")
|
|
32
|
+
.map((name) => name.trim())
|
|
33
|
+
.filter(Boolean);
|
|
34
|
+
return new Set(names);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Resolves public origin from tunnel backends (sync fields or untun-style async getURL). */
|
|
38
|
+
async function resolvePublicUrl(
|
|
39
|
+
tunnel: TunnelBackendResult,
|
|
40
|
+
): Promise<string | null> {
|
|
41
|
+
if (typeof tunnel.getURL === "function") {
|
|
42
|
+
return await tunnel.getURL();
|
|
43
|
+
}
|
|
44
|
+
return tunnel.url ?? tunnel.publicUrl ?? tunnel.tunnelUrl ?? null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function toCloseFn(tunnel: TunnelBackendResult): () => Promise<void> {
|
|
48
|
+
const close = tunnel.close ?? tunnel.stop ?? tunnel.destroy;
|
|
49
|
+
if (!close) return async () => {};
|
|
50
|
+
return async () => {
|
|
51
|
+
await close();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resolveExposeTargets<
|
|
56
|
+
TServices extends Record<string, ServiceConfig>,
|
|
57
|
+
TApps extends Record<string, AppConfig>,
|
|
58
|
+
>(
|
|
59
|
+
env: DevEnvironment<TServices, TApps>,
|
|
60
|
+
exposeValue?: string,
|
|
61
|
+
): {
|
|
62
|
+
targets: PublicExposeTarget[];
|
|
63
|
+
unknownNames: string[];
|
|
64
|
+
notEnabledNames: string[];
|
|
65
|
+
} {
|
|
66
|
+
const requestedNames = parseExposeNames(exposeValue);
|
|
67
|
+
const knownTargets = new Map<string, PublicExposeTarget>();
|
|
68
|
+
const enabledTargets = new Map<string, PublicExposeTarget>();
|
|
69
|
+
|
|
70
|
+
for (const [name, config] of Object.entries(env.services)) {
|
|
71
|
+
const port = env.ports[name];
|
|
72
|
+
if (port === undefined) continue;
|
|
73
|
+
const target: PublicExposeTarget = { kind: "service", name, port };
|
|
74
|
+
knownTargets.set(name, target);
|
|
75
|
+
if (config.expose === true) {
|
|
76
|
+
enabledTargets.set(name, target);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const [name, config] of Object.entries(env.apps)) {
|
|
81
|
+
const port = env.ports[name];
|
|
82
|
+
if (port === undefined) continue;
|
|
83
|
+
const target: PublicExposeTarget = { kind: "app", name, port };
|
|
84
|
+
knownTargets.set(name, target);
|
|
85
|
+
if (config.expose === true) {
|
|
86
|
+
enabledTargets.set(name, target);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (requestedNames === null) {
|
|
91
|
+
return {
|
|
92
|
+
targets: Array.from(enabledTargets.values()),
|
|
93
|
+
unknownNames: [],
|
|
94
|
+
notEnabledNames: [],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const unknownNames: string[] = [];
|
|
99
|
+
const notEnabledNames: string[] = [];
|
|
100
|
+
const targets: PublicExposeTarget[] = [];
|
|
101
|
+
|
|
102
|
+
for (const name of requestedNames) {
|
|
103
|
+
if (!knownTargets.has(name)) {
|
|
104
|
+
unknownNames.push(name);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const enabledTarget = enabledTargets.get(name);
|
|
108
|
+
if (!enabledTarget) {
|
|
109
|
+
notEnabledNames.push(name);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
targets.push(enabledTarget);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { targets, unknownNames, notEnabledNames };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function startPublicTunnels(
|
|
119
|
+
targets: PublicExposeTarget[],
|
|
120
|
+
options: {
|
|
121
|
+
start?: (input: {
|
|
122
|
+
url: string;
|
|
123
|
+
}) => Promise<TunnelBackendResult | undefined>;
|
|
124
|
+
} = {},
|
|
125
|
+
): Promise<PublicTunnel[]> {
|
|
126
|
+
const start = options.start ?? ((input) => startQuickTunnel(input));
|
|
127
|
+
const tunnels: PublicTunnel[] = [];
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
for (const target of targets) {
|
|
131
|
+
const localUrl = `http://localhost:${target.port}`;
|
|
132
|
+
const tunnel = (await start({
|
|
133
|
+
url: localUrl,
|
|
134
|
+
})) as TunnelBackendResult | undefined;
|
|
135
|
+
if (tunnel === undefined) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Tunnel for "${target.name}" could not be started (cloudflared missing or install declined)`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const publicUrl = await resolvePublicUrl(tunnel);
|
|
141
|
+
if (!publicUrl) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`Tunnel for "${target.name}" did not provide a public URL`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
tunnels.push({
|
|
147
|
+
kind: target.kind,
|
|
148
|
+
name: target.name,
|
|
149
|
+
localUrl,
|
|
150
|
+
publicUrl,
|
|
151
|
+
close: toCloseFn(tunnel),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return tunnels;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
await stopPublicTunnels(tunnels);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function stopPublicTunnels(
|
|
162
|
+
tunnels: PublicTunnel[],
|
|
163
|
+
): Promise<void> {
|
|
164
|
+
await Promise.allSettled(tunnels.map((tunnel) => tunnel.close()));
|
|
165
|
+
}
|
|
@@ -120,6 +120,10 @@ export function getWatchdogPid(projectName: string): number | null {
|
|
|
120
120
|
* Spawn watchdog as a detached process.
|
|
121
121
|
* The watchdog monitors the heartbeat file and shuts down containers after idle timeout.
|
|
122
122
|
*/
|
|
123
|
+
export function getWatchdogComposeArg(composeFile?: string): string {
|
|
124
|
+
return composeFile ? `-f "${composeFile}"` : "";
|
|
125
|
+
}
|
|
126
|
+
|
|
123
127
|
export async function spawnWatchdog(
|
|
124
128
|
projectName: string,
|
|
125
129
|
root: string,
|
|
@@ -162,7 +166,7 @@ export async function spawnWatchdog(
|
|
|
162
166
|
WATCHDOG_HEARTBEAT_FILE: getHeartbeatFile(projectName),
|
|
163
167
|
WATCHDOG_PID_FILE: pidFile,
|
|
164
168
|
WATCHDOG_TIMEOUT_MS: String(timeoutMinutes * 60 * 1000),
|
|
165
|
-
WATCHDOG_COMPOSE_ARG: composeFile
|
|
169
|
+
WATCHDOG_COMPOSE_ARG: getWatchdogComposeArg(composeFile),
|
|
166
170
|
},
|
|
167
171
|
});
|
|
168
172
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./runtime";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
+
import { sleep } from "../core/utils";
|
|
2
3
|
import type {
|
|
3
4
|
BuiltInHealthCheck,
|
|
4
5
|
HealthCheckFn,
|
|
5
6
|
ServiceConfig,
|
|
6
7
|
} from "../types";
|
|
7
|
-
import { sleep } from "./utils";
|
|
8
8
|
|
|
9
9
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
10
10
|
// Constants
|
|
@@ -91,6 +91,13 @@ export interface StartContainersOptions {
|
|
|
91
91
|
composeFile?: string;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Build `-f` argument for docker compose.
|
|
96
|
+
*/
|
|
97
|
+
export function getComposeArg(composeFile?: string): string {
|
|
98
|
+
return composeFile ? `-f "${composeFile}"` : "";
|
|
99
|
+
}
|
|
100
|
+
|
|
94
101
|
/**
|
|
95
102
|
* Start Docker Compose containers.
|
|
96
103
|
*/
|
|
@@ -105,7 +112,7 @@ export function startContainers(
|
|
|
105
112
|
|
|
106
113
|
if (verbose) console.log("🐳 Starting Docker containers...");
|
|
107
114
|
|
|
108
|
-
const composeArg = composeFile
|
|
115
|
+
const composeArg = getComposeArg(composeFile);
|
|
109
116
|
const waitFlag = wait ? "--wait" : "";
|
|
110
117
|
const cmd = `docker compose ${composeArg} up -d ${waitFlag}`.trim();
|
|
111
118
|
|
|
@@ -143,7 +150,7 @@ export function stopContainers(
|
|
|
143
150
|
);
|
|
144
151
|
}
|
|
145
152
|
|
|
146
|
-
const composeArg = composeFile
|
|
153
|
+
const composeArg = getComposeArg(composeFile);
|
|
147
154
|
const volumeFlag = removeVolumes ? "-v" : "";
|
|
148
155
|
const cmd = `docker compose ${composeArg} down ${volumeFlag}`.trim();
|
|
149
156
|
|
|
@@ -171,7 +178,7 @@ export function startService(
|
|
|
171
178
|
|
|
172
179
|
if (verbose) console.log(`🐳 Starting ${serviceName}...`);
|
|
173
180
|
|
|
174
|
-
const composeArg = composeFile
|
|
181
|
+
const composeArg = getComposeArg(composeFile);
|
|
175
182
|
const cmd = `docker compose ${composeArg} up -d ${serviceName}`.trim();
|
|
176
183
|
|
|
177
184
|
execSync(cmd, {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import type { DockerComposeGenerationOptions, ServiceConfig } from "../types";
|
|
4
|
+
import { buildComposeModel } from "./model";
|
|
5
|
+
import { composeToYaml } from "./yaml";
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_GENERATED_COMPOSE_FILE =
|
|
8
|
+
".buncargo/docker-compose.generated.yml";
|
|
9
|
+
|
|
10
|
+
export function getGeneratedComposePath(
|
|
11
|
+
root: string,
|
|
12
|
+
docker?: DockerComposeGenerationOptions,
|
|
13
|
+
): { absolutePath: string; composeFileArg: string } {
|
|
14
|
+
const generatedFile = docker?.generatedFile ?? DEFAULT_GENERATED_COMPOSE_FILE;
|
|
15
|
+
const absolutePath = isAbsolute(generatedFile)
|
|
16
|
+
? generatedFile
|
|
17
|
+
: resolve(root, generatedFile);
|
|
18
|
+
const relativePath = relative(root, absolutePath);
|
|
19
|
+
const composeFileArg =
|
|
20
|
+
relativePath && !relativePath.startsWith("..")
|
|
21
|
+
? relativePath
|
|
22
|
+
: absolutePath;
|
|
23
|
+
return { absolutePath, composeFileArg };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function writeGeneratedComposeFile(
|
|
27
|
+
root: string,
|
|
28
|
+
services: Record<string, ServiceConfig>,
|
|
29
|
+
docker?: DockerComposeGenerationOptions,
|
|
30
|
+
): string {
|
|
31
|
+
const { absolutePath, composeFileArg } = getGeneratedComposePath(
|
|
32
|
+
root,
|
|
33
|
+
docker,
|
|
34
|
+
);
|
|
35
|
+
const writeStrategy = docker?.writeStrategy ?? "always";
|
|
36
|
+
const shouldWrite = writeStrategy === "always" || !existsSync(absolutePath);
|
|
37
|
+
if (shouldWrite) {
|
|
38
|
+
const composeModel = buildComposeModel(services, docker);
|
|
39
|
+
const yaml = composeToYaml(composeModel);
|
|
40
|
+
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
41
|
+
writeFileSync(absolutePath, yaml, "utf-8");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return composeFileArg;
|
|
45
|
+
}
|