vyft 0.1.1-alpha → 0.3.0-alpha
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/README.md +5 -16
- package/dist/cli.js +192 -10
- package/dist/context.d.ts +39 -0
- package/dist/context.js +101 -0
- package/dist/docker.d.ts +14 -9
- package/dist/docker.js +145 -317
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/init.js +19 -2
- package/dist/interpolate.d.ts +11 -0
- package/dist/interpolate.js +11 -0
- package/dist/proxy.d.ts +16 -0
- package/dist/proxy.js +0 -0
- package/dist/resource.d.ts +97 -1
- package/dist/resource.js +11 -1
- package/dist/runtime.d.ts +4 -0
- package/dist/services/index.d.ts +24 -0
- package/dist/services/index.js +20 -0
- package/dist/services/minio.d.ts +36 -0
- package/dist/services/minio.js +53 -0
- package/dist/services/mongo.d.ts +28 -0
- package/dist/services/mongo.js +45 -0
- package/dist/services/mysql.d.ts +28 -0
- package/dist/services/mysql.js +44 -0
- package/dist/services/nats.d.ts +26 -0
- package/dist/services/nats.js +38 -0
- package/dist/services/postgres.d.ts +28 -0
- package/dist/services/postgres.js +45 -0
- package/dist/services/rabbitmq.d.ts +28 -0
- package/dist/services/rabbitmq.js +44 -0
- package/dist/services/redis.d.ts +28 -0
- package/dist/services/redis.js +49 -0
- package/dist/services/storage.d.ts +39 -0
- package/dist/services/storage.js +94 -0
- package/dist/swarm/factories.d.ts +12 -4
- package/dist/swarm/factories.js +50 -43
- package/dist/swarm/index.d.ts +10 -0
- package/dist/swarm/proxy.d.ts +24 -0
- package/dist/swarm/proxy.js +339 -0
- package/dist/swarm/types.d.ts +11 -10
- package/dist/symbols.d.ts +5 -0
- package/dist/symbols.js +1 -0
- package/package.json +2 -5
- package/templates/fullstack/vyft.config.ts +13 -28
package/dist/resource.d.ts
CHANGED
|
@@ -1,78 +1,174 @@
|
|
|
1
1
|
import type { RuntimeRef } from "./symbols.js";
|
|
2
|
+
/** Discriminant for the four resource kinds. */
|
|
2
3
|
export type ResourceType = "volume" | "secret" | "service" | "site";
|
|
3
|
-
|
|
4
|
+
/** Configuration for a persistent volume. */
|
|
5
|
+
export interface VolumeConfig {
|
|
6
|
+
/** Human-readable size hint (e.g. `"10GB"`). Informational only. */
|
|
7
|
+
size?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Configuration for an auto-generated secret. */
|
|
4
10
|
export interface SecretConfig {
|
|
11
|
+
/** Length of the generated random value in bytes. */
|
|
5
12
|
length?: number;
|
|
6
13
|
}
|
|
14
|
+
/** Container health-check configuration. */
|
|
7
15
|
export interface HealthCheckConfig {
|
|
16
|
+
/** Command to run inside the container (e.g. `["pg_isready", "-U", "postgres"]`). */
|
|
8
17
|
command: string[];
|
|
18
|
+
/** Time between checks (e.g. `"5s"`, `"1m"`). */
|
|
9
19
|
interval?: string;
|
|
20
|
+
/** Maximum time a single check may take. */
|
|
10
21
|
timeout?: string;
|
|
22
|
+
/** Consecutive failures required to mark unhealthy. */
|
|
11
23
|
retries?: number;
|
|
24
|
+
/** Grace period before the first check runs. */
|
|
12
25
|
startPeriod?: string;
|
|
13
26
|
}
|
|
27
|
+
/** CPU and memory limits for a service. */
|
|
14
28
|
export interface ResourceLimits {
|
|
29
|
+
/** Memory ceiling (e.g. `"512MB"`, `"2GB"`). */
|
|
15
30
|
memory?: string;
|
|
31
|
+
/** CPU core limit (e.g. `0.5`, `2`). */
|
|
16
32
|
cpus?: number;
|
|
17
33
|
}
|
|
34
|
+
/** A persistent storage volume. */
|
|
18
35
|
export interface Volume extends RuntimeRef {
|
|
19
36
|
type: "volume";
|
|
20
37
|
id: string;
|
|
21
38
|
config: VolumeConfig;
|
|
22
39
|
}
|
|
40
|
+
/** An auto-generated secret value, injected at deploy time. */
|
|
23
41
|
export interface Secret extends RuntimeRef {
|
|
24
42
|
type: "secret";
|
|
25
43
|
id: string;
|
|
26
44
|
config: SecretConfig;
|
|
27
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* A long-running service (container).
|
|
48
|
+
*
|
|
49
|
+
* Use `host` and `port` to reference this service from other services
|
|
50
|
+
* in the same project, or `url` for the full address.
|
|
51
|
+
*/
|
|
28
52
|
export interface Service extends RuntimeRef {
|
|
29
53
|
type: "service";
|
|
30
54
|
id: string;
|
|
31
55
|
config: ServiceConfig;
|
|
56
|
+
/** Internal hostname reachable by other services. */
|
|
32
57
|
host: string;
|
|
58
|
+
/** Port the service listens on. */
|
|
33
59
|
port: number;
|
|
60
|
+
/** Full URL — `https://<route>` if routed, otherwise `http://<host>:<port>`. */
|
|
34
61
|
url: string;
|
|
35
62
|
}
|
|
63
|
+
/** A static site served via Caddy. */
|
|
36
64
|
export interface Site extends RuntimeRef {
|
|
37
65
|
type: "site";
|
|
38
66
|
id: string;
|
|
39
67
|
config: SiteConfig;
|
|
68
|
+
/** Public URL derived from the route (e.g. `https://example.com`). */
|
|
40
69
|
url: string;
|
|
41
70
|
}
|
|
71
|
+
/** Union of all deployable resource types. */
|
|
42
72
|
export type Resource = Volume | Secret | Service | Site;
|
|
73
|
+
/**
|
|
74
|
+
* A deferred reference to a value that isn't known until deploy time.
|
|
75
|
+
*
|
|
76
|
+
* Currently only {@link Secret} produces deferred values. Expand this
|
|
77
|
+
* union as more resources gain deferred outputs.
|
|
78
|
+
*/
|
|
43
79
|
export type Reference = Secret;
|
|
80
|
+
/**
|
|
81
|
+
* A tagged-template interpolation that mixes literal strings with
|
|
82
|
+
* {@link Reference} values. Created via {@link interpolate}.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const connStr = interpolate`postgres://user:${dbPassword}@${db.host}:5432/app`;
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
44
89
|
export interface Interpolation {
|
|
45
90
|
type: "interpolation";
|
|
46
91
|
strings: TemplateStringsArray;
|
|
47
92
|
values: Array<Reference | string>;
|
|
48
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* A value that can appear in a service's `env` map.
|
|
96
|
+
*
|
|
97
|
+
* - Plain `string` — set verbatim.
|
|
98
|
+
* - {@link Reference} — resolved at deploy time (e.g. a secret).
|
|
99
|
+
* - {@link Interpolation} — a template mixing strings and references.
|
|
100
|
+
*/
|
|
49
101
|
export type EnvValue = string | Reference | Interpolation;
|
|
102
|
+
/** Type-guard: returns `true` if `value` is a {@link Reference}. */
|
|
50
103
|
export declare function isReference(value: unknown): value is Reference;
|
|
104
|
+
/** Type-guard: returns `true` if `value` is a {@link Secret}. */
|
|
51
105
|
export declare function isSecret(value: unknown): value is Secret;
|
|
106
|
+
/** Type-guard: returns `true` if `value` is an {@link Interpolation}. */
|
|
52
107
|
export declare function isInterpolation(value: unknown): value is Interpolation;
|
|
108
|
+
/** Configuration for a long-running service. */
|
|
53
109
|
export interface ServiceConfig {
|
|
110
|
+
/**
|
|
111
|
+
* Container image to run.
|
|
112
|
+
*
|
|
113
|
+
* - `string` — a registry image (e.g. `"node:22"`).
|
|
114
|
+
* - `{ context, dockerfile }` — build from a local Dockerfile.
|
|
115
|
+
*/
|
|
54
116
|
image: string | {
|
|
55
117
|
context?: string;
|
|
56
118
|
dockerfile?: string;
|
|
57
119
|
};
|
|
120
|
+
/** Public route to expose (e.g. `"api.example.com"` or `"example.com/api"`). */
|
|
58
121
|
route?: string;
|
|
122
|
+
/** Port the container listens on. Defaults to `3000`. */
|
|
59
123
|
port?: number;
|
|
124
|
+
/** Environment variables injected into the container. */
|
|
60
125
|
env?: Record<string, EnvValue>;
|
|
126
|
+
/** Override the container's default command. */
|
|
61
127
|
command?: string[];
|
|
128
|
+
/** Volumes to mount into the container. */
|
|
62
129
|
volumes?: Array<{
|
|
63
130
|
volume: Volume;
|
|
64
131
|
mount: string;
|
|
65
132
|
}>;
|
|
133
|
+
/** Services that must be healthy before this one starts. */
|
|
134
|
+
dependsOn?: Service[];
|
|
135
|
+
/** Container health check. */
|
|
136
|
+
healthCheck?: HealthCheckConfig;
|
|
137
|
+
/**
|
|
138
|
+
* Restart behaviour on failure.
|
|
139
|
+
* @defaultValue `"any"`
|
|
140
|
+
*/
|
|
141
|
+
restartPolicy?: "none" | "on-failure" | "any";
|
|
66
142
|
}
|
|
143
|
+
/** Configuration for a static site. */
|
|
67
144
|
export interface SiteConfig {
|
|
145
|
+
/** Domain (and optional path) to serve the site on. */
|
|
68
146
|
route: string;
|
|
147
|
+
/**
|
|
148
|
+
* Enable single-page application mode. When `true`, all requests that
|
|
149
|
+
* don't match a static file are rewritten to `/index.html`.
|
|
150
|
+
* @defaultValue `true`
|
|
151
|
+
*/
|
|
69
152
|
spa?: boolean;
|
|
153
|
+
/** Build settings for the static site. */
|
|
70
154
|
build: {
|
|
155
|
+
/** Working directory containing the source (relative to project root). */
|
|
71
156
|
cwd: string;
|
|
157
|
+
/** Directory containing the built output (relative to `cwd`). Defaults to `"dist"`. */
|
|
72
158
|
output?: string;
|
|
159
|
+
/** Build command to run (e.g. `"npm run build"`). */
|
|
73
160
|
command?: string;
|
|
161
|
+
/** Environment variables passed to the build command. */
|
|
74
162
|
env?: Record<string, string>;
|
|
75
163
|
};
|
|
76
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Validates a resource ID.
|
|
167
|
+
* @throws If the ID is empty, too long, or contains invalid characters.
|
|
168
|
+
*/
|
|
77
169
|
export declare function validateId(id: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* Validates a route string.
|
|
172
|
+
* @throws If the route is empty or not a valid domain with optional path.
|
|
173
|
+
*/
|
|
78
174
|
export declare function validateRoute(route: string): void;
|
package/dist/resource.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
+
/** Type-guard: returns `true` if `value` is a {@link Reference}. */
|
|
1
2
|
export function isReference(value) {
|
|
2
3
|
return isSecret(value);
|
|
3
4
|
}
|
|
5
|
+
/** Type-guard: returns `true` if `value` is a {@link Secret}. */
|
|
4
6
|
export function isSecret(value) {
|
|
5
7
|
return (typeof value === "object" &&
|
|
6
8
|
value !== null &&
|
|
7
9
|
value.type === "secret");
|
|
8
10
|
}
|
|
11
|
+
/** Type-guard: returns `true` if `value` is an {@link Interpolation}. */
|
|
9
12
|
export function isInterpolation(value) {
|
|
10
13
|
return (typeof value === "object" &&
|
|
11
14
|
value !== null &&
|
|
12
15
|
value.type === "interpolation");
|
|
13
16
|
}
|
|
14
|
-
// Validation
|
|
15
17
|
const ID_PATTERN = /^[a-z][a-z0-9-]*[a-z0-9]$|^[a-z]$/;
|
|
16
18
|
const ROUTE_PATTERN = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*(\/.+)?$/;
|
|
19
|
+
/**
|
|
20
|
+
* Validates a resource ID.
|
|
21
|
+
* @throws If the ID is empty, too long, or contains invalid characters.
|
|
22
|
+
*/
|
|
17
23
|
export function validateId(id) {
|
|
18
24
|
if (!id || id.length < 1) {
|
|
19
25
|
throw new Error("Resource ID cannot be empty");
|
|
@@ -25,6 +31,10 @@ export function validateId(id) {
|
|
|
25
31
|
throw new Error(`Invalid resource ID "${id}": must start with a letter, contain only lowercase letters, numbers, and hyphens, and end with a letter or number`);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates a route string.
|
|
36
|
+
* @throws If the route is empty or not a valid domain with optional path.
|
|
37
|
+
*/
|
|
28
38
|
export function validateRoute(route) {
|
|
29
39
|
if (!route) {
|
|
30
40
|
throw new Error("Route cannot be empty");
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Resource } from "./resource.js";
|
|
2
|
+
/** Backend that can deploy, query, and tear down resources. */
|
|
2
3
|
export interface Runtime {
|
|
4
|
+
/** Deploy or update a resource. */
|
|
3
5
|
create(resource: Resource): Promise<void>;
|
|
6
|
+
/** Check whether a resource currently exists. */
|
|
4
7
|
exists(resource: Resource): Promise<boolean>;
|
|
8
|
+
/** Tear down a resource. */
|
|
5
9
|
remove(resource: Resource): Promise<void>;
|
|
6
10
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Secret, SecretConfig, Service, ServiceConfig, Volume, VolumeConfig } from "../resource.js";
|
|
2
|
+
export interface Primitives {
|
|
3
|
+
volume(id: string, config?: VolumeConfig): Volume;
|
|
4
|
+
service(id: string, config: ServiceConfig): Service;
|
|
5
|
+
secret(id: string, config?: SecretConfig): Secret;
|
|
6
|
+
}
|
|
7
|
+
export declare function createServices(p: Primitives): {
|
|
8
|
+
postgres: (id: string, config?: import("./postgres.js").PostgresConfig) => import("./postgres.js").Postgres;
|
|
9
|
+
redis: (id: string, config?: import("./redis.js").RedisConfig) => import("./redis.js").Redis;
|
|
10
|
+
rabbitmq: (id: string, config?: import("./rabbitmq.js").RabbitmqConfig) => import("./rabbitmq.js").Rabbitmq;
|
|
11
|
+
nats: (id: string, config?: import("./nats.js").NatsConfig) => import("./nats.js").Nats;
|
|
12
|
+
mysql: (id: string, config?: import("./mysql.js").MysqlConfig) => import("./mysql.js").Mysql;
|
|
13
|
+
mongo: (id: string, config?: import("./mongo.js").MongoConfig) => import("./mongo.js").Mongo;
|
|
14
|
+
minio: (id: string, config?: import("./minio.js").MinioConfig) => import("./minio.js").Minio;
|
|
15
|
+
storage: (id: string, config?: import("./storage.js").StorageConfig) => import("./storage.js").Storage;
|
|
16
|
+
};
|
|
17
|
+
export type { Bucket, Minio, MinioConfig } from "./minio.js";
|
|
18
|
+
export type { Mongo, MongoConfig } from "./mongo.js";
|
|
19
|
+
export type { Mysql, MysqlConfig } from "./mysql.js";
|
|
20
|
+
export type { Nats, NatsConfig } from "./nats.js";
|
|
21
|
+
export type { Postgres, PostgresConfig } from "./postgres.js";
|
|
22
|
+
export type { Rabbitmq, RabbitmqConfig } from "./rabbitmq.js";
|
|
23
|
+
export type { Redis, RedisConfig } from "./redis.js";
|
|
24
|
+
export type { BackupConfig, Storage, StorageConfig } from "./storage.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createMinio } from "./minio.js";
|
|
2
|
+
import { createMongo } from "./mongo.js";
|
|
3
|
+
import { createMysql } from "./mysql.js";
|
|
4
|
+
import { createNats } from "./nats.js";
|
|
5
|
+
import { createPostgres } from "./postgres.js";
|
|
6
|
+
import { createRabbitmq } from "./rabbitmq.js";
|
|
7
|
+
import { createRedis } from "./redis.js";
|
|
8
|
+
import { createStorage } from "./storage.js";
|
|
9
|
+
export function createServices(p) {
|
|
10
|
+
return {
|
|
11
|
+
postgres: createPostgres(p),
|
|
12
|
+
redis: createRedis(p),
|
|
13
|
+
rabbitmq: createRabbitmq(p),
|
|
14
|
+
nats: createNats(p),
|
|
15
|
+
mysql: createMysql(p),
|
|
16
|
+
mongo: createMongo(p),
|
|
17
|
+
minio: createMinio(p),
|
|
18
|
+
storage: createStorage(p),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Secret, Service, Volume } from "../resource.js";
|
|
2
|
+
import type { Primitives } from "./index.js";
|
|
3
|
+
/** Configuration for a managed MinIO instance. */
|
|
4
|
+
export interface MinioConfig {
|
|
5
|
+
/** MinIO image tag. @defaultValue `"latest"` */
|
|
6
|
+
version?: string;
|
|
7
|
+
/** Volume size hint (e.g. `"50GB"`). */
|
|
8
|
+
size?: string;
|
|
9
|
+
}
|
|
10
|
+
/** A named S3-compatible bucket on this MinIO instance. */
|
|
11
|
+
export interface Bucket {
|
|
12
|
+
/** Bucket name. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Init service that creates the bucket on first deploy. */
|
|
15
|
+
service: Service;
|
|
16
|
+
}
|
|
17
|
+
/** A managed MinIO (S3-compatible) instance with its associated resources. */
|
|
18
|
+
export interface Minio {
|
|
19
|
+
/** The underlying service running MinIO. */
|
|
20
|
+
service: Service;
|
|
21
|
+
/** Persistent volume for object storage data. */
|
|
22
|
+
volume: Volume;
|
|
23
|
+
/** Auto-generated root access key. */
|
|
24
|
+
accessKey: Secret;
|
|
25
|
+
/** Auto-generated root secret key. */
|
|
26
|
+
secretKey: Secret;
|
|
27
|
+
/** Internal hostname reachable by other services. */
|
|
28
|
+
host: string;
|
|
29
|
+
/** Port the MinIO API listens on (`9000`). */
|
|
30
|
+
port: number;
|
|
31
|
+
/** Full internal endpoint URL (e.g. `http://<host>:9000`). */
|
|
32
|
+
endpoint: string;
|
|
33
|
+
/** Create a bucket that is provisioned automatically on deploy. */
|
|
34
|
+
bucket: (name: string) => Bucket;
|
|
35
|
+
}
|
|
36
|
+
export declare function createMinio(p: Primitives): (id: string, config?: MinioConfig) => Minio;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { validateId } from "../resource.js";
|
|
2
|
+
export function createMinio(p) {
|
|
3
|
+
return function minio(id, config = {}) {
|
|
4
|
+
validateId(id);
|
|
5
|
+
const version = config.version ?? "latest";
|
|
6
|
+
const accessKey = p.secret(`${id}-access-key`, { length: 16 });
|
|
7
|
+
const secretKey = p.secret(`${id}-secret-key`, { length: 32 });
|
|
8
|
+
const vol = p.volume(`${id}-data`, { size: config.size });
|
|
9
|
+
const svc = p.service(id, {
|
|
10
|
+
image: `minio/minio:${version}`,
|
|
11
|
+
port: 9000,
|
|
12
|
+
command: ["server", "/data"],
|
|
13
|
+
volumes: [{ volume: vol, mount: "/data" }],
|
|
14
|
+
env: {
|
|
15
|
+
MINIO_ROOT_USER: accessKey,
|
|
16
|
+
MINIO_ROOT_PASSWORD: secretKey,
|
|
17
|
+
},
|
|
18
|
+
healthCheck: {
|
|
19
|
+
command: ["mc", "ready", "local"],
|
|
20
|
+
interval: "5s",
|
|
21
|
+
timeout: "5s",
|
|
22
|
+
retries: 5,
|
|
23
|
+
startPeriod: "5s",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
service: svc,
|
|
28
|
+
volume: vol,
|
|
29
|
+
accessKey,
|
|
30
|
+
secretKey,
|
|
31
|
+
host: svc.host,
|
|
32
|
+
port: 9000,
|
|
33
|
+
endpoint: `http://${svc.host}:9000`,
|
|
34
|
+
bucket(name) {
|
|
35
|
+
const initSvc = p.service(`${id}-bucket-${name}`, {
|
|
36
|
+
image: "minio/mc:latest",
|
|
37
|
+
command: [
|
|
38
|
+
"sh",
|
|
39
|
+
"-c",
|
|
40
|
+
`mc alias set minio http://${svc.host}:9000 $(cat $ACCESS_KEY_FILE) $(cat $SECRET_KEY_FILE) && mc mb --ignore-existing minio/${name}`,
|
|
41
|
+
],
|
|
42
|
+
env: {
|
|
43
|
+
ACCESS_KEY: accessKey,
|
|
44
|
+
SECRET_KEY: secretKey,
|
|
45
|
+
},
|
|
46
|
+
dependsOn: [svc],
|
|
47
|
+
restartPolicy: "none",
|
|
48
|
+
});
|
|
49
|
+
return { name, service: initSvc };
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Interpolation, Secret, Service, Volume } from "../resource.js";
|
|
2
|
+
import type { Primitives } from "./index.js";
|
|
3
|
+
import { type BackupConfig } from "./storage.js";
|
|
4
|
+
/** Configuration for a managed MongoDB instance. */
|
|
5
|
+
export interface MongoConfig {
|
|
6
|
+
/** Major MongoDB version. @defaultValue `8` */
|
|
7
|
+
version?: number;
|
|
8
|
+
/** Volume size hint (e.g. `"10GB"`). */
|
|
9
|
+
size?: string;
|
|
10
|
+
/** Backup configuration. */
|
|
11
|
+
backup?: BackupConfig;
|
|
12
|
+
}
|
|
13
|
+
/** A managed MongoDB instance with its associated resources. */
|
|
14
|
+
export interface Mongo {
|
|
15
|
+
/** The underlying service running MongoDB. */
|
|
16
|
+
service: Service;
|
|
17
|
+
/** Persistent volume for MongoDB data. */
|
|
18
|
+
volume: Volume;
|
|
19
|
+
/** Auto-generated root password secret. */
|
|
20
|
+
password: Secret;
|
|
21
|
+
/** Internal hostname reachable by other services. */
|
|
22
|
+
host: string;
|
|
23
|
+
/** Port MongoDB listens on (`27017`). */
|
|
24
|
+
port: number;
|
|
25
|
+
/** Connection string with credentials injected at deploy time. */
|
|
26
|
+
url: Interpolation;
|
|
27
|
+
}
|
|
28
|
+
export declare function createMongo(p: Primitives): (id: string, config?: MongoConfig) => Mongo;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { interpolate } from "../interpolate.js";
|
|
2
|
+
import { validateId } from "../resource.js";
|
|
3
|
+
import { createBackupSidecar } from "./storage.js";
|
|
4
|
+
export function createMongo(p) {
|
|
5
|
+
return function mongo(id, config = {}) {
|
|
6
|
+
validateId(id);
|
|
7
|
+
const version = config.version ?? 8;
|
|
8
|
+
const password = p.secret(`${id}-password`, { length: 32 });
|
|
9
|
+
const vol = p.volume(`${id}-data`, { size: config.size });
|
|
10
|
+
const svc = p.service(id, {
|
|
11
|
+
image: `mongo:${version}`,
|
|
12
|
+
port: 27017,
|
|
13
|
+
volumes: [{ volume: vol, mount: "/data/db" }],
|
|
14
|
+
env: {
|
|
15
|
+
MONGO_INITDB_ROOT_USERNAME: "mongo",
|
|
16
|
+
MONGO_INITDB_ROOT_PASSWORD: password,
|
|
17
|
+
},
|
|
18
|
+
healthCheck: {
|
|
19
|
+
command: ["mongosh", "--eval", "db.runCommand('ping').ok", "--quiet"],
|
|
20
|
+
interval: "5s",
|
|
21
|
+
timeout: "5s",
|
|
22
|
+
retries: 5,
|
|
23
|
+
startPeriod: "10s",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (config.backup) {
|
|
27
|
+
createBackupSidecar(p, {
|
|
28
|
+
id,
|
|
29
|
+
image: `mongo:${version}`,
|
|
30
|
+
svc,
|
|
31
|
+
backup: config.backup,
|
|
32
|
+
dumpScript: `TIMESTAMP=$(date +%Y%m%d-%H%M%S) && mongodump --uri="mongodb://mongo:$(cat $DB_PASSWORD_FILE)@${svc.host}:27017" --archive --gzip | mc pipe backup/${config.backup.storage.bucket}/${id}-$TIMESTAMP.gz`,
|
|
33
|
+
env: { DB_PASSWORD: password },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
service: svc,
|
|
38
|
+
volume: vol,
|
|
39
|
+
password,
|
|
40
|
+
host: svc.host,
|
|
41
|
+
port: 27017,
|
|
42
|
+
url: interpolate `mongodb://mongo:${password}@${svc.host}:27017`,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Interpolation, Secret, Service, Volume } from "../resource.js";
|
|
2
|
+
import type { Primitives } from "./index.js";
|
|
3
|
+
import { type BackupConfig } from "./storage.js";
|
|
4
|
+
/** Configuration for a managed MySQL instance. */
|
|
5
|
+
export interface MysqlConfig {
|
|
6
|
+
/** Major MySQL version. @defaultValue `9` */
|
|
7
|
+
version?: number;
|
|
8
|
+
/** Volume size hint (e.g. `"10GB"`). */
|
|
9
|
+
size?: string;
|
|
10
|
+
/** Backup configuration. */
|
|
11
|
+
backup?: BackupConfig;
|
|
12
|
+
}
|
|
13
|
+
/** A managed MySQL instance with its associated resources. */
|
|
14
|
+
export interface Mysql {
|
|
15
|
+
/** The underlying service running MySQL. */
|
|
16
|
+
service: Service;
|
|
17
|
+
/** Persistent volume for MySQL data. */
|
|
18
|
+
volume: Volume;
|
|
19
|
+
/** Auto-generated `MYSQL_ROOT_PASSWORD` secret. */
|
|
20
|
+
password: Secret;
|
|
21
|
+
/** Internal hostname reachable by other services. */
|
|
22
|
+
host: string;
|
|
23
|
+
/** Port MySQL listens on (`3306`). */
|
|
24
|
+
port: number;
|
|
25
|
+
/** Connection string with the password injected at deploy time. */
|
|
26
|
+
url: Interpolation;
|
|
27
|
+
}
|
|
28
|
+
export declare function createMysql(p: Primitives): (id: string, config?: MysqlConfig) => Mysql;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { interpolate } from "../interpolate.js";
|
|
2
|
+
import { validateId } from "../resource.js";
|
|
3
|
+
import { createBackupSidecar } from "./storage.js";
|
|
4
|
+
export function createMysql(p) {
|
|
5
|
+
return function mysql(id, config = {}) {
|
|
6
|
+
validateId(id);
|
|
7
|
+
const version = config.version ?? 9;
|
|
8
|
+
const password = p.secret(`${id}-password`, { length: 32 });
|
|
9
|
+
const vol = p.volume(`${id}-data`, { size: config.size });
|
|
10
|
+
const svc = p.service(id, {
|
|
11
|
+
image: `mysql:${version}`,
|
|
12
|
+
port: 3306,
|
|
13
|
+
volumes: [{ volume: vol, mount: "/var/lib/mysql" }],
|
|
14
|
+
env: {
|
|
15
|
+
MYSQL_ROOT_PASSWORD: password,
|
|
16
|
+
},
|
|
17
|
+
healthCheck: {
|
|
18
|
+
command: ["mysqladmin", "ping", "-h", "localhost"],
|
|
19
|
+
interval: "5s",
|
|
20
|
+
timeout: "5s",
|
|
21
|
+
retries: 5,
|
|
22
|
+
startPeriod: "15s",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
if (config.backup) {
|
|
26
|
+
createBackupSidecar(p, {
|
|
27
|
+
id,
|
|
28
|
+
image: `mysql:${version}`,
|
|
29
|
+
svc,
|
|
30
|
+
backup: config.backup,
|
|
31
|
+
dumpScript: `TIMESTAMP=$(date +%Y%m%d-%H%M%S) && mysqldump -h ${svc.host} -u root -p$(cat $DB_PASSWORD_FILE) --all-databases | gzip | mc pipe backup/${config.backup.storage.bucket}/${id}-$TIMESTAMP.sql.gz`,
|
|
32
|
+
env: { DB_PASSWORD: password },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
service: svc,
|
|
37
|
+
volume: vol,
|
|
38
|
+
password,
|
|
39
|
+
host: svc.host,
|
|
40
|
+
port: 3306,
|
|
41
|
+
url: interpolate `mysql://root:${password}@${svc.host}:3306`,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Service, Volume } from "../resource.js";
|
|
2
|
+
import type { Primitives } from "./index.js";
|
|
3
|
+
import { type BackupConfig } from "./storage.js";
|
|
4
|
+
/** Configuration for a managed NATS instance. */
|
|
5
|
+
export interface NatsConfig {
|
|
6
|
+
/** Major NATS version. @defaultValue `2` */
|
|
7
|
+
version?: number;
|
|
8
|
+
/** Volume size hint (e.g. `"5GB"`). */
|
|
9
|
+
size?: string;
|
|
10
|
+
/** Backup configuration. */
|
|
11
|
+
backup?: BackupConfig;
|
|
12
|
+
}
|
|
13
|
+
/** A managed NATS instance with JetStream enabled. */
|
|
14
|
+
export interface Nats {
|
|
15
|
+
/** The underlying service running NATS. */
|
|
16
|
+
service: Service;
|
|
17
|
+
/** Persistent volume for JetStream data. */
|
|
18
|
+
volume: Volume;
|
|
19
|
+
/** Internal hostname reachable by other services. */
|
|
20
|
+
host: string;
|
|
21
|
+
/** Port NATS listens on (`4222`). */
|
|
22
|
+
port: number;
|
|
23
|
+
/** Connection URL (e.g. `nats://<host>:4222`). */
|
|
24
|
+
url: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function createNats(p: Primitives): (id: string, config?: NatsConfig) => Nats;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { validateId } from "../resource.js";
|
|
2
|
+
import { createBackupSidecar } from "./storage.js";
|
|
3
|
+
export function createNats(p) {
|
|
4
|
+
return function nats(id, config = {}) {
|
|
5
|
+
validateId(id);
|
|
6
|
+
const version = config.version ?? 2;
|
|
7
|
+
const vol = p.volume(`${id}-data`, { size: config.size });
|
|
8
|
+
const svc = p.service(id, {
|
|
9
|
+
image: `nats:${version}`,
|
|
10
|
+
port: 4222,
|
|
11
|
+
command: ["--jetstream", "--store_dir", "/data"],
|
|
12
|
+
volumes: [{ volume: vol, mount: "/data" }],
|
|
13
|
+
healthCheck: {
|
|
14
|
+
command: ["sh", "-c", "wget -qO- http://localhost:8222/healthz"],
|
|
15
|
+
interval: "5s",
|
|
16
|
+
timeout: "5s",
|
|
17
|
+
retries: 5,
|
|
18
|
+
startPeriod: "5s",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
if (config.backup) {
|
|
22
|
+
createBackupSidecar(p, {
|
|
23
|
+
id,
|
|
24
|
+
image: "natsio/nats-box",
|
|
25
|
+
svc,
|
|
26
|
+
backup: config.backup,
|
|
27
|
+
dumpScript: `TIMESTAMP=$(date +%Y%m%d-%H%M%S) && mkdir -p /tmp/backup && for s in $(nats -s nats://${svc.host}:4222 stream ls -n 2>/dev/null); do nats -s nats://${svc.host}:4222 stream backup "$s" "/tmp/backup/$s"; done && tar czf - -C /tmp backup | mc pipe backup/${config.backup.storage.bucket}/${id}-$TIMESTAMP.tar.gz && rm -rf /tmp/backup`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
service: svc,
|
|
32
|
+
volume: vol,
|
|
33
|
+
host: svc.host,
|
|
34
|
+
port: 4222,
|
|
35
|
+
url: `nats://${svc.host}:4222`,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Interpolation, Secret, Service, Volume } from "../resource.js";
|
|
2
|
+
import type { Primitives } from "./index.js";
|
|
3
|
+
import { type BackupConfig } from "./storage.js";
|
|
4
|
+
/** Configuration for a managed Postgres instance. */
|
|
5
|
+
export interface PostgresConfig {
|
|
6
|
+
/** Major Postgres version. @defaultValue `18` */
|
|
7
|
+
version?: number;
|
|
8
|
+
/** Volume size hint (e.g. `"10GB"`). */
|
|
9
|
+
size?: string;
|
|
10
|
+
/** Backup configuration. */
|
|
11
|
+
backup?: BackupConfig;
|
|
12
|
+
}
|
|
13
|
+
/** A managed Postgres instance with its associated resources. */
|
|
14
|
+
export interface Postgres {
|
|
15
|
+
/** The underlying service running Postgres. */
|
|
16
|
+
service: Service;
|
|
17
|
+
/** Persistent volume for Postgres data. */
|
|
18
|
+
volume: Volume;
|
|
19
|
+
/** Auto-generated `POSTGRES_PASSWORD` secret. */
|
|
20
|
+
password: Secret;
|
|
21
|
+
/** Internal hostname reachable by other services. */
|
|
22
|
+
host: string;
|
|
23
|
+
/** Port Postgres listens on (`5432`). */
|
|
24
|
+
port: number;
|
|
25
|
+
/** Connection string with the password injected at deploy time. */
|
|
26
|
+
url: Interpolation;
|
|
27
|
+
}
|
|
28
|
+
export declare function createPostgres(p: Primitives): (id: string, config?: PostgresConfig) => Postgres;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { interpolate } from "../interpolate.js";
|
|
2
|
+
import { validateId } from "../resource.js";
|
|
3
|
+
import { createBackupSidecar } from "./storage.js";
|
|
4
|
+
export function createPostgres(p) {
|
|
5
|
+
return function postgres(id, config = {}) {
|
|
6
|
+
validateId(id);
|
|
7
|
+
const version = config.version ?? 18;
|
|
8
|
+
const mount = version >= 18 ? "/var/lib/postgresql" : "/var/lib/postgresql/data";
|
|
9
|
+
const password = p.secret(`${id}-password`, { length: 32 });
|
|
10
|
+
const vol = p.volume(`${id}-data`, { size: config.size });
|
|
11
|
+
const svc = p.service(id, {
|
|
12
|
+
image: `postgres:${version}`,
|
|
13
|
+
port: 5432,
|
|
14
|
+
volumes: [{ volume: vol, mount }],
|
|
15
|
+
env: {
|
|
16
|
+
POSTGRES_PASSWORD: password,
|
|
17
|
+
},
|
|
18
|
+
healthCheck: {
|
|
19
|
+
command: ["pg_isready", "-U", "postgres"],
|
|
20
|
+
interval: "5s",
|
|
21
|
+
timeout: "5s",
|
|
22
|
+
retries: 5,
|
|
23
|
+
startPeriod: "10s",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (config.backup) {
|
|
27
|
+
createBackupSidecar(p, {
|
|
28
|
+
id,
|
|
29
|
+
image: `postgres:${version}`,
|
|
30
|
+
svc,
|
|
31
|
+
backup: config.backup,
|
|
32
|
+
dumpScript: `TIMESTAMP=$(date +%Y%m%d-%H%M%S) && PGPASSWORD=$(cat $DB_PASSWORD_FILE) pg_dump -h ${svc.host} -U postgres | gzip | mc pipe backup/${config.backup.storage.bucket}/${id}-$TIMESTAMP.sql.gz`,
|
|
33
|
+
env: { DB_PASSWORD: password },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
service: svc,
|
|
38
|
+
volume: vol,
|
|
39
|
+
password,
|
|
40
|
+
host: svc.host,
|
|
41
|
+
port: 5432,
|
|
42
|
+
url: interpolate `postgres://postgres:${password}@${svc.host}:5432/postgres`,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|