-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
93 lines (79 loc) · 4.12 KB
/
Copy pathindex.ts
File metadata and controls
93 lines (79 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as pulumi from "@pulumi/pulumi";
import type * as tailscale from "@pulumi/tailscale";
import { loadConfig } from "./src/config.ts";
import { getProvider } from "./src/cloud/index.ts";
import { generateCloudInit } from "./src/infra/cloud-init.ts";
import {
createAuthKey,
createDeviceCleanup,
createTailscaleProvider,
waitForDevice,
} from "./src/tailscale/resources.ts";
import { createHealthCheckWaiter } from "./src/opencode/health-check.ts";
import { HEALTH_PATH } from "./src/opencode/constants.ts";
const config = loadConfig();
const tailscaleProvider = createTailscaleProvider(config);
const tailnetKey = createAuthKey("opencode", config, tailscaleProvider);
const provider = getProvider(config.provider);
// Provision the persistent volume first (if enabled) so its device path is
// known before generating cloud-init userdata.
const volume = provider.createVolume?.(config);
const userData = generateCloudInit(config, tailnetKey.key, volume?.devicePath);
const vm = provider.createServer(config, userData, volume);
const device = pulumi.runtime.isDryRun()
? pulumi.output({ nodeId: "preview", addresses: ["preview"] } as unknown as tailscale.GetDeviceResult)
: waitForDevice(config, tailscaleProvider);
createDeviceCleanup("opencode", config, device.nodeId, tailscaleProvider);
if (config.healthCheckWaiter) {
createHealthCheckWaiter("opencode", config, [vm.publicIp as unknown as pulumi.Resource]);
}
// ---------------------------------------------------------------------------
// Stack outputs — base (always present)
// ---------------------------------------------------------------------------
export const publicIp = vm.publicIp;
export const serverId = vm.id;
export const serverName = vm.name;
export const cloudProvider = config.provider;
export const tailscaleHostname = config.tailscaleHostname;
/** Paste this block into ~/.ssh/config for Tailscale SSH access. */
export const sshConfigSnippet = `Host ${config.tailscaleHostname}\n User root\n ProxyCommand tailscale ssh --hostname %h\n`;
// ---------------------------------------------------------------------------
// Persistent storage outputs — populated when persistentStorage is enabled
// ---------------------------------------------------------------------------
export const volumeId = volume?.volumeId ?? pulumi.output("none");
export const volumeDevicePath = volume?.devicePath ?? pulumi.output("none");
// ---------------------------------------------------------------------------
// Multi-project outputs — one entry per project
// ---------------------------------------------------------------------------
export const projects =
config.projects.length > 0
? pulumi.output(
Object.fromEntries(
config.projects.map((p) => [
p.name,
{
url: pulumi.interpolate`http://${config.tailscaleHostname}:${p.port}`,
attachCommand: pulumi.interpolate`opencode attach http://${config.tailscaleHostname}:${p.port}`,
port: p.port,
},
]),
),
)
: pulumi.output({});
// ---------------------------------------------------------------------------
// V1 single-server outputs — only populated when no projects list is given
// ---------------------------------------------------------------------------
export const opencodePort = config.projects.length === 0 ? config.opencodePort : undefined;
export const opencodeUrl =
config.projects.length === 0
? pulumi.interpolate`http://${config.tailscaleHostname}:${config.opencodePort}`
: undefined;
export const attachCommand =
config.projects.length === 0
? pulumi.interpolate`opencode attach http://${config.tailscaleHostname}:${config.opencodePort}`
: undefined;
export const healthCheckUrl =
config.projects.length === 0
? pulumi.interpolate`http://${config.tailscaleHostname}:${config.opencodePort}${HEALTH_PATH}`
: undefined;
export const sshCommand = config.projects.length === 0 ? `ssh root@${config.tailscaleHostname}` : undefined;