vyft 0.1.1-alpha → 0.2.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/dist/cli.js +22 -1
- package/dist/swarm/factories.d.ts +6 -5
- package/dist/swarm/factories.js +74 -44
- package/dist/swarm/index.d.ts +3 -2
- package/dist/swarm/types.d.ts +12 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -46,6 +46,27 @@ function isResource(value) {
|
|
|
46
46
|
typeof value.type === "string" &&
|
|
47
47
|
typeof value.id === "string");
|
|
48
48
|
}
|
|
49
|
+
function collectResources(exports) {
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const resources = [];
|
|
52
|
+
for (const value of Object.values(exports)) {
|
|
53
|
+
if (isResource(value)) {
|
|
54
|
+
if (!seen.has(value.id)) {
|
|
55
|
+
seen.add(value.id);
|
|
56
|
+
resources.push(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (typeof value === "object" && value !== null) {
|
|
60
|
+
for (const nested of Object.values(value)) {
|
|
61
|
+
if (isResource(nested) && !seen.has(nested.id)) {
|
|
62
|
+
seen.add(nested.id);
|
|
63
|
+
resources.push(nested);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return resources;
|
|
69
|
+
}
|
|
49
70
|
function hasRuntime(value) {
|
|
50
71
|
return (typeof value === "object" &&
|
|
51
72
|
value !== null &&
|
|
@@ -72,7 +93,7 @@ async function deploy(configFile, verbose) {
|
|
|
72
93
|
process.env.VYFT_PROJECT = project;
|
|
73
94
|
intro(`Deploying ${project}`);
|
|
74
95
|
const config = await import(configFile);
|
|
75
|
-
const resources =
|
|
96
|
+
const resources = collectResources(config);
|
|
76
97
|
if (resources.length === 0) {
|
|
77
98
|
log.warn("No resources found");
|
|
78
99
|
outro();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Secret, SecretConfig, Service, Site, SiteConfig, Volume } from "../resource.js";
|
|
2
|
-
import type { StorageDriver, SwarmConfig, SwarmServiceConfig, SwarmVolumeConfig } from "./types.js";
|
|
2
|
+
import type { Postgres, PostgresConfig, StorageDriver, SwarmConfig, SwarmServiceConfig, SwarmVolumeConfig } from "./types.js";
|
|
3
3
|
export declare function createFactories<D extends StorageDriver = "local">(swarmConfig: SwarmConfig<D>): {
|
|
4
|
-
volume(id: string, config?: SwarmVolumeConfig<D>)
|
|
5
|
-
service(id: string, config: SwarmServiceConfig)
|
|
6
|
-
secret(id: string, config?: SecretConfig)
|
|
7
|
-
site(id: string, config: SiteConfig)
|
|
4
|
+
volume: (id: string, config?: SwarmVolumeConfig<D>) => Volume;
|
|
5
|
+
service: (id: string, config: SwarmServiceConfig) => Service;
|
|
6
|
+
secret: (id: string, config?: SecretConfig) => Secret;
|
|
7
|
+
site: (id: string, config: SiteConfig) => Site;
|
|
8
|
+
postgres: (id: string, config?: PostgresConfig) => Postgres;
|
|
8
9
|
};
|
package/dist/swarm/factories.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { interpolate } from "../interpolate.js";
|
|
1
2
|
import { validateId, validateRoute } from "../resource.js";
|
|
2
3
|
import { VYFT_RUNTIME } from "../symbols.js";
|
|
3
4
|
function attachRuntime(obj, config) {
|
|
@@ -8,49 +9,78 @@ function attachRuntime(obj, config) {
|
|
|
8
9
|
export function createFactories(swarmConfig) {
|
|
9
10
|
const project = process.env.VYFT_PROJECT;
|
|
10
11
|
const prefix = project ? `${project}-` : "";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (config.route) {
|
|
20
|
-
validateRoute(config.route);
|
|
21
|
-
}
|
|
22
|
-
const fullId = `${prefix}${id}`;
|
|
23
|
-
const port = config.port || 3000;
|
|
24
|
-
return attachRuntime({
|
|
25
|
-
type: "service",
|
|
26
|
-
id: fullId,
|
|
27
|
-
config,
|
|
28
|
-
host: fullId,
|
|
29
|
-
port,
|
|
30
|
-
url: config.route
|
|
31
|
-
? `https://${config.route}`
|
|
32
|
-
: `http://${fullId}:${port}`,
|
|
33
|
-
}, swarmConfig);
|
|
34
|
-
},
|
|
35
|
-
secret(id, config = {}) {
|
|
36
|
-
validateId(id);
|
|
37
|
-
const fullId = `${prefix}${id}`;
|
|
38
|
-
return attachRuntime({
|
|
39
|
-
type: "secret",
|
|
40
|
-
id: fullId,
|
|
41
|
-
config,
|
|
42
|
-
}, swarmConfig);
|
|
43
|
-
},
|
|
44
|
-
site(id, config) {
|
|
45
|
-
validateId(id);
|
|
12
|
+
function volume(id, config = {}) {
|
|
13
|
+
validateId(id);
|
|
14
|
+
const fullId = `${prefix}${id}`;
|
|
15
|
+
return attachRuntime({ type: "volume", id: fullId, config }, swarmConfig);
|
|
16
|
+
}
|
|
17
|
+
function service(id, config) {
|
|
18
|
+
validateId(id);
|
|
19
|
+
if (config.route) {
|
|
46
20
|
validateRoute(config.route);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
}
|
|
22
|
+
const fullId = `${prefix}${id}`;
|
|
23
|
+
const port = config.port || 3000;
|
|
24
|
+
return attachRuntime({
|
|
25
|
+
type: "service",
|
|
26
|
+
id: fullId,
|
|
27
|
+
config,
|
|
28
|
+
host: fullId,
|
|
29
|
+
port,
|
|
30
|
+
url: config.route
|
|
31
|
+
? `https://${config.route}`
|
|
32
|
+
: `http://${fullId}:${port}`,
|
|
33
|
+
}, swarmConfig);
|
|
34
|
+
}
|
|
35
|
+
function secret(id, config = {}) {
|
|
36
|
+
validateId(id);
|
|
37
|
+
const fullId = `${prefix}${id}`;
|
|
38
|
+
return attachRuntime({
|
|
39
|
+
type: "secret",
|
|
40
|
+
id: fullId,
|
|
41
|
+
config,
|
|
42
|
+
}, swarmConfig);
|
|
43
|
+
}
|
|
44
|
+
function site(id, config) {
|
|
45
|
+
validateId(id);
|
|
46
|
+
validateRoute(config.route);
|
|
47
|
+
const fullId = `${prefix}${id}`;
|
|
48
|
+
return attachRuntime({
|
|
49
|
+
type: "site",
|
|
50
|
+
id: fullId,
|
|
51
|
+
config,
|
|
52
|
+
url: `https://${config.route}`,
|
|
53
|
+
}, swarmConfig);
|
|
54
|
+
}
|
|
55
|
+
function postgres(id, config = {}) {
|
|
56
|
+
validateId(id);
|
|
57
|
+
const version = config.version ?? 18;
|
|
58
|
+
const mount = version >= 18 ? "/var/lib/postgresql" : "/var/lib/postgresql/data";
|
|
59
|
+
const password = secret(`${id}-password`, { length: 32 });
|
|
60
|
+
const vol = volume(`${id}-data`);
|
|
61
|
+
const svc = service(id, {
|
|
62
|
+
image: `postgres:${version}`,
|
|
63
|
+
port: 5432,
|
|
64
|
+
volumes: [{ volume: vol, mount }],
|
|
65
|
+
env: {
|
|
66
|
+
POSTGRES_PASSWORD: password,
|
|
67
|
+
},
|
|
68
|
+
healthCheck: {
|
|
69
|
+
command: ["pg_isready", "-U", "postgres"],
|
|
70
|
+
interval: "5s",
|
|
71
|
+
timeout: "5s",
|
|
72
|
+
retries: 5,
|
|
73
|
+
startPeriod: "10s",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
service: svc,
|
|
78
|
+
volume: vol,
|
|
79
|
+
password,
|
|
80
|
+
host: svc.host,
|
|
81
|
+
port: 5432,
|
|
82
|
+
connectionUrl: interpolate `postgres://postgres:${password}@${svc.host}:5432/postgres`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { volume, service, secret, site, postgres };
|
|
56
86
|
}
|
package/dist/swarm/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { createFactories } from "./factories.js";
|
|
2
|
-
export type { DriverVolumeOptions, StorageDriver, SwarmConfig, SwarmServiceConfig, SwarmVolumeConfig, } from "./types.js";
|
|
2
|
+
export type { DriverVolumeOptions, Postgres, PostgresConfig, StorageDriver, SwarmConfig, SwarmServiceConfig, SwarmVolumeConfig, } from "./types.js";
|
|
3
3
|
import type { Secret, SecretConfig, Service, Site, SiteConfig, Volume } from "../resource.js";
|
|
4
|
-
import type { StorageDriver, SwarmConfig, SwarmServiceConfig, SwarmVolumeConfig } from "./types.js";
|
|
4
|
+
import type { Postgres, PostgresConfig, StorageDriver, SwarmConfig, SwarmServiceConfig, SwarmVolumeConfig } from "./types.js";
|
|
5
5
|
export declare function swarm<D extends StorageDriver = "local">(config?: SwarmConfig<D>): {
|
|
6
6
|
volume: (id: string, config?: SwarmVolumeConfig<D>) => Volume;
|
|
7
7
|
service: (id: string, config: SwarmServiceConfig) => Service;
|
|
8
8
|
secret: (id: string, config?: SecretConfig) => Secret;
|
|
9
9
|
site: (id: string, config: SiteConfig) => Site;
|
|
10
|
+
postgres: (id: string, config?: PostgresConfig) => Postgres;
|
|
10
11
|
};
|
package/dist/swarm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HealthCheckConfig, ResourceLimits, ServiceConfig, VolumeConfig } from "../resource.js";
|
|
1
|
+
import type { HealthCheckConfig, Interpolation, ResourceLimits, Secret, Service, ServiceConfig, Volume, VolumeConfig } from "../resource.js";
|
|
2
2
|
export interface DriverVolumeOptions {
|
|
3
3
|
local: {
|
|
4
4
|
size?: string;
|
|
@@ -23,3 +23,14 @@ export interface SwarmServiceConfig extends ServiceConfig {
|
|
|
23
23
|
resources?: ResourceLimits;
|
|
24
24
|
restartPolicy?: "none" | "on-failure" | "any";
|
|
25
25
|
}
|
|
26
|
+
export interface PostgresConfig {
|
|
27
|
+
version?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface Postgres {
|
|
30
|
+
service: Service;
|
|
31
|
+
volume: Volume;
|
|
32
|
+
password: Secret;
|
|
33
|
+
host: string;
|
|
34
|
+
port: number;
|
|
35
|
+
connectionUrl: Interpolation;
|
|
36
|
+
}
|