-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathdeploy-with-rivet-self-hosted.ts
More file actions
67 lines (58 loc) · 1.54 KB
/
deploy-with-rivet-self-hosted.ts
File metadata and controls
67 lines (58 loc) · 1.54 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
import { RivetClient } from "@rivetkit/engine-api-full";
import {
configureRivetServerless,
type DeployRequest,
deployToFreestyle,
generateNamespaceName,
type LogCallback,
} from "./utils.ts";
export async function deployWithRivetSelfHosted(
req: DeployRequest,
log: LogCallback,
) {
if (!("selfHosted" in req.kind)) {
throw new Error("Expected self-hosted deployment request");
}
const { endpoint, token } = req.kind.selfHosted;
const { freestyleDomain, freestyleApiKey } = req;
const rivet = new RivetClient({
environment: endpoint,
token: token,
});
const namespaceName = generateNamespaceName();
await log(`Creating namespace ${namespaceName}`);
const { namespace } = await rivet.namespaces.create({
displayName: namespaceName,
name: namespaceName,
});
const datacenter = req.datacenter || "us-west-1";
// Deploy to Freestyle
const { deploymentId } = await deployToFreestyle({
registryCode: req.registryCode,
appCode: req.appCode,
domain: freestyleDomain,
apiKey: freestyleApiKey,
envVars: {
VITE_RIVET_ENDPOINT: endpoint,
VITE_RIVET_NAMESPACE: namespace.name,
VITE_RIVET_TOKEN: token,
VITE_RIVET_DATACENTER: datacenter,
RIVET_ENDPOINT: endpoint,
RIVET_NAMESPACE: namespace.name,
RIVET_RUNNER_TOKEN: token,
RIVET_PUBLISHABLE_TOKEN: token,
},
log,
});
await configureRivetServerless({
rivet,
domain: freestyleDomain,
namespace: namespace.name,
datacenter,
log,
});
return {
success: true,
freestyleUrl: `https://admin.freestyle.sh/dashboard/deployments/${deploymentId}`,
};
}