vyft 0.2.0-alpha → 0.4.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.
Files changed (56) hide show
  1. package/README.md +5 -16
  2. package/dist/build.d.ts +1 -0
  3. package/dist/build.js +9 -4
  4. package/dist/cli.js +648 -43
  5. package/dist/context.d.ts +39 -0
  6. package/dist/context.js +101 -0
  7. package/dist/docker.d.ts +24 -12
  8. package/dist/docker.js +299 -389
  9. package/dist/exec.d.ts +1 -1
  10. package/dist/exec.js +2 -2
  11. package/dist/index.d.ts +4 -1
  12. package/dist/index.js +5 -1
  13. package/dist/init.js +19 -2
  14. package/dist/interpolate.d.ts +11 -0
  15. package/dist/interpolate.js +11 -0
  16. package/dist/local/dev.d.ts +31 -0
  17. package/dist/local/dev.js +109 -0
  18. package/dist/local/index.d.ts +2 -0
  19. package/dist/local/index.js +2 -0
  20. package/dist/local/runtime.d.ts +61 -0
  21. package/dist/local/runtime.js +391 -0
  22. package/dist/proxy.d.ts +16 -0
  23. package/dist/proxy.js +0 -0
  24. package/dist/resource.d.ts +104 -1
  25. package/dist/resource.js +11 -1
  26. package/dist/runtime.d.ts +11 -1
  27. package/dist/services/index.d.ts +26 -0
  28. package/dist/services/index.js +35 -0
  29. package/dist/services/minio.d.ts +36 -0
  30. package/dist/services/minio.js +53 -0
  31. package/dist/services/mongo.d.ts +28 -0
  32. package/dist/services/mongo.js +45 -0
  33. package/dist/services/mysql.d.ts +28 -0
  34. package/dist/services/mysql.js +44 -0
  35. package/dist/services/nats.d.ts +26 -0
  36. package/dist/services/nats.js +38 -0
  37. package/dist/services/postgres.d.ts +28 -0
  38. package/dist/services/postgres.js +45 -0
  39. package/dist/services/rabbitmq.d.ts +28 -0
  40. package/dist/services/rabbitmq.js +44 -0
  41. package/dist/services/redis.d.ts +28 -0
  42. package/dist/services/redis.js +49 -0
  43. package/dist/services/storage.d.ts +39 -0
  44. package/dist/services/storage.js +94 -0
  45. package/dist/swarm/factories.d.ts +9 -2
  46. package/dist/swarm/factories.js +9 -32
  47. package/dist/swarm/index.d.ts +11 -2
  48. package/dist/swarm/proxy.d.ts +24 -0
  49. package/dist/swarm/proxy.js +339 -0
  50. package/dist/swarm/types.d.ts +11 -21
  51. package/dist/symbols.d.ts +7 -0
  52. package/dist/symbols.js +3 -0
  53. package/package.json +4 -5
  54. package/templates/fullstack/package.json +2 -6
  55. package/templates/fullstack/vyft.config.ts +13 -28
  56. package/templates/fullstack/compose.yaml +0 -14
