@astrale-os/adapter-astrale 0.5.0-beta.17 → 0.5.0-beta.170
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 +102 -2
- package/dist/adapter.d.ts +7 -16
- package/dist/adapter.js +27 -266
- package/dist/admit.d.ts +11 -0
- package/dist/admit.js +63 -0
- package/dist/cli/commands/call.d.ts +15 -0
- package/dist/cli/commands/call.js +36 -0
- package/dist/cli/commands/version.d.ts +12 -0
- package/dist/cli/commands/version.js +56 -0
- package/dist/cli/diagnostic.d.ts +6 -0
- package/dist/cli/diagnostic.js +28 -0
- package/dist/cli/error.d.ts +7 -0
- package/dist/cli/error.js +29 -0
- package/dist/cli/executable.d.ts +2 -0
- package/dist/cli/executable.js +47 -0
- package/dist/cli/identity.d.ts +5 -0
- package/dist/cli/identity.js +11 -0
- package/dist/cli/json.d.ts +2 -0
- package/dist/cli/json.js +39 -0
- package/dist/cli/process.d.ts +18 -0
- package/dist/cli/process.js +108 -0
- package/dist/configure.d.ts +14 -0
- package/dist/configure.js +42 -0
- package/dist/deploy/deploy-release.d.ts +35 -0
- package/dist/deploy/deploy-release.js +153 -0
- package/dist/deploy/list.d.ts +21 -0
- package/dist/deploy/list.js +61 -0
- package/dist/deploy/readiness.d.ts +17 -0
- package/dist/deploy/readiness.js +56 -0
- package/dist/index.d.ts +20 -11
- package/dist/index.js +20 -11
- package/dist/params.d.ts +25 -36
- package/dist/services/api.d.ts +152 -0
- package/dist/services/api.js +38 -0
- package/dist/services/base64.d.ts +8 -0
- package/dist/services/base64.js +13 -0
- package/dist/services/content.d.ts +7 -0
- package/dist/services/content.js +13 -0
- package/dist/services/request.d.ts +24 -0
- package/dist/services/request.js +75 -0
- package/dist/services/response.d.ts +18 -0
- package/dist/services/response.js +206 -0
- package/package.json +10 -7
- package/template/astrale.config.ts +27 -38
- package/dist/cli.d.ts +0 -15
- package/dist/cli.js +0 -48
- package/dist/prerequisite.d.ts +0 -19
- package/dist/prerequisite.js +0 -59
- package/dist/service/addressing.d.ts +0 -3
- package/dist/service/addressing.js +0 -16
- package/dist/service/artifact.d.ts +0 -34
- package/dist/service/artifact.js +0 -122
- package/dist/service/readiness.d.ts +0 -3
- package/dist/service/readiness.js +0 -16
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# `@astrale-os/adapter-astrale`
|
|
2
2
|
|
|
3
|
-
Managed Astrale platform deployment adapter for Astrale Domains
|
|
3
|
+
Managed Astrale platform deployment adapter for Astrale Domains: every deploy is an immutable
|
|
4
|
+
deployment hosted by Admin's Services.
|
|
4
5
|
|
|
5
6
|
During the SDK beta program, install the beta package set explicitly:
|
|
6
7
|
|
|
@@ -8,4 +9,103 @@ During the SDK beta program, install the beta package set explicitly:
|
|
|
8
9
|
npm install @astrale-os/sdk@beta @astrale-os/adapter-astrale@beta
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
One adapter value configures one Project Environment:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
export default defineProject({
|
|
16
|
+
domain,
|
|
17
|
+
environments: {
|
|
18
|
+
development: {
|
|
19
|
+
deployment: astrale({ secrets: '.env.dev' }),
|
|
20
|
+
},
|
|
21
|
+
production: {
|
|
22
|
+
deployment: astrale({ secrets: '.env.production' }),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`astrale-domain deploy <environment>` builds the release locally and makes one immutable
|
|
29
|
+
deployment of it on Admin's Services, as a version of the Service of the Domain's origin and the
|
|
30
|
+
Environment: its own Worker script at its own URL, `https://<line>-<content>.<routingDomain>`. The
|
|
31
|
+
line comes from the Domain's origin and the Environment name, is opaque (a fingerprint), and names
|
|
32
|
+
the Service, whose stable URL `https://<line>.<routingDomain>` serves its current deployment. The
|
|
33
|
+
first deploy creates the Service, and every deploy makes the Service serve the deployment it
|
|
34
|
+
created or reused. The content covers the build and the frozen
|
|
35
|
+
configuration (variables, execution settings, durable options, the Workers runtime and the names of
|
|
36
|
+
the declared secrets, never their values), so one URL serves one release and a changed variable gives another
|
|
37
|
+
URL. The commit the deploy runs from is recorded but never part of the label: the same release
|
|
38
|
+
deployed from a later commit, or from a dirty or clean working tree, reuses its deployment, whose
|
|
39
|
+
record keeps the commit of the deploy that created it. Each deployment is its own issuer, with a signing
|
|
40
|
+
key Services generates for it: there is no key file to keep or distribute. Deploying a new release
|
|
41
|
+
leaves earlier deployments served at their own URLs; Services keeps each one until it is retired,
|
|
42
|
+
with no preview, expiry or retention to manage.
|
|
43
|
+
|
|
44
|
+
Every Environment deploys as the authenticated Astrale CLI identity, selected with `--as` when
|
|
45
|
+
needed. The adapter names no `owner`, so a Service its first deploy creates is owned by that
|
|
46
|
+
identity; a Service owned by another Identity, which the caller neither is nor acts as, is refused
|
|
47
|
+
as `service-owned-elsewhere`. Give a Service to another owner with its `transfer` Method.
|
|
48
|
+
`admin` names the Admin bookmark of the astrale CLI to deploy through; by default the CLI's
|
|
49
|
+
configured Admin target.
|
|
50
|
+
|
|
51
|
+
`durable` declares what a Domain serving durable Workflows tells the workflow engine (run
|
|
52
|
+
retention, retry before pausing, the deadline of each Step). The options are frozen into the
|
|
53
|
+
deployment's configuration (`settings.durableOptions`), so another value is another deployment,
|
|
54
|
+
and a durable run stays on the deployment that started it. A hosted deployment binds no service,
|
|
55
|
+
no dispatch namespace and no router.
|
|
56
|
+
|
|
57
|
+
The adapter calls the static Methods of `CloudflareService` on Admin's Services with
|
|
58
|
+
`astrale call --admin` (astrale CLI 1.0.0-beta.126 or newer): `CloudflareService.hosting` to read
|
|
59
|
+
the routing domain, then `CloudflareService.deploy`, a non-durable Action, with the request on
|
|
60
|
+
stdin; `list` calls `CloudflareService.list`. It never calls an instance and never installs the
|
|
61
|
+
Domain: install the URL the deploy prints with `astrale domain install <url> --direct -i <instance>`.
|
|
62
|
+
|
|
63
|
+
Secrets come from the file `secrets` names. A new deployment binds the file's current values. A
|
|
64
|
+
redeploy of the same release (same label) reuses its deployment and rewrites that deployment's
|
|
65
|
+
secrets in place when they changed (`Secrets: updated`); the new values are served once
|
|
66
|
+
propagated, which is eventually consistent (about 4 s). No other deployment's secrets are ever
|
|
67
|
+
written. A secret name added or removed changes the configuration, so it is a new deployment.
|
|
68
|
+
|
|
69
|
+
`astrale-domain list [--environment <name>] [--json]` lists, Environment by Environment, the
|
|
70
|
+
deployments of the Services the caller owns or acts as the owner of (`CloudflareService.list`,
|
|
71
|
+
which changes nothing): each one's release, its name computed from its record
|
|
72
|
+
(`1.4.2 + 7 commits · a1b2c3d · staging`), its state, `active (current)` for the one its Service
|
|
73
|
+
serves (`current` in `--json`), its URL, and its call target on the Admin instance. A Services
|
|
74
|
+
deployment is listed `published` until it is retired (`withdrawn` once retiring), with no last
|
|
75
|
+
call or expiry: Services counts neither. A deployment whose stored record Services' SDK no longer
|
|
76
|
+
admits is listed with the record as stored; the listing names it from its host's facts.
|
|
77
|
+
|
|
78
|
+
The call target names two nodes. `callTarget.service`,
|
|
79
|
+
`@<serviceId>::services.astrale.ai:class.CloudflareService`, takes the Service's Methods, which
|
|
80
|
+
act on the Service and the deployment it currently serves: `promote` (`{ "label": "<label>" }`,
|
|
81
|
+
to roll back or forward to one of its active deployments), `setSecret` (`{ "name", "value" }`, to
|
|
82
|
+
rewrite one secret of the current deployment in place without redeploying), `secrets`,
|
|
83
|
+
`setSchedule` and `schedules` (UTC crons run on the current deployment), `logs`, `transfer`
|
|
84
|
+
(`{ "owner" }`) and `delete`. `callTarget.path`, `@<id>::services.astrale.ai:class.CloudflareDeployment`,
|
|
85
|
+
takes `retire` (`{}`), the emergency stop of that deployment alone. Call them with
|
|
86
|
+
`astrale call "<node>.method.<method>" --admin -d @file` (`--admin=<callTarget.admin>` when it
|
|
87
|
+
names a bookmark).
|
|
88
|
+
|
|
89
|
+
The deploy is ready once the deployment URL serves exactly the sealed release: its `release.json`
|
|
90
|
+
(release digest and build digest), its Bundle and its issuer documents. Readiness is cancellable
|
|
91
|
+
and bounded to two minutes; certificate verification is never disabled. Services refusals are
|
|
92
|
+
reported with their reason (`service-owned-elsewhere`, `deployment-conflict`, ...). A validation or
|
|
93
|
+
ownership refusal changes nothing. `service-unavailable` waited on, or lost to, another operation on
|
|
94
|
+
the deployment and may follow effects: a creation that lost its lease after uploading, or an
|
|
95
|
+
in-place secret rewrite that wrote part of the values. Rerunning the same deploy converges on the
|
|
96
|
+
same deployment.
|
|
97
|
+
|
|
98
|
+
The removed instance mode (`instance`, `serviceKey`, `name`, `signingIdentity`) is refused with the
|
|
99
|
+
configuration to write instead. A Project Environment that declares `installation` is refused before
|
|
100
|
+
any effect, naming the commands that replace it. Iterate with `astrale-domain deploy development`,
|
|
101
|
+
then install the URL it prints.
|
|
102
|
+
|
|
103
|
+
The managed Worker is the one `@astrale-os/adapter-cloudflare` builds: it owns frontend response
|
|
104
|
+
headers and routing, and it is the only server-side code. Bundling therefore refuses a built
|
|
105
|
+
frontend whose root contains `_headers`, `_redirects`, or `.assetsignore`, in any letter case,
|
|
106
|
+
before anything is uploaded: Services would serve them as public files, whereas a direct Cloudflare
|
|
107
|
+
deployment would apply them as Workers Static Assets configuration. It likewise refuses a root name
|
|
108
|
+
starting with `_worker.js`, in that exact case, such as a Cloudflare Pages `_worker.js` file or
|
|
109
|
+
directory: Services would publish that possible server-side code, whereas Wrangler refuses to
|
|
110
|
+
upload it. Vite copies its public directory (`public/` by default) to that root, so remove or
|
|
111
|
+
rename them there. The same names below the root remain ordinary files.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { Deployment } from '@astrale-os/sdk/deployment';
|
|
2
|
+
import type { Adapter } from '@astrale-os/sdk/deployment/adapter';
|
|
3
|
+
import type { AstraleDependencies } from './deploy/deploy-release.js';
|
|
3
4
|
import type { AstraleParams } from './params.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
prepare(parameters: AstraleParams, context: PrepareContext): Promise<ArtifactSource>;
|
|
9
|
-
watch(parameters: AstraleParams, context: WatchContext): Promise<WatchHandle>;
|
|
10
|
-
ensureServices: typeof ensureServices;
|
|
11
|
-
callAstrale: typeof callAstrale;
|
|
12
|
-
runAstrale: typeof runAstrale;
|
|
13
|
-
waitForReadiness: typeof waitForReadiness;
|
|
14
|
-
signingIdentity: typeof signingIdentity;
|
|
15
|
-
}
|
|
16
|
-
export declare function astrale(environments: Readonly<Record<string, AstraleParams>>): import("@astrale-os/sdk/deployment/adapter").Adapter<AstraleParams>;
|
|
17
|
-
export declare function astraleWithDependencies(environments: Readonly<Record<string, AstraleParams>>, dependencies: AstraleDependencies): import("@astrale-os/sdk/deployment/adapter").Adapter<AstraleParams>;
|
|
5
|
+
export type { AstraleDependencies } from './deploy/deploy-release.js';
|
|
6
|
+
/** Deploy one Project Environment as immutable deployments on Admin's Services. */
|
|
7
|
+
export declare function astrale(parameters?: AstraleParams): Deployment<AstraleParams, Adapter<AstraleParams>>;
|
|
8
|
+
export declare function astraleWithDependencies(parameters: AstraleParams, dependencies: AstraleDependencies): Deployment<AstraleParams, Adapter<AstraleParams>>;
|
package/dist/adapter.js
CHANGED
|
@@ -1,276 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { defineAdapter } from '@astrale-os/sdk/deployment/adapter';
|
|
4
|
-
import { addressing, assemble } from '@astrale-os/sdk/deployment/release';
|
|
1
|
+
import { cloudflareWorkerBundler } from '@astrale-os/adapter-cloudflare/build';
|
|
2
|
+
import { defineAdapter, defineDeployment } from '@astrale-os/sdk/deployment/adapter';
|
|
5
3
|
import { createRequire } from 'node:module';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import { admitAstraleParameters } from './admit.js';
|
|
5
|
+
import { callAdmin } from './cli/commands/call.js';
|
|
6
|
+
import { requireCliVersion } from './cli/commands/version.js';
|
|
7
|
+
import { resolveCliExecutable } from './cli/executable.js';
|
|
8
|
+
import { configureAstrale } from './configure.js';
|
|
9
|
+
import { deployAstraleRelease, placeAstrale } from './deploy/deploy-release.js';
|
|
10
|
+
import { listAstraleDeployments } from './deploy/list.js';
|
|
11
|
+
import { waitForReadiness } from './deploy/readiness.js';
|
|
13
12
|
const packageVersion = createRequire(import.meta.url)('../package.json')
|
|
14
13
|
.version;
|
|
15
|
-
|
|
16
|
-
export function astrale(
|
|
17
|
-
return astraleWithDependencies(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
runAstrale,
|
|
23
|
-
waitForReadiness,
|
|
24
|
-
signingIdentity,
|
|
14
|
+
/** Deploy one Project Environment as immutable deployments on Admin's Services. */
|
|
15
|
+
export function astrale(parameters = {}) {
|
|
16
|
+
return astraleWithDependencies(parameters, {
|
|
17
|
+
resolveCliExecutable,
|
|
18
|
+
requireCliVersion,
|
|
19
|
+
callAdmin,
|
|
20
|
+
waitForReadiness: (release, signal) => waitForReadiness(release, signal),
|
|
25
21
|
});
|
|
26
22
|
}
|
|
27
|
-
export function astraleWithDependencies(
|
|
28
|
-
|
|
23
|
+
export function astraleWithDependencies(parameters, dependencies) {
|
|
24
|
+
const adapter = defineAdapter({
|
|
29
25
|
name: 'astrale',
|
|
30
26
|
version: packageVersion,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let secrets;
|
|
39
|
-
let signing;
|
|
40
|
-
try {
|
|
41
|
-
signing = await dependencies.signingIdentity({
|
|
42
|
-
projectDir: context.projectDir,
|
|
43
|
-
source: parameters.signingIdentity,
|
|
44
|
-
origin: context.artifact.build.schema.compiled.root.origin,
|
|
45
|
-
mode: 'deploy',
|
|
46
|
-
});
|
|
47
|
-
secrets = signingIdentitySecrets(context.secrets, signing);
|
|
48
|
-
}
|
|
49
|
-
catch (cause) {
|
|
50
|
-
return failed('prerequisite', progress(), cause);
|
|
51
|
-
}
|
|
52
|
-
const instance = parameters.instance;
|
|
53
|
-
const servicesOrigin = parameters.servicesOrigin ?? SERVICES_ORIGIN;
|
|
54
|
-
const identity = identityArguments(parameters.identity);
|
|
55
|
-
let prerequisite;
|
|
56
|
-
try {
|
|
57
|
-
const evidence = await dependencies.ensureServices({
|
|
58
|
-
projectDir: context.projectDir,
|
|
59
|
-
instance,
|
|
60
|
-
servicesOrigin,
|
|
61
|
-
identity,
|
|
62
|
-
run: dependencies.runAstrale,
|
|
63
|
-
});
|
|
64
|
-
prerequisite =
|
|
65
|
-
evidence.state === 'installed'
|
|
66
|
-
? Object.freeze({ kind: 'applied', evidence })
|
|
67
|
-
: NONE;
|
|
68
|
-
}
|
|
69
|
-
catch (cause) {
|
|
70
|
-
const prerequisite = cause instanceof ServicesPrerequisiteError && cause.mutation === 'installed'
|
|
71
|
-
? Object.freeze({
|
|
72
|
-
kind: 'applied',
|
|
73
|
-
evidence: Object.freeze({ origin: servicesOrigin, state: 'installed' }),
|
|
74
|
-
})
|
|
75
|
-
: cause instanceof ServicesPrerequisiteError && cause.mutation === 'unknown'
|
|
76
|
-
? Object.freeze({ kind: 'unknown' })
|
|
77
|
-
: NONE;
|
|
78
|
-
return failed('prerequisite', progress({ prerequisite }), cause);
|
|
79
|
-
}
|
|
80
|
-
const origin = context.artifact.build.schema.compiled.root.origin;
|
|
81
|
-
const name = parameters.name ?? serviceName(origin);
|
|
82
|
-
let payload;
|
|
83
|
-
try {
|
|
84
|
-
payload = deploymentPayload(context.artifact, { origin, name, vars: parameters.vars });
|
|
85
|
-
}
|
|
86
|
-
catch (cause) {
|
|
87
|
-
return failed('provider', progress({ prerequisite }), cause);
|
|
88
|
-
}
|
|
89
|
-
let deployed;
|
|
90
|
-
try {
|
|
91
|
-
deployed = await dependencies.callAstrale({
|
|
92
|
-
projectDir: context.projectDir,
|
|
93
|
-
instance,
|
|
94
|
-
path: servicesDeployMethod(servicesOrigin),
|
|
95
|
-
identity,
|
|
96
|
-
data: payload,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
catch (cause) {
|
|
100
|
-
return failed('provider', progress({ prerequisite, provider: { kind: 'unknown' } }), cause);
|
|
101
|
-
}
|
|
102
|
-
const expectedPath = servicePath(origin);
|
|
103
|
-
let observation;
|
|
104
|
-
try {
|
|
105
|
-
observation = deployedService(deployed, expectedPath);
|
|
106
|
-
}
|
|
107
|
-
catch (cause) {
|
|
108
|
-
return failed('provider', progress({
|
|
109
|
-
prerequisite,
|
|
110
|
-
provider: { kind: 'partial' },
|
|
111
|
-
}), cause);
|
|
112
|
-
}
|
|
113
|
-
const url = observation.url;
|
|
114
|
-
const applied = Object.freeze({
|
|
115
|
-
kind: 'applied',
|
|
116
|
-
evidence: Object.freeze({
|
|
117
|
-
provider: 'astrale',
|
|
118
|
-
deployment: observation.digest,
|
|
119
|
-
artifact: context.artifact.digest,
|
|
120
|
-
}),
|
|
121
|
-
});
|
|
122
|
-
if (url === undefined) {
|
|
123
|
-
return failed('addressing', progress({ prerequisite, provider: applied }), new Error('Astrale Services deployment returned no URL.'));
|
|
124
|
-
}
|
|
125
|
-
let selected;
|
|
126
|
-
try {
|
|
127
|
-
selected = addressing(url);
|
|
128
|
-
}
|
|
129
|
-
catch (cause) {
|
|
130
|
-
return failed('addressing', progress({ prerequisite, provider: applied }), cause);
|
|
131
|
-
}
|
|
132
|
-
const provider = Object.freeze({
|
|
133
|
-
kind: 'applied',
|
|
134
|
-
evidence: Object.freeze({ ...applied.evidence, issuer: selected.issuer }),
|
|
135
|
-
});
|
|
136
|
-
let configuration = NONE;
|
|
137
|
-
const secretNames = [signing.binding, ...Object.keys(context.secrets).sort()];
|
|
138
|
-
const configured = [];
|
|
139
|
-
if (secretNames.length > 0) {
|
|
140
|
-
try {
|
|
141
|
-
for (const secret of secretNames) {
|
|
142
|
-
await dependencies.callAstrale({
|
|
143
|
-
projectDir: context.projectDir,
|
|
144
|
-
instance,
|
|
145
|
-
path: `${servicePath(origin)}::setSecret`,
|
|
146
|
-
identity,
|
|
147
|
-
data: { name: secret, value: secrets[secret] },
|
|
148
|
-
});
|
|
149
|
-
configured.push(secret);
|
|
150
|
-
}
|
|
151
|
-
configuration = Object.freeze({
|
|
152
|
-
kind: 'applied',
|
|
153
|
-
evidence: Object.freeze({ names: secretNames }),
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
catch (cause) {
|
|
157
|
-
const configuration = configured.length === 0
|
|
158
|
-
? { kind: 'unknown' }
|
|
159
|
-
: {
|
|
160
|
-
kind: 'partial',
|
|
161
|
-
evidence: Object.freeze({ names: Object.freeze([...configured]) }),
|
|
162
|
-
};
|
|
163
|
-
return failed('configuration', progress({ prerequisite, provider, configuration }), cause);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
let release;
|
|
167
|
-
try {
|
|
168
|
-
release = assemble(context.artifact.build, selected);
|
|
169
|
-
}
|
|
170
|
-
catch (cause) {
|
|
171
|
-
return failed('release', progress({ prerequisite, provider, configuration }), cause);
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
await dependencies.waitForReadiness(release);
|
|
175
|
-
}
|
|
176
|
-
catch (cause) {
|
|
177
|
-
return failed('readiness', progress({ prerequisite, provider, configuration }), cause, release);
|
|
178
|
-
}
|
|
179
|
-
let installation;
|
|
180
|
-
try {
|
|
181
|
-
await dependencies.runAstrale({
|
|
182
|
-
projectDir: context.projectDir,
|
|
183
|
-
input: [
|
|
184
|
-
'domain',
|
|
185
|
-
'install',
|
|
186
|
-
url,
|
|
187
|
-
'--direct',
|
|
188
|
-
'-i',
|
|
189
|
-
instance,
|
|
190
|
-
'--allow-identity-override',
|
|
191
|
-
'--json',
|
|
192
|
-
'--timeout',
|
|
193
|
-
'240000',
|
|
194
|
-
...identity,
|
|
195
|
-
],
|
|
196
|
-
});
|
|
197
|
-
installation = Object.freeze({
|
|
198
|
-
kind: 'applied',
|
|
199
|
-
evidence: Object.freeze({ instance, origin }),
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
catch (cause) {
|
|
203
|
-
return failed('installation', progress({ prerequisite, provider, configuration, installation: { kind: 'unknown' } }), cause, release);
|
|
204
|
-
}
|
|
205
|
-
return Object.freeze({
|
|
206
|
-
status: 'ready',
|
|
207
|
-
phase: 'complete',
|
|
208
|
-
progress: Object.freeze({
|
|
209
|
-
...progress({ prerequisite, configuration, installation }),
|
|
210
|
-
provider,
|
|
211
|
-
}),
|
|
212
|
-
release,
|
|
213
|
-
});
|
|
214
|
-
},
|
|
27
|
+
// Services hosts the same generated Worker: both adapters share one build.
|
|
28
|
+
bundler: cloudflareWorkerBundler,
|
|
29
|
+
admit: admitAstraleParameters,
|
|
30
|
+
configure: configureAstrale,
|
|
31
|
+
placement: (parameters, context) => placeAstrale(parameters, context, dependencies),
|
|
32
|
+
deployRelease: (parameters, context) => deployAstraleRelease(parameters, context, dependencies),
|
|
33
|
+
list: (parameters, context) => listAstraleDeployments(parameters, context, dependencies),
|
|
215
34
|
secretsFile: (parameters) => parameters.secrets,
|
|
216
35
|
});
|
|
217
|
-
|
|
218
|
-
function cloudflareParameters(parameters, watch) {
|
|
219
|
-
return Object.freeze({
|
|
220
|
-
...(parameters.port === undefined ? {} : { port: parameters.port }),
|
|
221
|
-
...(watch && parameters.host !== undefined ? { host: parameters.host } : {}),
|
|
222
|
-
...(parameters.vars === undefined ? {} : { vars: parameters.vars }),
|
|
223
|
-
...(parameters.signingIdentity === undefined
|
|
224
|
-
? {}
|
|
225
|
-
: { signingIdentity: parameters.signingIdentity }),
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
function deployedService(input, expectedPath) {
|
|
229
|
-
if (input === null || typeof input !== 'object' || Array.isArray(input))
|
|
230
|
-
invalidDeployment();
|
|
231
|
-
const value = input;
|
|
232
|
-
if (value.error !== undefined && value.error !== null)
|
|
233
|
-
invalidDeployment();
|
|
234
|
-
if (value.state !== 'ready') {
|
|
235
|
-
throw new TypeError('Astrale Services deployment did not report ready provider state.');
|
|
236
|
-
}
|
|
237
|
-
if (value.path !== expectedPath) {
|
|
238
|
-
throw new TypeError('Astrale Services deployment returned a different Service path.');
|
|
239
|
-
}
|
|
240
|
-
if (typeof value.digest !== 'string' || value.digest.length === 0) {
|
|
241
|
-
throw new TypeError('Astrale Services deployment returned an invalid provider digest.');
|
|
242
|
-
}
|
|
243
|
-
let url;
|
|
244
|
-
if (typeof value.url === 'string') {
|
|
245
|
-
try {
|
|
246
|
-
url = new URL(value.url).href.replace(/\/$/u, '');
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
// Addressing admission below retains the successful provider effect.
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return Object.freeze({
|
|
253
|
-
...(url === undefined ? {} : { url }),
|
|
254
|
-
digest: value.digest,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
function invalidDeployment() {
|
|
258
|
-
throw new TypeError('Astrale Services deployment returned invalid provider evidence.');
|
|
259
|
-
}
|
|
260
|
-
function progress(input = {}) {
|
|
261
|
-
return Object.freeze({
|
|
262
|
-
prerequisite: input.prerequisite ?? NONE,
|
|
263
|
-
provider: input.provider ?? NONE,
|
|
264
|
-
configuration: input.configuration ?? NONE,
|
|
265
|
-
installation: input.installation ?? NONE,
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
function failed(phase, deploymentProgress, cause, release) {
|
|
269
|
-
return Object.freeze({
|
|
270
|
-
status: 'failed',
|
|
271
|
-
phase,
|
|
272
|
-
progress: deploymentProgress,
|
|
273
|
-
error: cause instanceof Error ? cause : new Error(String(cause)),
|
|
274
|
-
...(release === undefined ? {} : { release }),
|
|
275
|
-
});
|
|
36
|
+
return defineDeployment(adapter, parameters);
|
|
276
37
|
}
|
package/dist/admit.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AdapterEnvironmentContext } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { AstraleParams } from './params.js';
|
|
3
|
+
/**
|
|
4
|
+
* Refuse, when the Project loads, an Environment this adapter cannot deploy: an unknown or removed
|
|
5
|
+
* parameter or a malformed Admin bookmark.
|
|
6
|
+
*
|
|
7
|
+
* An Environment of the removed instance mode (`instance`, `signingIdentity`) is left to the deploy
|
|
8
|
+
* mode selection, which refuses it when it deploys with the configuration to write instead; loading
|
|
9
|
+
* it to build or test it has no effect.
|
|
10
|
+
*/
|
|
11
|
+
export declare function admitAstraleParameters(parameters: AstraleParams, context: AdapterEnvironmentContext): void;
|
package/dist/admit.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The parameters an Environment of this adapter declares. */
|
|
2
|
+
const PARAMETERS = Object.freeze([
|
|
3
|
+
'admin',
|
|
4
|
+
'secrets',
|
|
5
|
+
'vars',
|
|
6
|
+
'maximumRequestBytes',
|
|
7
|
+
'tokenExchange',
|
|
8
|
+
'durable',
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* The parameters of the removed instance mode. `astrale-domain deploy` refuses them before any
|
|
12
|
+
* effect, with the configuration to write instead (CT33, AM-72).
|
|
13
|
+
*/
|
|
14
|
+
const INSTANCE_MODE = Object.freeze(['instance', 'signingIdentity']);
|
|
15
|
+
/** The parameters that named the stable Service of the removed instance mode. */
|
|
16
|
+
const INSTANCE_SERVICE = Object.freeze(['serviceKey', 'name']);
|
|
17
|
+
/** The longest Admin bookmark name an Environment may name. */
|
|
18
|
+
const MAXIMUM_NAME_LENGTH = 256;
|
|
19
|
+
/**
|
|
20
|
+
* Refuse, when the Project loads, an Environment this adapter cannot deploy: an unknown or removed
|
|
21
|
+
* parameter or a malformed Admin bookmark.
|
|
22
|
+
*
|
|
23
|
+
* An Environment of the removed instance mode (`instance`, `signingIdentity`) is left to the deploy
|
|
24
|
+
* mode selection, which refuses it when it deploys with the configuration to write instead; loading
|
|
25
|
+
* it to build or test it has no effect.
|
|
26
|
+
*/
|
|
27
|
+
export function admitAstraleParameters(parameters, context) {
|
|
28
|
+
const values = parameters;
|
|
29
|
+
// A parameter is declared when its value is not `undefined`, as optional parameters read.
|
|
30
|
+
const declared = Reflect.ownKeys(values).filter((key) => values[key] !== undefined);
|
|
31
|
+
const environment = `Astrale Environment ${context.environment}`;
|
|
32
|
+
if (declared.some((key) => isOneOf(key, INSTANCE_MODE)))
|
|
33
|
+
return;
|
|
34
|
+
const service = declared.filter((key) => isOneOf(key, INSTANCE_SERVICE));
|
|
35
|
+
if (service.length > 0) {
|
|
36
|
+
throw new TypeError(`${environment} declares ${names(service)}, which named the stable Service of the removed ` +
|
|
37
|
+
`instance mode. Remove ${service.length === 1 ? 'it' : 'them'}: each immutable ` +
|
|
38
|
+
'deployment is named by its own label.');
|
|
39
|
+
}
|
|
40
|
+
const unknown = declared.filter((key) => !isOneOf(key, PARAMETERS));
|
|
41
|
+
if (unknown.length > 0) {
|
|
42
|
+
throw new TypeError(`${environment} declares unknown parameters ${names(unknown)}.`);
|
|
43
|
+
}
|
|
44
|
+
if (parameters.admin !== undefined &&
|
|
45
|
+
(!stable(parameters.admin, MAXIMUM_NAME_LENGTH) ||
|
|
46
|
+
parameters.admin.startsWith('-') ||
|
|
47
|
+
parameters.admin.includes('='))) {
|
|
48
|
+
throw new TypeError(`${environment} names an invalid admin: the name of an Admin bookmark of the astrale CLI.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** A non-empty single token: no whitespace or control character, within `maximum` characters. */
|
|
52
|
+
function stable(value, maximum) {
|
|
53
|
+
return (typeof value === 'string' &&
|
|
54
|
+
value.length > 0 &&
|
|
55
|
+
value.length <= maximum &&
|
|
56
|
+
!/[\s\p{Cc}]/u.test(value));
|
|
57
|
+
}
|
|
58
|
+
function isOneOf(key, list) {
|
|
59
|
+
return typeof key === 'string' && list.includes(key);
|
|
60
|
+
}
|
|
61
|
+
function names(keys) {
|
|
62
|
+
return keys.map((key) => `\`${String(key)}\``).join(', ');
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Call one Domain Method on Admin's Kernel with `astrale call --admin` (CT21) and decode its JSON
|
|
3
|
+
* result. The input goes through stdin (`-d -`), never argv, since it can hold the Environment's
|
|
4
|
+
* secrets; `--admin=<bookmark>` keeps a bookmark from being read as a param.
|
|
5
|
+
*/
|
|
6
|
+
export declare function callAdmin(input: {
|
|
7
|
+
readonly executable: string;
|
|
8
|
+
readonly projectDir: string;
|
|
9
|
+
/** The Admin bookmark; the CLI's configured Admin target when absent. */
|
|
10
|
+
readonly admin?: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly authority: readonly string[];
|
|
13
|
+
readonly data: unknown;
|
|
14
|
+
readonly signal: AbortSignal;
|
|
15
|
+
}): Promise<unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CliProcessError } from '../error.js';
|
|
2
|
+
import { decodeJson } from '../json.js';
|
|
3
|
+
import { runCliProcess } from '../process.js';
|
|
4
|
+
/** How long a call to Admin's Services may take, and the CLI process around it. */
|
|
5
|
+
const CALL_TIMEOUT_MS = 240_000;
|
|
6
|
+
const PROCESS_TIMEOUT_MS = 250_000;
|
|
7
|
+
/**
|
|
8
|
+
* Call one Domain Method on Admin's Kernel with `astrale call --admin` (CT21) and decode its JSON
|
|
9
|
+
* result. The input goes through stdin (`-d -`), never argv, since it can hold the Environment's
|
|
10
|
+
* secrets; `--admin=<bookmark>` keeps a bookmark from being read as a param.
|
|
11
|
+
*/
|
|
12
|
+
export async function callAdmin(input) {
|
|
13
|
+
const result = await runCliProcess({
|
|
14
|
+
executable: input.executable,
|
|
15
|
+
projectDir: input.projectDir,
|
|
16
|
+
args: [
|
|
17
|
+
'--ci',
|
|
18
|
+
'--no-prompt',
|
|
19
|
+
'call',
|
|
20
|
+
input.path,
|
|
21
|
+
input.admin === undefined ? '--admin' : `--admin=${input.admin}`,
|
|
22
|
+
'--json',
|
|
23
|
+
'--timeout',
|
|
24
|
+
String(CALL_TIMEOUT_MS),
|
|
25
|
+
...input.authority,
|
|
26
|
+
'-d',
|
|
27
|
+
'-',
|
|
28
|
+
],
|
|
29
|
+
stdin: JSON.stringify(input.data),
|
|
30
|
+
signal: input.signal,
|
|
31
|
+
timeoutMs: PROCESS_TIMEOUT_MS,
|
|
32
|
+
});
|
|
33
|
+
if (!result.ok)
|
|
34
|
+
throw new CliProcessError('command', `call ${input.path}`, result.failure);
|
|
35
|
+
return decodeJson(result.stdout, `astrale call ${input.path} success`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first astrale CLI release whose `call` runs on the Admin kernel (`--admin`) and reads its
|
|
3
|
+
* input from stdin with `-d -` (CT21, cli#579), built on an SDK that reads an R1 Kernel's Schema
|
|
4
|
+
* introspection (cli#581): every deploy reaches Admin's Services that way. cli 1.0.0-beta.125
|
|
5
|
+
* carries neither.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MINIMUM_ASTRALE_CLI_VERSION = "1.0.0-beta.126";
|
|
8
|
+
export declare function requireCliVersion(input: {
|
|
9
|
+
readonly executable: string;
|
|
10
|
+
readonly projectDir: string;
|
|
11
|
+
readonly signal: AbortSignal;
|
|
12
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CliProcessError } from '../error.js';
|
|
2
|
+
import { runCliProcess } from '../process.js';
|
|
3
|
+
/**
|
|
4
|
+
* The first astrale CLI release whose `call` runs on the Admin kernel (`--admin`) and reads its
|
|
5
|
+
* input from stdin with `-d -` (CT21, cli#579), built on an SDK that reads an R1 Kernel's Schema
|
|
6
|
+
* introspection (cli#581): every deploy reaches Admin's Services that way. cli 1.0.0-beta.125
|
|
7
|
+
* carries neither.
|
|
8
|
+
*/
|
|
9
|
+
export const MINIMUM_ASTRALE_CLI_VERSION = '1.0.0-beta.126';
|
|
10
|
+
export async function requireCliVersion(input) {
|
|
11
|
+
const result = await runCliProcess({
|
|
12
|
+
executable: input.executable,
|
|
13
|
+
projectDir: input.projectDir,
|
|
14
|
+
args: ['--version'],
|
|
15
|
+
signal: input.signal,
|
|
16
|
+
timeoutMs: 10_000,
|
|
17
|
+
stdoutLimit: 256,
|
|
18
|
+
stderrLimit: 4_096,
|
|
19
|
+
});
|
|
20
|
+
if (!result.ok)
|
|
21
|
+
throw new CliProcessError('command', 'version', result.failure);
|
|
22
|
+
const version = result.stdout.trim().replace(/^v/u, '');
|
|
23
|
+
if (!isCompatible(version)) {
|
|
24
|
+
throw new TypeError(`Astrale CLI ${version || '<invalid>'} is incompatible; ${MINIMUM_ASTRALE_CLI_VERSION} or newer is required.`);
|
|
25
|
+
}
|
|
26
|
+
return version;
|
|
27
|
+
}
|
|
28
|
+
function isCompatible(input) {
|
|
29
|
+
const value = semver(input);
|
|
30
|
+
const minimum = semver(MINIMUM_ASTRALE_CLI_VERSION);
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return false;
|
|
33
|
+
for (let index = 0; index < 3; index += 1) {
|
|
34
|
+
if (value.core[index] > minimum.core[index])
|
|
35
|
+
return true;
|
|
36
|
+
if (value.core[index] < minimum.core[index])
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (value.prerelease === undefined)
|
|
40
|
+
return true;
|
|
41
|
+
if (minimum.prerelease === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
if (value.prerelease.name !== minimum.prerelease.name) {
|
|
44
|
+
return value.prerelease.name.localeCompare(minimum.prerelease.name) > 0;
|
|
45
|
+
}
|
|
46
|
+
return value.prerelease.number >= minimum.prerelease.number;
|
|
47
|
+
}
|
|
48
|
+
function semver(input) {
|
|
49
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z]+)\.(\d+))?$/u.exec(input);
|
|
50
|
+
if (match === null)
|
|
51
|
+
return undefined;
|
|
52
|
+
return {
|
|
53
|
+
core: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
54
|
+
...(match[4] === undefined ? {} : { prerelease: { name: match[4], number: Number(match[5]) } }),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type PublicResponseDiagnostic = Readonly<{
|
|
2
|
+
code: number;
|
|
3
|
+
message?: string;
|
|
4
|
+
}>;
|
|
5
|
+
/** Admit only the CLI's bounded, caller-safe public response projection. */
|
|
6
|
+
export declare function publicResponseDiagnostic(input: Readonly<Record<string, unknown>> | undefined): PublicResponseDiagnostic | undefined;
|