@kaupang/core 0.1.0

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.
@@ -0,0 +1,208 @@
1
+ type BackendName = "compose" | "swarm" | "kubernetes";
2
+ /** Maps to Docker Compose pull_policy / Swarm --resolve-image. */
3
+ type PullPolicy = "always" | "missing" | "never";
4
+ /** A value that should never be persisted — emitted as a runtime reference. */
5
+ interface SecretRef {
6
+ /** Name of the host/pipeline env var to read the value from at deploy time. */
7
+ readonly $secret: string;
8
+ }
9
+ /** An env value: a literal string, or a `secret()` reference. */
10
+ type EnvValue = string | SecretRef;
11
+ /** A map of env vars whose values may be literals or secret references. */
12
+ type EnvMap = Record<string, EnvValue>;
13
+ interface BuildConfig {
14
+ context: string;
15
+ dockerfile?: string;
16
+ args?: Record<string, string>;
17
+ }
18
+ interface HealthcheckConfig {
19
+ /** e.g. "curl -f http://localhost/health" or ["CMD", "pg_isready"] */
20
+ test: string | string[];
21
+ interval?: string;
22
+ timeout?: string;
23
+ retries?: number;
24
+ startPeriod?: string;
25
+ }
26
+ /**
27
+ * Normalized service — what backends consume. Authoring uses `ServiceInput`
28
+ * (below), which the loader normalizes into this shape: image prefixed with the
29
+ * docker repository, `dependsOn` coerced to an array, pull policy filled in.
30
+ */
31
+ interface ServiceDefinition {
32
+ image?: string;
33
+ build?: string | BuildConfig;
34
+ command?: string | string[];
35
+ ports?: string[];
36
+ env?: EnvMap;
37
+ volumes?: string[];
38
+ /** Other services in the same environment that must start first (normalized). */
39
+ dependsOn?: string[];
40
+ replicas?: number;
41
+ restart?: "no" | "always" | "on-failure" | "unless-stopped";
42
+ labels?: Record<string, string>;
43
+ networks?: string[];
44
+ healthcheck?: HealthcheckConfig;
45
+ /** Pull behavior for this service's image. */
46
+ pull?: PullPolicy;
47
+ /**
48
+ * A run-to-completion job (e.g. migrations / seed): it runs once and exits 0.
49
+ * Implies `restart: "no"`, and dependents that list it in `dependsOn` wait for it
50
+ * to finish successfully (compose `condition: service_completed_successfully`) so
51
+ * `compose up --wait` doesn't treat its exit as a failure. (Compose backend; swarm
52
+ * just won't restart it, and the minimal k8s backend ignores it.)
53
+ */
54
+ runOnce?: boolean;
55
+ }
56
+ /** "foo" | ["foo", "bar"] — coerced to an array during normalization. */
57
+ type Dependable = string | string[];
58
+ /** A service spec as authored: like ServiceDefinition but `dependsOn` is loose. */
59
+ interface ServiceSpec extends Omit<ServiceDefinition, "dependsOn"> {
60
+ dependsOn?: Dependable;
61
+ }
62
+ /** Reference to a catalog preset, produced by `use(name, overrides?)`. */
63
+ interface CatalogRef {
64
+ $catalog: string;
65
+ overrides?: Partial<ServiceSpec>;
66
+ }
67
+ /**
68
+ * How you may declare a service:
69
+ * - a string -> shorthand for `{ image: "<string>" }`
70
+ * - a spec -> full object
71
+ * - use(name) -> a catalog preset
72
+ */
73
+ type ServiceInput = string | ServiceSpec | CatalogRef;
74
+ /** A hook command: a shell string, or an object with cwd/env. */
75
+ type HookCommand = string | {
76
+ run: string;
77
+ cwd?: string;
78
+ env?: Record<string, string>;
79
+ };
80
+ interface Hooks {
81
+ beforeUp?: HookCommand[];
82
+ afterUp?: HookCommand[];
83
+ beforeDown?: HookCommand[];
84
+ afterDown?: HookCommand[];
85
+ }
86
+ interface EnvironmentDefinition {
87
+ /** Unique name. Defaults to the file (or folder) name when omitted. */
88
+ name?: string;
89
+ /** Services that make up this environment (string / spec / catalog ref). */
90
+ services: Record<string, ServiceInput>;
91
+ /** Other environments that must be up first (string or array). */
92
+ dependsOn?: Dependable;
93
+ /** Environment-scoped variables (over globalEnv, under service env). */
94
+ env?: EnvMap;
95
+ /** Image prefix for services in this environment (overrides config.dockerRepository). */
96
+ dockerRepository?: string;
97
+ /** Default pull policy for this environment's services. */
98
+ pull?: PullPolicy;
99
+ /** Lifecycle hooks run around up/down. */
100
+ hooks?: Hooks;
101
+ networks?: string[];
102
+ volumes?: string[];
103
+ }
104
+ interface CatalogSourceConfig {
105
+ /**
106
+ * - "file": a JSON manifest on disk (`path`)
107
+ * - "http": a JSON manifest over HTTP (`url`, optional `headers`)
108
+ * - "oci": an OCI artifact (`ref`, e.g. "ghcr.io/acme/kaupang-catalog:1") [planned]
109
+ * - "service": a running catalog service kaupang queries (`url`) [planned]
110
+ */
111
+ type: "file" | "http" | "oci" | "service";
112
+ path?: string;
113
+ url?: string;
114
+ ref?: string;
115
+ headers?: Record<string, string>;
116
+ }
117
+ interface CatalogConfig {
118
+ sources: CatalogSourceConfig[];
119
+ }
120
+ /** A named place kaupang deploys to (a cluster, a remote host, or local). */
121
+ interface TargetConfig {
122
+ /** Default backend for this target (e.g. staging: swarm, prod: kubernetes). */
123
+ backend?: BackendName;
124
+ /** Default pull policy for this target. */
125
+ pull?: PullPolicy;
126
+ /** Env merged over globalEnv + environment env, under service env. */
127
+ env?: EnvMap;
128
+ /** docker context name → spawned as `docker --context <name> …` (compose/swarm). */
129
+ dockerContext?: string;
130
+ /** Explicit DOCKER_HOST (e.g. "ssh://deploy@host", "tcp://10.0.0.5:2375"). */
131
+ dockerHost?: string;
132
+ /** kube context name → spawned as `kubectl --context <name> …`. */
133
+ kubeContext?: string;
134
+ /** Path to a kubeconfig (relative to the config file); sets KUBECONFIG. */
135
+ kubeconfig?: string;
136
+ }
137
+ /** A named, versioned composition of environments — what a pipeline bundles. */
138
+ interface SolutionRecipe {
139
+ /** Optional version label, recorded for reproducibility/audit. */
140
+ version?: string;
141
+ /** Top-level environments this solution deploys (their deps are pulled in). */
142
+ environments: string[];
143
+ /** Per-service image overrides, keyed by "environment.service". */
144
+ pins?: Record<string, string>;
145
+ /** Env overlay applied across the solution (above target env). */
146
+ env?: EnvMap;
147
+ /** Default target for this solution. */
148
+ target?: string;
149
+ }
150
+ /** A wait condition for a pipeline `wait` step. */
151
+ interface WaitSpec {
152
+ /** Poll this URL until it returns `status` (default 200) or `timeout` elapses. */
153
+ http?: string;
154
+ status?: number;
155
+ /** Poll interval, e.g. "2s". Default "2s". */
156
+ interval?: string;
157
+ /** Give up after this, e.g. "60s" / "2m". Default "60s". */
158
+ timeout?: string;
159
+ /** Or simply sleep this many seconds. */
160
+ seconds?: number;
161
+ }
162
+ /** One node in a pipeline DAG. Exactly one action key must be set. */
163
+ interface PipelineStep {
164
+ /** Steps that must finish before this one. */
165
+ needs?: Dependable;
166
+ /** Run a shell command. */
167
+ run?: HookCommand;
168
+ /** Deploy an environment (like `kaupang up <env>`). */
169
+ up?: string;
170
+ /** Tear an environment down. */
171
+ down?: string;
172
+ /** Build images for an environment. */
173
+ build?: string;
174
+ /** Wait for a condition. */
175
+ wait?: WaitSpec;
176
+ /** Per-step target/backend overrides for up/down/build. */
177
+ target?: string;
178
+ backend?: BackendName;
179
+ }
180
+ interface Pipeline {
181
+ steps: Record<string, PipelineStep>;
182
+ }
183
+ interface KaupangConfig {
184
+ /** Folder (relative to the config file) holding one environment per file. */
185
+ environments: string;
186
+ /** Variables injected into every service of every environment (lowest priority). */
187
+ globalEnv?: EnvMap;
188
+ /** Backend used when `--backend` is not passed. Defaults to "compose". */
189
+ defaultBackend?: BackendName;
190
+ /** Cache directory. Defaults to ".kaupang". */
191
+ cacheDir?: string;
192
+ /** Project name used to namespace stacks / compose projects / k8s namespaces. */
193
+ project?: string;
194
+ /** Image prefix applied to bare image names (e.g. "ghcr.io/acme"). */
195
+ dockerRepository?: string;
196
+ /** Default pull policy for all services unless overridden. */
197
+ defaultPull?: PullPolicy;
198
+ /** Where to resolve catalog presets from. */
199
+ catalog?: CatalogConfig;
200
+ /** Named deployment targets (clusters / remote hosts). "local" is implicit. */
201
+ targets?: Record<string, TargetConfig>;
202
+ /** Inline solution recipes (also resolvable from the catalog). */
203
+ solutions?: Record<string, SolutionRecipe>;
204
+ /** Named pipelines: ordered run / up / down / build / wait steps. */
205
+ pipelines?: Record<string, Pipeline>;
206
+ }
207
+
208
+ export type { BackendName as B, CatalogRef as C, Dependable as D, EnvironmentDefinition as E, HealthcheckConfig as H, KaupangConfig as K, Pipeline as P, ServiceSpec as S, TargetConfig as T, WaitSpec as W, SolutionRecipe as a, SecretRef as b, BuildConfig as c, CatalogConfig as d, CatalogSourceConfig as e, EnvMap as f, EnvValue as g, HookCommand as h, Hooks as i, PipelineStep as j, PullPolicy as k, ServiceDefinition as l, ServiceInput as m };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@kaupang/core",
3
+ "version": "0.1.0",
4
+ "description": "kaupang's engine + config-authoring API (defineConfig/defineEnvironment/secret/use + types). The CLI lives in @kaupang/cli.",
5
+ "license": "MIT",
6
+ "author": "Andreas Quist Batista",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/kaupang-dev/kaupang.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/kaupang-dev/kaupang/issues"
14
+ },
15
+ "homepage": "https://github.com/kaupang-dev/kaupang#readme",
16
+ "type": "module",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./internal": {
26
+ "types": "./dist/internal.d.ts",
27
+ "import": "./dist/internal.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest run",
37
+ "coverage": "vitest run --coverage",
38
+ "prepublishOnly": "npm run build"
39
+ },
40
+ "dependencies": {
41
+ "consola": "3.4.0",
42
+ "execa": "9.5.2",
43
+ "jiti": "2.4.2",
44
+ "tar": "7.5.16",
45
+ "yaml": "2.7.0"
46
+ },
47
+ "engines": {
48
+ "node": ">=18"
49
+ }
50
+ }