@fabrika/provider-zerops 0.9.0-dev.1 → 0.9.0-dev.10
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/package.json +17 -14
- package/sandbox/Dockerfile +16 -0
- package/sandbox/bin/postgres-auth.sh +38 -0
- package/sandbox/bin/reset.sh +12 -0
- package/sandbox/bin/run-build.sh +35 -0
- package/sandbox/bin/run-launcher.sh +18 -0
- package/sandbox/bin/start-launcher.sh +25 -0
- package/sandbox/bin/stop.sh +47 -0
- package/sandbox/init.sh +61 -0
- package/src/api/client.ts +15 -1
- package/src/api/errors.ts +7 -3
- package/src/api/readers.ts +29 -0
- package/src/api/types.ts +52 -0
- package/src/api.ts +2 -0
- package/src/cli.ts +11 -0
- package/src/collaborators.ts +0 -14
- package/src/compile.ts +1 -1
- package/src/control.ts +159 -92
- package/src/execution.ts +45 -195
- package/src/index.ts +2 -0
- package/src/installation/admin.ts +1 -1
- package/src/installation/deploy-options.ts +1 -2
- package/src/installation/deploy.ts +225 -80
- package/src/installation/generated/platform-console-schema.ts +3 -0
- package/src/installation/generated/platform-proxy-manifest.ts +1 -1
- package/src/installation/guide.md +48 -18
- package/src/installation/hosts.ts +1 -7
- package/src/installation/index.ts +13 -16
- package/src/installation/init-options.ts +2 -1
- package/src/installation/install-environment.ts +47 -108
- package/src/installation/install-options.ts +3 -1
- package/src/installation/install-secrets.ts +24 -68
- package/src/installation/install.ts +9 -4
- package/src/installation/sidecar.ts +5 -26
- package/src/installation/topology/setups.ts +17 -4
- package/src/installation/topology/topology.ts +32 -22
- package/src/installation/upgrade-options.ts +2 -2
- package/src/managed-env.ts +1 -174
- package/src/manifest.ts +4 -16
- package/src/namespace/claims.ts +60 -1
- package/src/namespace/codec.ts +17 -0
- package/src/namespace/errors.ts +22 -1
- package/src/namespace/manifest.ts +36 -23
- package/src/namespace/provisioning.ts +88 -114
- package/src/namespace/proxy-attempt.ts +14 -2
- package/src/namespace/proxy-reads.ts +28 -23
- package/src/namespace/proxy-secrets.ts +18 -5
- package/src/namespace/sandbox-host.ts +212 -0
- package/src/namespace/subdomain.ts +113 -0
- package/src/namespace/topology.ts +1 -1
- package/src/namespace/types.ts +13 -0
- package/src/namespace/update.ts +1 -0
- package/src/namespace-cli.ts +152 -0
- package/src/plan.ts +1 -6
- package/src/provider.ts +88 -166
- package/src/proxy-manifest-carrier.ts +39 -0
- package/src/sandbox/base-image.ts +100 -0
- package/src/sandbox/constants.ts +44 -0
- package/src/sandbox/deploy.ts +471 -0
- package/src/sandbox/dev-artifact.ts +206 -0
- package/src/sandbox/lifecycle.ts +204 -0
- package/src/sandbox/scripts.ts +26 -0
- package/src/sandbox-host.ts +28 -0
- package/src/source/port.ts +5 -0
- package/src/types.ts +0 -2
- package/src/zbox/client.ts +259 -0
- package/src/zbox/errors.ts +45 -0
- package/src/zbox/index.ts +22 -0
- package/src/zbox/types.ts +165 -0
- package/types/src/api/client.d.ts +5 -0
- package/types/src/api/errors.d.ts +26 -0
- package/types/src/api/polling.d.ts +41 -0
- package/types/src/api/readers.d.ts +1115 -0
- package/types/src/api/service-env-limit.d.ts +17 -0
- package/types/src/api/service-env-response.d.ts +23 -0
- package/types/src/api/types.d.ts +687 -0
- package/types/src/api.d.ts +6 -0
- package/types/src/authoring.d.ts +9 -0
- package/types/src/cli-args.d.ts +19 -0
- package/types/src/cli.d.ts +13 -0
- package/types/src/collaborators.d.ts +16 -0
- package/types/src/compile.d.ts +91 -0
- package/types/src/control.d.ts +51 -0
- package/types/src/database-budget.d.ts +38 -0
- package/types/src/descriptor.d.ts +28 -0
- package/types/src/execution.d.ts +114 -0
- package/types/src/exposure.d.ts +47 -0
- package/types/src/index.d.ts +31 -0
- package/types/src/installation/admin-options.d.ts +24 -0
- package/types/src/installation/admin.d.ts +35 -0
- package/types/src/installation/checker-release.d.ts +12 -0
- package/types/src/installation/deploy-options.d.ts +37 -0
- package/types/src/installation/deploy.d.ts +136 -0
- package/types/src/installation/generated/platform-console-schema.d.ts +2 -0
- package/types/src/installation/generated/platform-proxy-manifest.d.ts +2 -0
- package/types/src/installation/hosts.d.ts +34 -0
- package/types/src/installation/index.d.ts +7 -0
- package/types/src/installation/init-options.d.ts +38 -0
- package/types/src/installation/init.d.ts +60 -0
- package/types/src/installation/install-collaborators.d.ts +24 -0
- package/types/src/installation/install-environment.d.ts +63 -0
- package/types/src/installation/install-options.d.ts +49 -0
- package/types/src/installation/install-project.d.ts +13 -0
- package/types/src/installation/install-provisioning.d.ts +58 -0
- package/types/src/installation/install-secrets.d.ts +17 -0
- package/types/src/installation/install-token.d.ts +10 -0
- package/types/src/installation/install.d.ts +23 -0
- package/types/src/installation/installation-source.d.ts +8 -0
- package/types/src/installation/log.d.ts +44 -0
- package/types/src/installation/machine-key.d.ts +19 -0
- package/types/src/installation/placement-options.d.ts +11 -0
- package/types/src/installation/platform-archive.d.ts +7 -0
- package/types/src/installation/platform-source.d.ts +8 -0
- package/types/src/installation/platform-upload.d.ts +3 -0
- package/types/src/installation/sidecar.d.ts +49 -0
- package/types/src/installation/source-options.d.ts +1 -0
- package/types/src/installation/topology/artifacts.d.ts +8 -0
- package/types/src/installation/topology/index.d.ts +5 -0
- package/types/src/installation/topology/installation-schemas.d.ts +2242 -0
- package/types/src/installation/topology/invariants.d.ts +23 -0
- package/types/src/installation/topology/setups.d.ts +59 -0
- package/types/src/installation/topology/topology.d.ts +153 -0
- package/types/src/installation/topology/validate.d.ts +11 -0
- package/types/src/installation/upgrade-options.d.ts +26 -0
- package/types/src/installation/upgrade-output.d.ts +6 -0
- package/types/src/installation/upgrade.d.ts +88 -0
- package/types/src/managed-env.d.ts +24 -0
- package/types/src/manifest.d.ts +199 -0
- package/types/src/namespace/claims.d.ts +16 -0
- package/types/src/namespace/codec.d.ts +352 -0
- package/types/src/namespace/constants.d.ts +25 -0
- package/types/src/namespace/errors.d.ts +25 -0
- package/types/src/namespace/manifest.d.ts +4 -0
- package/types/src/namespace/operator.d.ts +12 -0
- package/types/src/namespace/provisioning.d.ts +4 -0
- package/types/src/namespace/proxy-attempt.d.ts +39 -0
- package/types/src/namespace/proxy-reads.d.ts +27 -0
- package/types/src/namespace/proxy-secrets.d.ts +8 -0
- package/types/src/namespace/proxy-source.d.ts +74 -0
- package/types/src/namespace/sandbox-host.d.ts +23 -0
- package/types/src/namespace/subdomain.d.ts +43 -0
- package/types/src/namespace/topology.d.ts +9 -0
- package/types/src/namespace/types.d.ts +111 -0
- package/types/src/namespace/update.d.ts +6 -0
- package/types/src/namespace/validation.d.ts +12 -0
- package/types/src/namespace-cli.d.ts +2 -0
- package/types/src/namespace.d.ts +9 -0
- package/types/src/plan.d.ts +11 -0
- package/types/src/provider.d.ts +60 -0
- package/types/src/proxy-manifest-carrier.d.ts +37 -0
- package/types/src/sandbox/base-image.d.ts +28 -0
- package/types/src/sandbox/constants.d.ts +30 -0
- package/types/src/sandbox/deploy.d.ts +75 -0
- package/types/src/sandbox/dev-artifact.d.ts +51 -0
- package/types/src/sandbox/lifecycle.d.ts +27 -0
- package/types/src/sandbox/scripts.d.ts +11 -0
- package/types/src/sandbox-host.d.ts +16 -0
- package/types/src/schema.generated.d.ts +376 -0
- package/types/src/service-names.d.ts +4 -0
- package/types/src/service-references.d.ts +13 -0
- package/types/src/source/constants.d.ts +6 -0
- package/types/src/source/port.d.ts +65 -0
- package/types/src/source/types.d.ts +4 -0
- package/types/src/source/validation.d.ts +19 -0
- package/types/src/source.d.ts +2 -0
- package/types/src/types.d.ts +119 -0
- package/types/src/version-attempt.d.ts +8 -0
- package/types/src/zbox/client.d.ts +2 -0
- package/types/src/zbox/errors.d.ts +25 -0
- package/types/src/zbox/index.d.ts +3 -0
- package/types/src/zbox/types.d.ts +433 -0
- package/src/installation/mcp.ts +0 -102
- package/src/installation/proxy-manifest.ts +0 -214
- package/src/installation/secrets.ts +0 -78
package/src/control.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { appEnvironmentId } from '@fabrika/auth-core'
|
|
2
1
|
import type {
|
|
3
2
|
ControlProvider,
|
|
4
3
|
JsonValue,
|
|
@@ -8,7 +7,6 @@ import type {
|
|
|
8
7
|
ProviderDeployInput,
|
|
9
8
|
ProviderDeploymentNamespace,
|
|
10
9
|
ProviderDeployOutcome,
|
|
11
|
-
ProviderDevEnvironmentInput,
|
|
12
10
|
ProviderEnvelope,
|
|
13
11
|
ProviderEnvironment,
|
|
14
12
|
ProviderReconcileOutcome,
|
|
@@ -17,7 +15,6 @@ import type {
|
|
|
17
15
|
ProviderSourceBinding,
|
|
18
16
|
ProviderSourceResolution,
|
|
19
17
|
ProviderSourceResolutionInput,
|
|
20
|
-
SchemaReconciler,
|
|
21
18
|
} from '@fabrika/provider-contract'
|
|
22
19
|
import { decodeEnvelope, ProviderSecretError } from '@fabrika/provider-contract'
|
|
23
20
|
import { z } from 'zod'
|
|
@@ -32,9 +29,8 @@ import {
|
|
|
32
29
|
} from './api'
|
|
33
30
|
import { defaultSleep, defaultZeropsCollaborators, type Sleeper } from './collaborators'
|
|
34
31
|
import { createdServices, type ExposureAlerter, isObjectStorageType } from './exposure'
|
|
35
|
-
import { assertAuthoredManagedInputs, assertAuthoredManagedName, assertNoFrameworkReference
|
|
32
|
+
import { assertAuthoredManagedInputs, assertAuthoredManagedName, assertNoFrameworkReference } from './managed-env'
|
|
36
33
|
import {
|
|
37
|
-
approvedSchemaOf,
|
|
38
34
|
assertFabrikaManifestCoordinates,
|
|
39
35
|
type FabrikaManifest,
|
|
40
36
|
manifestServiceHostnames,
|
|
@@ -49,16 +45,25 @@ import {
|
|
|
49
45
|
type ZeropsNamespaceTarget,
|
|
50
46
|
zeropsNamespaceTargetCodec,
|
|
51
47
|
} from './namespace'
|
|
52
|
-
import {
|
|
48
|
+
import { namespaceError, ZEROPS_DEV_TARGET_RETIRED } from './namespace/errors'
|
|
49
|
+
import { assertNamespaceProxyAcceptsSandboxes, assertNamespaceProxyReads, type OlderProxyReaders } from './namespace/proxy-reads'
|
|
50
|
+
import type { ZeropsNamespaceSandboxHost } from './namespace/types'
|
|
53
51
|
import { createZeropsDeployer, ZEROPS_VERSION_DEADLINE_MS } from './provider'
|
|
52
|
+
import { deploySandbox, parseSandboxCheckpoint } from './sandbox/deploy'
|
|
53
|
+
import { assertSandboxArtifact } from './sandbox/dev-artifact'
|
|
54
|
+
import { createZeropsDevSandboxes } from './sandbox/lifecycle'
|
|
54
55
|
import { allowedReferenceHosts, assertNoPlatformOnlyReference, foreignReferenceHost, serviceReferenceHosts } from './service-references'
|
|
55
56
|
import { normalizeZeropsSourceRepository } from './source'
|
|
56
57
|
import type { ZeropsSourcePort, ZeropsSourcePrivateBinding } from './source/port'
|
|
57
58
|
import type { ZeropsRunState, ZeropsRuntimeTarget } from './types'
|
|
58
59
|
import { deleteVersion, isVersionNotFound } from './version-attempt'
|
|
60
|
+
import { createZboxClient, type ZboxClient, type ZboxFetch } from './zbox'
|
|
59
61
|
|
|
60
62
|
/** Provider coordinates that are safe to persist. Credentials are composed only for a live run. */
|
|
61
|
-
export
|
|
63
|
+
export type ZeropsStoredTarget = ZeropsServiceTarget | ZeropsDevSandboxesTarget
|
|
64
|
+
|
|
65
|
+
/** An environment served by its own Zerops service. */
|
|
66
|
+
export interface ZeropsServiceTarget {
|
|
62
67
|
serviceId: string
|
|
63
68
|
/**
|
|
64
69
|
* The object-storage service ids the first registration's collision-refusing import created: the creation evidence
|
|
@@ -67,14 +72,26 @@ export interface ZeropsStoredTarget {
|
|
|
67
72
|
createdBuckets?: string[]
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
/** A `dev` environment: it has no service, and each MCP workspace runs in a sandbox of the namespace's sandbox host. */
|
|
76
|
+
export interface ZeropsDevSandboxesTarget {
|
|
77
|
+
kind: 'devSandboxes'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const storedTargetSchema = z.union([
|
|
81
|
+
z.object({ kind: z.literal('devSandboxes') }).strict(),
|
|
82
|
+
z.object({ serviceId: z.string().min(1), createdBuckets: z.array(z.string().min(1)).min(1).optional() }),
|
|
83
|
+
])
|
|
71
84
|
|
|
85
|
+
// The dev variant is additive: every stored service target still reads as it did, so the version stays.
|
|
72
86
|
export const zeropsStoredTargetCodec: ProviderCodec<ZeropsStoredTarget> = {
|
|
73
87
|
version: 2,
|
|
74
|
-
encode: (target) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
88
|
+
encode: (target): JsonValue => {
|
|
89
|
+
if ('kind' in target) return { kind: target.kind }
|
|
90
|
+
return {
|
|
91
|
+
serviceId: target.serviceId,
|
|
92
|
+
...(target.createdBuckets === undefined ? {} : { createdBuckets: [...target.createdBuckets] }),
|
|
93
|
+
}
|
|
94
|
+
},
|
|
78
95
|
decode: (payload) => {
|
|
79
96
|
const result = storedTargetSchema.safeParse(payload)
|
|
80
97
|
if (!result.success) throw new Error('Zerops stored target serviceId must be a non-empty string')
|
|
@@ -82,6 +99,12 @@ export const zeropsStoredTargetCodec: ProviderCodec<ZeropsStoredTarget> = {
|
|
|
82
99
|
},
|
|
83
100
|
}
|
|
84
101
|
|
|
102
|
+
/** The service of a target that has one; a dev environment's sandboxes are not one. */
|
|
103
|
+
const serviceTargetOf = (target: ZeropsStoredTarget): ZeropsServiceTarget => {
|
|
104
|
+
if ('kind' in target) throw new Error('zerops: a dev environment runs in workspace sandboxes and has no Zerops service')
|
|
105
|
+
return target
|
|
106
|
+
}
|
|
107
|
+
|
|
85
108
|
const envelope = <T>(codec: ProviderCodec<T>, value: T): ProviderEnvelope => ({
|
|
86
109
|
provider: 'zerops',
|
|
87
110
|
version: codec.version,
|
|
@@ -91,11 +114,8 @@ const envelope = <T>(codec: ProviderCodec<T>, value: T): ProviderEnvelope => ({
|
|
|
91
114
|
export interface ZeropsControlProviderOptions {
|
|
92
115
|
readonly accessToken: string
|
|
93
116
|
readonly apiBaseUrl?: string
|
|
94
|
-
readonly propustkaUrl?: string
|
|
95
|
-
readonly adminKey?: string
|
|
96
117
|
readonly api?: ZeropsApi
|
|
97
118
|
readonly source: ZeropsSourcePort
|
|
98
|
-
readonly reconcileSchema?: SchemaReconciler
|
|
99
119
|
readonly alertExposure?: ExposureAlerter
|
|
100
120
|
readonly sleep?: Sleeper
|
|
101
121
|
readonly namespaces?: {
|
|
@@ -103,9 +123,15 @@ export interface ZeropsControlProviderOptions {
|
|
|
103
123
|
readonly proxySource: ZeropsNamespaceProxySource
|
|
104
124
|
readonly iamUrl: string
|
|
105
125
|
readonly iamKey: string
|
|
126
|
+
/** The installation's own project, which no namespace may adopt. */
|
|
127
|
+
readonly installationProjectId?: string
|
|
106
128
|
/** The manifest parsers of the older releases' proxies, which a namespace pinned to an older source may run. */
|
|
107
129
|
readonly olderProxies: OlderProxyReaders
|
|
108
130
|
}
|
|
131
|
+
/** The transport of the sandbox host API; tests pass a fake. */
|
|
132
|
+
readonly zboxFetch?: ZboxFetch
|
|
133
|
+
/** Where a provider event outside a run is reported (a dev sandbox replaced); the process's stderr by default. */
|
|
134
|
+
readonly log?: (line: string) => void
|
|
109
135
|
}
|
|
110
136
|
|
|
111
137
|
interface DecodedZeropsEnvironment {
|
|
@@ -227,7 +253,6 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
227
253
|
return {
|
|
228
254
|
api,
|
|
229
255
|
source: options.source,
|
|
230
|
-
reconcileSchema: options.reconcileSchema ?? defaults.reconcileSchema,
|
|
231
256
|
alertExposure: options.alertExposure ?? defaults.alertExposure,
|
|
232
257
|
sleep: options.sleep ?? defaultSleep,
|
|
233
258
|
}
|
|
@@ -261,36 +286,8 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
261
286
|
}
|
|
262
287
|
}
|
|
263
288
|
|
|
264
|
-
const reconcileActiveSchema = async (
|
|
265
|
-
input: { environment: ProviderEnvironment; returnOrigins?: readonly string[] },
|
|
266
|
-
signal: AbortSignal,
|
|
267
|
-
): Promise<void> => {
|
|
268
|
-
const artifact = artifactFor(input.environment)
|
|
269
|
-
const schema = approvedSchemaOf(input.environment)
|
|
270
|
-
if (schema === undefined || options.propustkaUrl === undefined) return
|
|
271
|
-
const placement = resolvedEnvironment(input.environment, { requireReady: false })
|
|
272
|
-
const runtimeTarget: ZeropsRuntimeTarget = {
|
|
273
|
-
projectId: placement.projectId,
|
|
274
|
-
serviceId: placement.target.serviceId,
|
|
275
|
-
accessToken: options.accessToken,
|
|
276
|
-
...(options.apiBaseUrl !== undefined ? { apiBaseUrl: options.apiBaseUrl } : {}),
|
|
277
|
-
propustkaUrl: options.propustkaUrl,
|
|
278
|
-
...(options.adminKey !== undefined ? { adminKey: options.adminKey } : {}),
|
|
279
|
-
}
|
|
280
|
-
const reconcileSchema = options.reconcileSchema ?? defaultZeropsCollaborators(runtimeTarget).reconcileSchema
|
|
281
|
-
signal.throwIfAborted()
|
|
282
|
-
await reconcileSchema({
|
|
283
|
-
url: options.propustkaUrl,
|
|
284
|
-
app: appEnvironmentId(artifact.app.id, artifact.app.env),
|
|
285
|
-
schema,
|
|
286
|
-
...(input.returnOrigins === undefined || input.returnOrigins.length === 0 ? {} : { returnOrigins: input.returnOrigins }),
|
|
287
|
-
adminKey: options.adminKey,
|
|
288
|
-
signal,
|
|
289
|
-
})
|
|
290
|
-
}
|
|
291
|
-
|
|
292
289
|
const assertVersionCoordinates = (environment: ProviderEnvironment, appVersionId: string, version: ZeropsAppVersion): void => {
|
|
293
|
-
const serviceId = decodeEnvironment(environment).target.serviceId
|
|
290
|
+
const serviceId = serviceTargetOf(decodeEnvironment(environment).target).serviceId
|
|
294
291
|
if (version.id !== appVersionId || (version.serviceStackId !== undefined && version.serviceStackId !== serviceId)) {
|
|
295
292
|
throw new Error('Zerops app-version response has different coordinates')
|
|
296
293
|
}
|
|
@@ -323,29 +320,66 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
323
320
|
return { commitSha: result.commitSha }
|
|
324
321
|
}
|
|
325
322
|
|
|
326
|
-
/**
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
323
|
+
/** The namespace's sandbox host, which runs the workspace sandboxes of its dev environment; null until it is created. */
|
|
324
|
+
const sandboxHostOf = (environment: ProviderEnvironment): ZeropsNamespaceSandboxHost | null => {
|
|
325
|
+
const { target, namespaceTarget } = decodeEnvironment(environment)
|
|
326
|
+
// An older release registered a dev environment as its own Zerops service; it never runs in a sandbox.
|
|
327
|
+
if (environment.kind === 'dev' && !('kind' in target)) {
|
|
328
|
+
throw namespaceError(
|
|
329
|
+
ZEROPS_DEV_TARGET_RETIRED,
|
|
330
|
+
`zerops: dev environment \`${environment.appId}/${environment.env}\` was registered with its own Zerops service, which this release `
|
|
331
|
+
+ 'no longer runs; delete the environment and register it again with --kind=dev and a wildcard domain',
|
|
332
|
+
false,
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
return namespaceTarget.sandboxHost ?? null
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const sandboxClient = (apiOrigin: string, sandboxKey: string): ZboxClient =>
|
|
339
|
+
createZboxClient({ baseUrl: apiOrigin, apiKey: sandboxKey, ...(options.zboxFetch === undefined ? {} : { fetch: options.zboxFetch }) })
|
|
340
|
+
|
|
341
|
+
const devSandboxes = createZeropsDevSandboxes({
|
|
342
|
+
client: (environment, sandboxKey) => {
|
|
343
|
+
const host = sandboxHostOf(environment)
|
|
344
|
+
return host === null ? null : sandboxClient(host.apiOrigin, sandboxKey)
|
|
345
|
+
},
|
|
346
|
+
admit: (environment) => {
|
|
347
|
+
sandboxHostOf(environment)
|
|
348
|
+
const { namespace, namespaceTarget } = decodeNamespace(environment)
|
|
349
|
+
assertNamespaceProxyAcceptsSandboxes(namespace.id, namespaceTarget.proxySource)
|
|
350
|
+
},
|
|
351
|
+
sleep: options.sleep ?? defaultSleep,
|
|
352
|
+
log: options.log ?? ((line) => console.warn(line)),
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A dev environment imports no service: each workspace gets a sandbox when it binds. What a sandbox cannot give the
|
|
357
|
+
* application is refused here, before anything is created.
|
|
358
|
+
*/
|
|
359
|
+
const prepareDevRegistration = (
|
|
360
|
+
registration: ProviderRegistration,
|
|
361
|
+
namespaceId: string,
|
|
362
|
+
namespaceTarget: ZeropsNamespaceTarget,
|
|
363
|
+
): ProviderRegistration => {
|
|
364
|
+
if (namespaceTarget.publicAccess === 'zerops-subdomain') {
|
|
365
|
+
throw new Error(
|
|
366
|
+
`zerops: a dev environment serves each workspace on its own host, so namespace \`${namespaceId}\` needs custom-domain public access`,
|
|
367
|
+
)
|
|
368
|
+
}
|
|
369
|
+
const manifest = decodeEnvelope('artifact', 'zerops', registration.environment.artifact, zeropsArtifactCodec)
|
|
370
|
+
assertFabrikaManifestCoordinates(manifest.app, { appId: registration.app.id, env: registration.environment.env })
|
|
371
|
+
assertSandboxArtifact(manifest)
|
|
372
|
+
return normalizeRegistration({
|
|
373
|
+
app: registration.app,
|
|
374
|
+
environment: { ...registration.environment, target: envelope(zeropsStoredTargetCodec, { kind: 'devSandboxes' }) },
|
|
343
375
|
})
|
|
344
376
|
}
|
|
345
377
|
|
|
346
378
|
const controlProvider: ControlProvider = {
|
|
347
379
|
id: 'zerops',
|
|
348
380
|
normalizeRegistration,
|
|
381
|
+
// The deploy reads `zerops.yaml` from the repository, so a workspace may not change it (ADR-0049 D6).
|
|
382
|
+
authoring: { protectedFiles: ['zerops.yaml', 'zerops.yml'] },
|
|
349
383
|
source: { binding: 'connection' },
|
|
350
384
|
/**
|
|
351
385
|
* A Zerops artifact IS the compiled manifest, so the declaration is right here and core can refuse
|
|
@@ -368,8 +402,6 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
368
402
|
deploy: async (input: ProviderDeployInput): Promise<ProviderDeployOutcome> => {
|
|
369
403
|
input.signal.throwIfAborted()
|
|
370
404
|
assertAuthoredManagedInputs({ variableNames: Object.keys(input.vars), secretNames: Object.keys(input.secrets) })
|
|
371
|
-
const handed = parseManagedEnvironment(input.managedEnvironment)
|
|
372
|
-
const managedEnvironment = { ...handed.values, ...handed.familyVariables }
|
|
373
405
|
const binding = privateBinding(input.sourceBinding)
|
|
374
406
|
assertEnvironmentOfApp(input.app, input.environment)
|
|
375
407
|
const placement = resolvedEnvironment(input.environment, { requireReady: true })
|
|
@@ -388,24 +420,57 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
388
420
|
...(binding === undefined ? {} : { privateBinding: binding }),
|
|
389
421
|
}
|
|
390
422
|
}
|
|
423
|
+
if (input.devSandbox !== undefined && input.environment.kind !== 'dev') {
|
|
424
|
+
throw new Error('zerops: only a dev environment deploys into a workspace sandbox')
|
|
425
|
+
}
|
|
426
|
+
if (input.environment.kind === 'dev') {
|
|
427
|
+
if (input.devSandbox === undefined) throw new Error('zerops: a dev environment deploys only into a workspace sandbox, through bind_dev')
|
|
428
|
+
const host = sandboxHostOf(input.environment)
|
|
429
|
+
if (host === null) throw new Error("zerops: the namespace's sandbox host is not created yet; bind the workspace again")
|
|
430
|
+
const result = await deploySandbox({
|
|
431
|
+
appId: input.app.id,
|
|
432
|
+
env: input.environment.env,
|
|
433
|
+
runId: input.runId,
|
|
434
|
+
artifact,
|
|
435
|
+
access: input.environment.access,
|
|
436
|
+
vars: input.vars,
|
|
437
|
+
secrets: input.secrets,
|
|
438
|
+
managedEnvironment: input.managedEnvironment,
|
|
439
|
+
...(source === undefined
|
|
440
|
+
? {}
|
|
441
|
+
: {
|
|
442
|
+
source: {
|
|
443
|
+
repository: source.repository,
|
|
444
|
+
commitSha: source.commitSha,
|
|
445
|
+
...(source.privateBinding === undefined ? {} : { privateBinding: source.privateBinding }),
|
|
446
|
+
},
|
|
447
|
+
}),
|
|
448
|
+
sandbox: { sandboxId: input.devSandbox.sandboxId, apiOrigin: host.apiOrigin, sandboxKey: input.devSandbox.sandboxKey },
|
|
449
|
+
client: sandboxClient(host.apiOrigin, input.devSandbox.sandboxKey),
|
|
450
|
+
sourcePort: options.source,
|
|
451
|
+
sleep: options.sleep ?? defaultSleep,
|
|
452
|
+
dryRun: input.dryRun,
|
|
453
|
+
signal: input.signal,
|
|
454
|
+
events: input.events,
|
|
455
|
+
})
|
|
456
|
+
input.signal.throwIfAborted()
|
|
457
|
+
return { state: result.status }
|
|
458
|
+
}
|
|
459
|
+
const serviceTarget = serviceTargetOf(placement.target)
|
|
391
460
|
const runtimeTarget: ZeropsRuntimeTarget = {
|
|
392
461
|
projectId: placement.projectId,
|
|
393
|
-
serviceId:
|
|
462
|
+
serviceId: serviceTarget.serviceId,
|
|
394
463
|
accessToken: options.accessToken,
|
|
395
|
-
...(
|
|
464
|
+
...(serviceTarget.createdBuckets === undefined ? {} : { createdBuckets: serviceTarget.createdBuckets }),
|
|
396
465
|
...(source === undefined ? {} : { source }),
|
|
397
466
|
...(options.apiBaseUrl !== undefined ? { apiBaseUrl: options.apiBaseUrl } : {}),
|
|
398
|
-
...(options.propustkaUrl !== undefined ? { propustkaUrl: options.propustkaUrl } : {}),
|
|
399
|
-
...(options.adminKey !== undefined ? { adminKey: options.adminKey } : {}),
|
|
400
467
|
}
|
|
401
468
|
const result = await deployRun({
|
|
402
469
|
appId: input.app.id,
|
|
403
470
|
env: input.environment.env,
|
|
404
|
-
...(input.environment.kind === 'dev' && source !== undefined ? { dev: { head: source.commitSha } } : {}),
|
|
405
|
-
...(input.returnOrigins === undefined ? {} : { returnOrigins: input.returnOrigins }),
|
|
406
471
|
secrets: input.secrets,
|
|
407
472
|
vars: input.vars,
|
|
408
|
-
managedEnvironment,
|
|
473
|
+
managedEnvironment: input.managedEnvironment,
|
|
409
474
|
target: runtimeTarget,
|
|
410
475
|
artifact,
|
|
411
476
|
...(input.environment.access === undefined ? {} : { access: input.environment.access }),
|
|
@@ -417,13 +482,12 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
417
482
|
input.signal.throwIfAborted()
|
|
418
483
|
return { state: result.status, ...(result.artifactState === undefined ? {} : { artifactState: result.artifactState }) }
|
|
419
484
|
},
|
|
420
|
-
|
|
421
|
-
stop: (input) => runningState(input, 'stop'),
|
|
422
|
-
start: (input) => runningState(input, 'start'),
|
|
423
|
-
},
|
|
485
|
+
devSandboxes,
|
|
424
486
|
cancel: async (input): Promise<ProviderCancelOutcome> => {
|
|
425
487
|
const signal = input.signal
|
|
426
488
|
signal.throwIfAborted()
|
|
489
|
+
// The deploy's own invocation stops a sandbox build on a cancel; nothing here holds the sandbox host's key.
|
|
490
|
+
if (parseSandboxCheckpoint(input) !== null) return { state: 'settled', outcome: 'failed' }
|
|
427
491
|
const checkpoint = runCheckpoint(input)
|
|
428
492
|
if (checkpoint === null) return { state: 'settled', outcome: 'failed' }
|
|
429
493
|
if (!checkpoint.triggered) {
|
|
@@ -438,17 +502,8 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
438
502
|
const version = await getVersion({ appVersionId: checkpoint.appVersionId, signal })
|
|
439
503
|
if (version === null) return { state: 'settled', outcome: 'failed' }
|
|
440
504
|
assertVersionCoordinates(input.environment, checkpoint.appVersionId, version)
|
|
441
|
-
// Cancellation never implies rollback: a version that activated first makes the run a success
|
|
442
|
-
|
|
443
|
-
if (version.status === ZEROPS_ACTIVE) {
|
|
444
|
-
try {
|
|
445
|
-
await reconcileActiveSchema(input, signal)
|
|
446
|
-
} catch {
|
|
447
|
-
signal.throwIfAborted()
|
|
448
|
-
return { state: 'pending' }
|
|
449
|
-
}
|
|
450
|
-
return { state: 'settled', outcome: 'succeeded' }
|
|
451
|
-
}
|
|
505
|
+
// Cancellation never implies rollback: a version that activated first makes the run a success.
|
|
506
|
+
if (version.status === ZEROPS_ACTIVE) return { state: 'settled', outcome: 'succeeded' }
|
|
452
507
|
if (version.status !== undefined && ZEROPS_TERMINAL.has(version.status)) return { state: 'settled', outcome: 'failed' }
|
|
453
508
|
await cancelBuildQuietly(checkpoint.appVersionId, signal)
|
|
454
509
|
// A build request that never landed leaves the version UPLOADING for good; the deadline settles it.
|
|
@@ -460,6 +515,10 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
460
515
|
const log = async (line: string): Promise<void> => {
|
|
461
516
|
await input.log?.(line).catch(() => {})
|
|
462
517
|
}
|
|
518
|
+
if (parseSandboxCheckpoint(input) !== null) {
|
|
519
|
+
await log('deploy interrupted: Control stopped while it deployed into the workspace sandbox; bind the workspace again')
|
|
520
|
+
return { state: 'failed' }
|
|
521
|
+
}
|
|
463
522
|
const checkpoint = runCheckpoint(input)
|
|
464
523
|
if (checkpoint === null) {
|
|
465
524
|
await log('unrecognised checkpoint; failing without platform calls')
|
|
@@ -485,10 +544,7 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
485
544
|
}
|
|
486
545
|
if (version === null) return { state: 'failed' }
|
|
487
546
|
assertVersionCoordinates(input.environment, checkpoint.appVersionId, version)
|
|
488
|
-
if (version.status === ZEROPS_ACTIVE) {
|
|
489
|
-
await reconcileActiveSchema(input, signal)
|
|
490
|
-
return { state: 'succeeded' }
|
|
491
|
-
}
|
|
547
|
+
if (version.status === ZEROPS_ACTIVE) return { state: 'succeeded' }
|
|
492
548
|
if (version.status !== undefined && ZEROPS_TERMINAL.has(version.status)) return { state: 'failed' }
|
|
493
549
|
if (pastDeadline(input.startedAtMs)) {
|
|
494
550
|
await cancelBuildQuietly(checkpoint.appVersionId, signal)
|
|
@@ -505,7 +561,14 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
505
561
|
assertNoPlatformOnlyReference(input.name)
|
|
506
562
|
assertNoPlatformOnlyReference(input.value)
|
|
507
563
|
assertOwnReferencesOnly(input.environment, input.name, input.value)
|
|
508
|
-
const
|
|
564
|
+
const stored = decodeEnvironment(input.environment).target
|
|
565
|
+
if ('kind' in stored) {
|
|
566
|
+
throw new ProviderSecretError(
|
|
567
|
+
'zerops: a dev environment runs in workspace sandboxes and keeps no secret on a Zerops service',
|
|
568
|
+
'devEnvironment',
|
|
569
|
+
)
|
|
570
|
+
}
|
|
571
|
+
const target = stored
|
|
509
572
|
try {
|
|
510
573
|
await api.putServiceEnv({
|
|
511
574
|
serviceId: target.serviceId,
|
|
@@ -522,7 +585,10 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
522
585
|
},
|
|
523
586
|
delete: async (input) => {
|
|
524
587
|
assertAuthoredManagedName(input.name)
|
|
525
|
-
const
|
|
588
|
+
const stored = decodeEnvironment(input.environment).target
|
|
589
|
+
// A dev environment's put refuses, so there is nothing to delete.
|
|
590
|
+
if ('kind' in stored) return
|
|
591
|
+
const target = stored
|
|
526
592
|
const variables = await api.listServiceEnv({ serviceId: target.serviceId, signal: abortSignal() })
|
|
527
593
|
const found = variables.find((variable) => variable.key === input.name)
|
|
528
594
|
if (found !== undefined) {
|
|
@@ -540,6 +606,7 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
|
|
|
540
606
|
if (namespaceTarget.ready !== true || namespaceTarget.projectId === undefined) {
|
|
541
607
|
throw new Error(`Zerops deployment namespace \`${namespace.id}\` is not ready`)
|
|
542
608
|
}
|
|
609
|
+
if (input.registration.environment.kind === 'dev') return prepareDevRegistration(input.registration, namespace.id, namespaceTarget)
|
|
543
610
|
const projectId = namespaceTarget.projectId
|
|
544
611
|
const manifest = decodeEnvelope('artifact', 'zerops', input.registration.environment.artifact, zeropsArtifactCodec)
|
|
545
612
|
assertFabrikaManifestCoordinates(manifest.app, {
|