@@ -0,0 +1,35 @@
1
+ import { VYFT_MANAGED } from "../symbols.js";
2
+ import { createMinio } from "./minio.js";
3
+ import { createMongo } from "./mongo.js";
4
+ import { createMysql } from "./mysql.js";
5
+ import { createNats } from "./nats.js";
6
+ import { createPostgres } from "./postgres.js";
7
+ import { createRabbitmq } from "./rabbitmq.js";
8
+ import { createRedis } from "./redis.js";
9
+ import { createStorage } from "./storage.js";
10
+ function wrapPrimitives(p) {
11
+ return {
12
+ volume: (id, cfg) => Object.assign(p.volume(id, cfg), { [VYFT_MANAGED]: true }),
13
+ service: (id, cfg) => Object.assign(p.service(id, cfg), { [VYFT_MANAGED]: true }),
14
+ secret: (id, cfg) => Object.assign(p.secret(id, cfg), { [VYFT_MANAGED]: true }),
15
+ };
16
+ }
17
+ /** Returns `true` if a resource was created by a built-in factory. */
18
+ export function isManaged(resource) {
19
+ return (typeof resource === "object" &&
20
+ resource !== null &&
21
+ resource[VYFT_MANAGED] === true);
22
+ }
23
+ export function createServices(p) {
24
+ const wrapped = wrapPrimitives(p);
25
+ return {
26
+ postgres: createPostgres(wrapped),
27
+ redis: createRedis(wrapped),
28
+ rabbitmq: createRabbitmq(wrapped),
29
+ nats: createNats(wrapped),
30
+ mysql: createMysql(wrapped),
31
+ mongo: createMongo(wrapped),
32
+ minio: createMinio(wrapped),
33
+ storage: createStorage(wrapped),
34
+ };
35
+ }
@@ -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
+ }
@@ -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 RabbitMQ instance. */
5
+ export interface RabbitmqConfig {
6
+ /** Major RabbitMQ version. @defaultValue `4` */
7
+ version?: number;
8
+ /** Volume size hint (e.g. `"5GB"`). */
9
+ size?: string;
10
+ /** Backup configuration. */
11
+ backup?: BackupConfig;
12
+ }
13
+ /** A managed RabbitMQ instance with its associated resources. */
14
+ export interface Rabbitmq {
15
+ /** The underlying service running RabbitMQ. */
16
+ service: Service;
17
+ /** Persistent volume for RabbitMQ data. */
18
+ volume: Volume;
19
+ /** Auto-generated `RABBITMQ_DEFAULT_PASS` secret. */
20
+ password: Secret;
21
+ /** Internal hostname reachable by other services. */
22
+ host: string;
23
+ /** Port RabbitMQ listens on (`5672`). */
24
+ port: number;
25
+ /** AMQP connection string with credentials injected at deploy time. */
26
+ url: Interpolation;
27
+ }
28
+ export declare function createRabbitmq(p: Primitives): (id: string, config?: RabbitmqConfig) => Rabbitmq;
@@ -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 createRabbitmq(p) {
5
+ return function rabbitmq(id, config = {}) {
6
+ validateId(id);
7
+ const version = config.version ?? 4;
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: `rabbitmq:${version}`,
12
+ port: 5672,
13
+ volumes: [{ volume: vol, mount: "/var/lib/rabbitmq" }],
14
+ env: {
15
+ RABBITMQ_DEFAULT_PASS: password,
16
+ },
17
+ healthCheck: {
18
+ command: ["rabbitmq-diagnostics", "check_running"],
19
+ interval: "10s",
20
+ timeout: "10s",
21
+ retries: 5,
22
+ startPeriod: "30s",
23
+ },
24
+ });
25
+ if (config.backup) {
26
+ createBackupSidecar(p, {
27
+ id,
28
+ image: `rabbitmq:${version}`,
29
+ svc,
30
+ backup: config.backup,
31
+ dumpScript: `TIMESTAMP=$(date +%Y%m%d-%H%M%S) && rabbitmqctl export_definitions - | gzip | mc pipe backup/${config.backup.storage.bucket}/${id}-$TIMESTAMP.json.gz`,
32
+ env: { DB_PASSWORD: password },
33
+ });
34
+ }
35
+ return {
36
+ service: svc,
37
+ volume: vol,
38
+ password,
39
+ host: svc.host,
40
+ port: 5672,
41
+ url: interpolate `amqp://guest:${password}@${svc.host}:5672`,
42
+ };
43
+ };
44
+ }
@@ -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 Redis instance. */
5
+ export interface RedisConfig {
6
+ /** Major Redis version. @defaultValue `7` */
7
+ version?: number;
8
+ /** Volume size hint (e.g. `"5GB"`). */
9
+ size?: string;
10
+ /** Backup configuration. */
11
+ backup?: BackupConfig;
12
+ }
13
+ /** A managed Redis instance with its associated resources. */
14
+ export interface Redis {
15
+ /** The underlying service running Redis. */
16
+ service: Service;
17
+ /** Persistent volume for Redis data. */
18
+ volume: Volume;
19
+ /** Auto-generated `REDIS_PASSWORD` secret. */
20
+ password: Secret;
21
+ /** Internal hostname reachable by other services. */
22
+ host: string;
23
+ /** Port Redis listens on (`6379`). */
24
+ port: number;
25
+ /** Connection string with the password injected at deploy time. */
26
+ url: Interpolation;
27
+ }
28
+ export declare function createRedis(p: Primitives): (id: string, config?: RedisConfig) => Redis;
@@ -0,0 +1,49 @@
1
+ import { interpolate } from "../interpolate.js";
2
+ import { validateId } from "../resource.js";
3
+ import { createBackupSidecar } from "./storage.js";
4
+ export function createRedis(p) {
5
+ return function redis(id, config = {}) {
6
+ validateId(id);
7
+ const version = config.version ?? 7;
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: `redis:${version}`,
12
+ port: 6379,
13
+ command: [
14
+ "sh",
15
+ "-c",
16
+ 'redis-server --requirepass "$(cat /run/secrets/*-password)"',
17
+ ],
18
+ volumes: [{ volume: vol, mount: "/data" }],
19
+ env: {
20
+ REDIS_PASSWORD: password,
21
+ },
22
+ healthCheck: {
23
+ command: ["redis-cli", "ping"],
24
+ interval: "5s",
25
+ timeout: "5s",
26
+ retries: 5,
27
+ startPeriod: "5s",
28
+ },
29
+ });
30
+ if (config.backup) {
31
+ createBackupSidecar(p, {
32
+ id,
33
+ image: `redis:${version}`,
34
+ svc,
35
+ backup: config.backup,
36
+ dumpScript: `TIMESTAMP=$(date +%Y%m%d-%H%M%S) && redis-cli -h ${svc.host} -a $(cat $DB_PASSWORD_FILE) --rdb /tmp/dump.rdb && gzip -c /tmp/dump.rdb | mc pipe backup/${config.backup.storage.bucket}/${id}-$TIMESTAMP.rdb.gz && rm -f /tmp/dump.rdb`,
37
+ env: { DB_PASSWORD: password },
38
+ });
39
+ }
40
+ return {
41
+ service: svc,
42
+ volume: vol,
43
+ password,
44
+ host: svc.host,
45
+ port: 6379,
46
+ url: interpolate `redis://:${password}@${svc.host}:6379`,
47
+ };
48
+ };
49
+ }
@@ -0,0 +1,39 @@
1
+ import type { EnvValue, Secret, Service } from "../resource.js";
2
+ import type { Primitives } from "./index.js";
3
+ /** Configuration for a managed storage backend. */
4
+ export interface StorageConfig {
5
+ /** Volume size hint for the backing store. */
6
+ size?: string;
7
+ /** MinIO image tag. @defaultValue `"latest"` */
8
+ version?: string;
9
+ }
10
+ /** An S3-compatible storage bucket provisioned by the shared storage backend. */
11
+ export interface Storage {
12
+ /** The backing MinIO service (for dependsOn). */
13
+ service: Service;
14
+ /** Root access key. */
15
+ accessKey: Secret;
16
+ /** Root secret key. */
17
+ secretKey: Secret;
18
+ /** S3-compatible endpoint URL (e.g. `http://<host>:9000`). */
19
+ endpoint: string;
20
+ /** Bucket name (matches the storage id). */
21
+ bucket: string;
22
+ }
23
+ /** Backup configuration accepted by service factories. */
24
+ export interface BackupConfig {
25
+ /** Storage target for backups. */
26
+ storage: Storage;
27
+ /** Cron expression for backup schedule. @defaultValue `"0 3 * * *"` (daily 3am) */
28
+ schedule?: string;
29
+ }
30
+ /** Create a backup sidecar service for a database. */
31
+ export declare function createBackupSidecar(p: Primitives, opts: {
32
+ id: string;
33
+ image: string;
34
+ svc: Service;
35
+ backup: BackupConfig;
36
+ dumpScript: string;
37
+ env?: Record<string, EnvValue>;
38
+ }): void;
39
+ export declare function createStorage(p: Primitives): (id: string, config?: StorageConfig) => Storage;