@molecule/api-deploy-rollout-sandbox 0.0.0-stage → 1.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.
- package/LICENSE +202 -0
- package/README.md +210 -2
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +18 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/sandbox.d.ts +103 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +146 -0
- package/package.json +57 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,211 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-10-19T18:03:28.785Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/api-deploy-rollout-sandbox
|
|
10
|
+
|
|
11
|
+
Sandbox provider bond for the deploy-rollout core.
|
|
12
|
+
|
|
13
|
+
One adapter over `@molecule/api-code-sandbox`, so E2B, Docker and Fly sandboxes
|
|
14
|
+
share one rolling-deploy implementation. The deploy supplies its launch recipe and
|
|
15
|
+
readiness gate; the bond supplies the lifecycle.
|
|
16
|
+
|
|
17
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
18
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
19
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { runRollout, setProvider } from '@molecule/api-deploy-rollout'
|
|
25
|
+
import { provider } from '@molecule/api-deploy-rollout-default'
|
|
26
|
+
import { createSandboxInstanceProvider } from '@molecule/api-deploy-rollout-sandbox'
|
|
27
|
+
|
|
28
|
+
setProvider(provider)
|
|
29
|
+
await runRollout({
|
|
30
|
+
provider: createSandboxInstanceProvider({
|
|
31
|
+
provider: sandboxProvider,
|
|
32
|
+
launch: (index) => launchReplica(index),
|
|
33
|
+
join: (instance) => upsertUpstream(instance.upstreamUrl ?? ''),
|
|
34
|
+
}),
|
|
35
|
+
current: oldInstances,
|
|
36
|
+
policy: { replicas: 2 },
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Type
|
|
41
|
+
|
|
42
|
+
`provider`
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install @molecule/api-deploy-rollout-sandbox @molecule/api-code-sandbox @molecule/api-deploy-rollout
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
### Interfaces
|
|
53
|
+
|
|
54
|
+
#### `SandboxInstance`
|
|
55
|
+
|
|
56
|
+
One sandbox instance plus the address the edge dials.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
interface SandboxInstance extends RolloutInstance {
|
|
60
|
+
/** The live sandbox handle, when this run holds it. */
|
|
61
|
+
sandbox: Sandbox | null
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `SandboxInstanceOptions`
|
|
66
|
+
|
|
67
|
+
How a sandbox rollout reaches and gates one app's instances.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
interface SandboxInstanceOptions {
|
|
71
|
+
/** The sandbox provider (E2B, Docker, Fly — any bonded provider). */
|
|
72
|
+
provider: SandboxProvider
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create and start the instance at `index`, resolving once it exists. This is the
|
|
76
|
+
* deploy's own recipe (tree transfer, env, boot script); the bond never guesses
|
|
77
|
+
* it.
|
|
78
|
+
*/
|
|
79
|
+
launch: (index: number) => Promise<{ sandbox: Sandbox; upstreamUrl: string }>
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A BLOCKING readiness gate with the caller's own semantics and budget. When
|
|
83
|
+
* present, `waitReady` delegates to it. When absent, the bond polls
|
|
84
|
+
* `readinessProbe` until `readinessTimeoutMs` elapses.
|
|
85
|
+
*/
|
|
86
|
+
waitReady?: (instance: SandboxInstance) => Promise<boolean>
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* One HTTP readiness probe. Default: `GET <upstreamUrl>/health/ready`, falling
|
|
90
|
+
* back to `GET <upstreamUrl>/health` on 404/405 (an app scaffolded before the
|
|
91
|
+
* lifecycle bond answers only the latter).
|
|
92
|
+
*/
|
|
93
|
+
readinessProbe?: (instance: SandboxInstance) => Promise<boolean>
|
|
94
|
+
|
|
95
|
+
/** How long the bond's own readiness poll may take. Defaults to 120 s. */
|
|
96
|
+
readinessTimeoutMs?: number
|
|
97
|
+
|
|
98
|
+
/** Probe cadence for the bond's own readiness poll. Defaults to 2000 ms. */
|
|
99
|
+
readinessPollMs?: number
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The shell command that tells the app to drain. Defaults to a SIGTERM to the
|
|
103
|
+
* sandbox's node processes ({@link sigtermNodeProcessesCommand}).
|
|
104
|
+
*/
|
|
105
|
+
drainCommand?: string | ((drainMs: number) => string)
|
|
106
|
+
|
|
107
|
+
/** Add a ready instance to the caller's routable set. Default: no-op. */
|
|
108
|
+
join?: (instance: SandboxInstance) => Promise<void>
|
|
109
|
+
|
|
110
|
+
/** Remove an instance from the caller's routable set. Default: no-op. */
|
|
111
|
+
leave?: (instance: SandboxInstance) => Promise<void>
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Enumerate this deployment's live instances, when the caller can. Used by the
|
|
115
|
+
* rollout's idempotent resume; omitted means "roll from the caller's set".
|
|
116
|
+
*/
|
|
117
|
+
list?: () => Promise<SandboxInstance[]>
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Functions
|
|
122
|
+
|
|
123
|
+
#### `sigtermNodeProcessesCommand(drainMs)`
|
|
124
|
+
|
|
125
|
+
A drain command that sends SIGTERM to the sandbox's node processes and waits,
|
|
126
|
+
bounded, for them to exit.
|
|
127
|
+
|
|
128
|
+
The lifecycle bond turns SIGTERM into "flip readiness to 503, finish in-flight
|
|
129
|
+
requests, exit". An app without the bond ignores the signal and the rollout
|
|
130
|
+
destroys it after the same bound — no worse than destroying it without a word.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
function sigtermNodeProcessesCommand(drainMs: number): string
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- `drainMs` — How long to wait for those processes to exit.
|
|
137
|
+
|
|
138
|
+
**Returns:** The shell command.
|
|
139
|
+
|
|
140
|
+
#### `probeSandboxReadiness(instance, timeoutMs)`
|
|
141
|
+
|
|
142
|
+
One HTTP readiness look at an instance.
|
|
143
|
+
|
|
144
|
+
`/health/ready` first; a 404 or 405 means the app predates the lifecycle bond, so
|
|
145
|
+
`/health` is asked instead. Any other non-2xx answer is "not ready", and a
|
|
146
|
+
transport failure is "not ready" too (the instance may still be booting).
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
function probeSandboxReadiness(instance: SandboxInstance, timeoutMs?: number): Promise<boolean>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- `instance` — The instance to probe.
|
|
153
|
+
- `timeoutMs` — Per-request budget. Defaults to 5000 ms.
|
|
154
|
+
|
|
155
|
+
**Returns:** Whether it answered ready.
|
|
156
|
+
|
|
157
|
+
#### `createSandboxInstanceProvider(options)`
|
|
158
|
+
|
|
159
|
+
Create a grow-then-shrink instance provider over a sandbox provider.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
function createSandboxInstanceProvider(
|
|
163
|
+
options: SandboxInstanceOptions,
|
|
164
|
+
): InstanceProvider<SandboxInstance>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- `options` — The provider, the launch recipe and the gate.
|
|
168
|
+
|
|
169
|
+
**Returns:** An `InstanceProvider` over sandboxes.
|
|
170
|
+
|
|
171
|
+
### Constants
|
|
172
|
+
|
|
173
|
+
#### `DEFAULT_SANDBOX_READINESS_TIMEOUT_MS`
|
|
174
|
+
|
|
175
|
+
The default poll cadence for the bond's own readiness wait.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const DEFAULT_SANDBOX_READINESS_TIMEOUT_MS: 120000
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### `DEFAULT_SANDBOX_READINESS_POLL_MS`
|
|
182
|
+
|
|
183
|
+
The default per-probe budget.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const DEFAULT_SANDBOX_READINESS_POLL_MS: 2000
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Core Interface
|
|
190
|
+
|
|
191
|
+
Implements `@molecule/api-deploy-rollout` interface.
|
|
192
|
+
|
|
193
|
+
## Injection Notes
|
|
194
|
+
|
|
195
|
+
### Requirements
|
|
196
|
+
|
|
197
|
+
Peer dependencies:
|
|
198
|
+
|
|
199
|
+
- `@molecule/api-code-sandbox` ^1.0.0
|
|
200
|
+
- `@molecule/api-deploy-rollout` ^1.0.0
|
|
201
|
+
|
|
202
|
+
### Runtime Dependencies
|
|
203
|
+
|
|
204
|
+
- `@molecule/api-code-sandbox`
|
|
205
|
+
- `@molecule/api-deploy-rollout`
|
|
206
|
+
|
|
207
|
+
- **The launch recipe stays the deploy's.** Building, copying and booting an app
|
|
208
|
+
inside a sandbox is app knowledge; this bond never guesses it.
|
|
209
|
+
- **Readiness falls back.** `/health/ready` first, `/health` on 404/405, so an app
|
|
210
|
+
scaffolded before the lifecycle bond still gates correctly.
|
|
211
|
+
- **Drain is a SIGTERM**, bounded, through the sandbox's own exec channel.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser guard — `@molecule/api-deploy-rollout-sandbox` is SERVER-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
|
|
5
|
+
* Evaluating a server package in a browser bundle is always an import-graph mistake
|
|
6
|
+
* (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
|
|
7
|
+
* ("Buffer is not defined") far from the culprit. Throwing here names the package and
|
|
8
|
+
* the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
|
|
9
|
+
* unaffected: the throw requires browser globals AND the absence of a node runtime.
|
|
10
|
+
*/
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
|
|
13
|
+
throw new Error('@molecule/api-deploy-rollout-sandbox is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
|
|
14
|
+
'from server code (a server route/function or your API), or dynamic-import it inside ' +
|
|
15
|
+
'the server handler — never from components or shared client modules, and never ' +
|
|
16
|
+
'polyfill Buffer/process to silence this.');
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox provider bond for the deploy-rollout core.
|
|
3
|
+
*
|
|
4
|
+
* One adapter over `@molecule/api-code-sandbox`, so E2B, Docker and Fly sandboxes
|
|
5
|
+
* share one rolling-deploy implementation. The deploy supplies its launch recipe and
|
|
6
|
+
* readiness gate; the bond supplies the lifecycle.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { runRollout, setProvider } from '@molecule/api-deploy-rollout'
|
|
11
|
+
* import { provider } from '@molecule/api-deploy-rollout-default'
|
|
12
|
+
* import { createSandboxInstanceProvider } from '@molecule/api-deploy-rollout-sandbox'
|
|
13
|
+
*
|
|
14
|
+
* setProvider(provider)
|
|
15
|
+
* await runRollout({
|
|
16
|
+
* provider: createSandboxInstanceProvider({
|
|
17
|
+
* provider: sandboxProvider,
|
|
18
|
+
* launch: (index) => launchReplica(index),
|
|
19
|
+
* join: (instance) => upsertUpstream(instance.upstreamUrl ?? ''),
|
|
20
|
+
* }),
|
|
21
|
+
* current: oldInstances,
|
|
22
|
+
* policy: { replicas: 2 },
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - **The launch recipe stays the deploy's.** Building, copying and booting an app
|
|
28
|
+
* inside a sandbox is app knowledge; this bond never guesses it.
|
|
29
|
+
* - **Readiness falls back.** `/health/ready` first, `/health` on 404/405, so an app
|
|
30
|
+
* scaffolded before the lifecycle bond still gates correctly.
|
|
31
|
+
* - **Drain is a SIGTERM**, bounded, through the sandbox's own exec channel.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
export * from './browser-guard.js';
|
|
36
|
+
export * from './sandbox.js';
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox provider bond for the deploy-rollout core.
|
|
3
|
+
*
|
|
4
|
+
* One adapter over `@molecule/api-code-sandbox`, so E2B, Docker and Fly sandboxes
|
|
5
|
+
* share one rolling-deploy implementation. The deploy supplies its launch recipe and
|
|
6
|
+
* readiness gate; the bond supplies the lifecycle.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { runRollout, setProvider } from '@molecule/api-deploy-rollout'
|
|
11
|
+
* import { provider } from '@molecule/api-deploy-rollout-default'
|
|
12
|
+
* import { createSandboxInstanceProvider } from '@molecule/api-deploy-rollout-sandbox'
|
|
13
|
+
*
|
|
14
|
+
* setProvider(provider)
|
|
15
|
+
* await runRollout({
|
|
16
|
+
* provider: createSandboxInstanceProvider({
|
|
17
|
+
* provider: sandboxProvider,
|
|
18
|
+
* launch: (index) => launchReplica(index),
|
|
19
|
+
* join: (instance) => upsertUpstream(instance.upstreamUrl ?? ''),
|
|
20
|
+
* }),
|
|
21
|
+
* current: oldInstances,
|
|
22
|
+
* policy: { replicas: 2 },
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - **The launch recipe stays the deploy's.** Building, copying and booting an app
|
|
28
|
+
* inside a sandbox is app knowledge; this bond never guesses it.
|
|
29
|
+
* - **Readiness falls back.** `/health/ready` first, `/health` on 404/405, so an app
|
|
30
|
+
* scaffolded before the lifecycle bond still gates correctly.
|
|
31
|
+
* - **Drain is a SIGTERM**, bounded, through the sandbox's own exec channel.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
export * from './browser-guard.js';
|
|
36
|
+
export * from './sandbox.js';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox adapter for the deploy-rollout core.
|
|
3
|
+
*
|
|
4
|
+
* Implements the grow-then-shrink instance provider over
|
|
5
|
+
* `@molecule/api-code-sandbox`'s `SandboxProvider` — the seam molecule.dev's
|
|
6
|
+
* production deploy already uses (`requireProductionSandboxProvider()`), so ONE
|
|
7
|
+
* bond covers every sandbox backend: E2B, Docker, Fly, and any future provider.
|
|
8
|
+
*
|
|
9
|
+
* What the bond owns is the provider-independent lifecycle: create through the
|
|
10
|
+
* caller's launch recipe, gate on an HTTP readiness probe, join/leave the routable
|
|
11
|
+
* set, drain by SIGTERM through `sandbox.exec`, destroy through the provider. What
|
|
12
|
+
* it does NOT own is how the app is built and booted inside the sandbox — that is
|
|
13
|
+
* the deploy's recipe, passed in as `launch`.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import type { Sandbox, SandboxProvider } from '@molecule/api-code-sandbox';
|
|
18
|
+
import type { InstanceProvider, RolloutInstance } from '@molecule/api-deploy-rollout';
|
|
19
|
+
/** One sandbox instance plus the address the edge dials. */
|
|
20
|
+
export interface SandboxInstance extends RolloutInstance {
|
|
21
|
+
/** The live sandbox handle, when this run holds it. */
|
|
22
|
+
sandbox: Sandbox | null;
|
|
23
|
+
}
|
|
24
|
+
/** How a sandbox rollout reaches and gates one app's instances. */
|
|
25
|
+
export interface SandboxInstanceOptions {
|
|
26
|
+
/** The sandbox provider (E2B, Docker, Fly — any bonded provider). */
|
|
27
|
+
provider: SandboxProvider;
|
|
28
|
+
/**
|
|
29
|
+
* Create and start the instance at `index`, resolving once it exists. This is the
|
|
30
|
+
* deploy's own recipe (tree transfer, env, boot script); the bond never guesses
|
|
31
|
+
* it.
|
|
32
|
+
*/
|
|
33
|
+
launch: (index: number) => Promise<{
|
|
34
|
+
sandbox: Sandbox;
|
|
35
|
+
upstreamUrl: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* A BLOCKING readiness gate with the caller's own semantics and budget. When
|
|
39
|
+
* present, `waitReady` delegates to it. When absent, the bond polls
|
|
40
|
+
* `readinessProbe` until `readinessTimeoutMs` elapses.
|
|
41
|
+
*/
|
|
42
|
+
waitReady?: (instance: SandboxInstance) => Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* One HTTP readiness probe. Default: `GET <upstreamUrl>/health/ready`, falling
|
|
45
|
+
* back to `GET <upstreamUrl>/health` on 404/405 (an app scaffolded before the
|
|
46
|
+
* lifecycle bond answers only the latter).
|
|
47
|
+
*/
|
|
48
|
+
readinessProbe?: (instance: SandboxInstance) => Promise<boolean>;
|
|
49
|
+
/** How long the bond's own readiness poll may take. Defaults to 120 s. */
|
|
50
|
+
readinessTimeoutMs?: number;
|
|
51
|
+
/** Probe cadence for the bond's own readiness poll. Defaults to 2000 ms. */
|
|
52
|
+
readinessPollMs?: number;
|
|
53
|
+
/**
|
|
54
|
+
* The shell command that tells the app to drain. Defaults to a SIGTERM to the
|
|
55
|
+
* sandbox's node processes ({@link sigtermNodeProcessesCommand}).
|
|
56
|
+
*/
|
|
57
|
+
drainCommand?: string | ((drainMs: number) => string);
|
|
58
|
+
/** Add a ready instance to the caller's routable set. Default: no-op. */
|
|
59
|
+
join?: (instance: SandboxInstance) => Promise<void>;
|
|
60
|
+
/** Remove an instance from the caller's routable set. Default: no-op. */
|
|
61
|
+
leave?: (instance: SandboxInstance) => Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Enumerate this deployment's live instances, when the caller can. Used by the
|
|
64
|
+
* rollout's idempotent resume; omitted means "roll from the caller's set".
|
|
65
|
+
*/
|
|
66
|
+
list?: () => Promise<SandboxInstance[]>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A drain command that sends SIGTERM to the sandbox's node processes and waits,
|
|
70
|
+
* bounded, for them to exit.
|
|
71
|
+
*
|
|
72
|
+
* The lifecycle bond turns SIGTERM into "flip readiness to 503, finish in-flight
|
|
73
|
+
* requests, exit". An app without the bond ignores the signal and the rollout
|
|
74
|
+
* destroys it after the same bound — no worse than destroying it without a word.
|
|
75
|
+
*
|
|
76
|
+
* @param drainMs - How long to wait for those processes to exit.
|
|
77
|
+
* @returns The shell command.
|
|
78
|
+
*/
|
|
79
|
+
export declare const sigtermNodeProcessesCommand: (drainMs: number) => string;
|
|
80
|
+
/**
|
|
81
|
+
* One HTTP readiness look at an instance.
|
|
82
|
+
*
|
|
83
|
+
* `/health/ready` first; a 404 or 405 means the app predates the lifecycle bond, so
|
|
84
|
+
* `/health` is asked instead. Any other non-2xx answer is "not ready", and a
|
|
85
|
+
* transport failure is "not ready" too (the instance may still be booting).
|
|
86
|
+
*
|
|
87
|
+
* @param instance - The instance to probe.
|
|
88
|
+
* @param timeoutMs - Per-request budget. Defaults to 5000 ms.
|
|
89
|
+
* @returns Whether it answered ready.
|
|
90
|
+
*/
|
|
91
|
+
export declare const probeSandboxReadiness: (instance: SandboxInstance, timeoutMs?: number) => Promise<boolean>;
|
|
92
|
+
/** The default poll cadence for the bond's own readiness wait. */
|
|
93
|
+
export declare const DEFAULT_SANDBOX_READINESS_TIMEOUT_MS = 120000;
|
|
94
|
+
/** The default per-probe budget. */
|
|
95
|
+
export declare const DEFAULT_SANDBOX_READINESS_POLL_MS = 2000;
|
|
96
|
+
/**
|
|
97
|
+
* Create a grow-then-shrink instance provider over a sandbox provider.
|
|
98
|
+
*
|
|
99
|
+
* @param options - The provider, the launch recipe and the gate.
|
|
100
|
+
* @returns An `InstanceProvider` over sandboxes.
|
|
101
|
+
*/
|
|
102
|
+
export declare const createSandboxInstanceProvider: (options: SandboxInstanceOptions) => InstanceProvider<SandboxInstance>;
|
|
103
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAc,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAErF,4DAA4D;AAC5D,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,uDAAuD;IACvD,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CACxB;AAED,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,EAAE,eAAe,CAAA;IAEzB;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAE7E;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE3D;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEhE,0EAA0E;IAC1E,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAA;IAErD,yEAAyE;IACzE,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnD,yEAAyE;IACzE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpD;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC,CAAA;CACxC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,MAAM,KAAG,MAuB7D,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,eAAe,EACzB,kBAAiB,KAChB,OAAO,CAAC,OAAO,CAkBjB,CAAA;AAED,kEAAkE;AAClE,eAAO,MAAM,oCAAoC,SAAU,CAAA;AAE3D,oCAAoC;AACpC,eAAO,MAAM,iCAAiC,OAAQ,CAAA;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GACxC,SAAS,sBAAsB,KAC9B,gBAAgB,CAAC,eAAe,CAsDlC,CAAA"}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox adapter for the deploy-rollout core.
|
|
3
|
+
*
|
|
4
|
+
* Implements the grow-then-shrink instance provider over
|
|
5
|
+
* `@molecule/api-code-sandbox`'s `SandboxProvider` — the seam molecule.dev's
|
|
6
|
+
* production deploy already uses (`requireProductionSandboxProvider()`), so ONE
|
|
7
|
+
* bond covers every sandbox backend: E2B, Docker, Fly, and any future provider.
|
|
8
|
+
*
|
|
9
|
+
* What the bond owns is the provider-independent lifecycle: create through the
|
|
10
|
+
* caller's launch recipe, gate on an HTTP readiness probe, join/leave the routable
|
|
11
|
+
* set, drain by SIGTERM through `sandbox.exec`, destroy through the provider. What
|
|
12
|
+
* it does NOT own is how the app is built and booted inside the sandbox — that is
|
|
13
|
+
* the deploy's recipe, passed in as `launch`.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* A drain command that sends SIGTERM to the sandbox's node processes and waits,
|
|
19
|
+
* bounded, for them to exit.
|
|
20
|
+
*
|
|
21
|
+
* The lifecycle bond turns SIGTERM into "flip readiness to 503, finish in-flight
|
|
22
|
+
* requests, exit". An app without the bond ignores the signal and the rollout
|
|
23
|
+
* destroys it after the same bound — no worse than destroying it without a word.
|
|
24
|
+
*
|
|
25
|
+
* @param drainMs - How long to wait for those processes to exit.
|
|
26
|
+
* @returns The shell command.
|
|
27
|
+
*/
|
|
28
|
+
export const sigtermNodeProcessesCommand = (drainMs) => {
|
|
29
|
+
const seconds = Math.max(1, Math.ceil(drainMs / 1000));
|
|
30
|
+
return [
|
|
31
|
+
'for p in /proc/[0-9]*; do',
|
|
32
|
+
' c=$(tr "\\0" " " < "$p/cmdline" 2>/dev/null) || continue',
|
|
33
|
+
' case "$c" in',
|
|
34
|
+
' *node*) kill -TERM "${p#/proc/}" 2>/dev/null;;',
|
|
35
|
+
' esac',
|
|
36
|
+
'done',
|
|
37
|
+
'end=$(( $(date +%s) + ' + seconds + ' ))',
|
|
38
|
+
'while [ "$(date +%s)" -lt "$end" ]; do',
|
|
39
|
+
' alive=0',
|
|
40
|
+
' for p in /proc/[0-9]*; do',
|
|
41
|
+
' c=$(tr "\\0" " " < "$p/cmdline" 2>/dev/null) || continue',
|
|
42
|
+
' case "$c" in',
|
|
43
|
+
' *node*) alive=1;;',
|
|
44
|
+
' esac',
|
|
45
|
+
' done',
|
|
46
|
+
' [ "$alive" = 0 ] && break',
|
|
47
|
+
' sleep 1',
|
|
48
|
+
'done',
|
|
49
|
+
'exit 0',
|
|
50
|
+
].join('\n');
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* One HTTP readiness look at an instance.
|
|
54
|
+
*
|
|
55
|
+
* `/health/ready` first; a 404 or 405 means the app predates the lifecycle bond, so
|
|
56
|
+
* `/health` is asked instead. Any other non-2xx answer is "not ready", and a
|
|
57
|
+
* transport failure is "not ready" too (the instance may still be booting).
|
|
58
|
+
*
|
|
59
|
+
* @param instance - The instance to probe.
|
|
60
|
+
* @param timeoutMs - Per-request budget. Defaults to 5000 ms.
|
|
61
|
+
* @returns Whether it answered ready.
|
|
62
|
+
*/
|
|
63
|
+
export const probeSandboxReadiness = async (instance, timeoutMs = 5_000) => {
|
|
64
|
+
if (!instance.upstreamUrl)
|
|
65
|
+
return false;
|
|
66
|
+
const base = instance.upstreamUrl.replace(/\/+$/, '');
|
|
67
|
+
for (const path of ['/health/ready', '/health']) {
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetch(`${base}${path}`, {
|
|
70
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
71
|
+
});
|
|
72
|
+
if (response.ok)
|
|
73
|
+
return true;
|
|
74
|
+
if (path === '/health/ready' && (response.status === 404 || response.status === 405))
|
|
75
|
+
continue;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
catch (_error) {
|
|
79
|
+
// A transport failure is "not ready yet", never a crash: the instance is
|
|
80
|
+
// booting and the next poll is the health look that settles it.
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
/** The default poll cadence for the bond's own readiness wait. */
|
|
87
|
+
export const DEFAULT_SANDBOX_READINESS_TIMEOUT_MS = 120_000;
|
|
88
|
+
/** The default per-probe budget. */
|
|
89
|
+
export const DEFAULT_SANDBOX_READINESS_POLL_MS = 2_000;
|
|
90
|
+
/**
|
|
91
|
+
* Create a grow-then-shrink instance provider over a sandbox provider.
|
|
92
|
+
*
|
|
93
|
+
* @param options - The provider, the launch recipe and the gate.
|
|
94
|
+
* @returns An `InstanceProvider` over sandboxes.
|
|
95
|
+
*/
|
|
96
|
+
export const createSandboxInstanceProvider = (options) => {
|
|
97
|
+
const readinessProbe = options.readinessProbe ??
|
|
98
|
+
((instance) => probeSandboxReadiness(instance));
|
|
99
|
+
const provider = {
|
|
100
|
+
name: `sandbox:${options.provider.name}`,
|
|
101
|
+
create: async (index) => {
|
|
102
|
+
const launched = await options.launch(index);
|
|
103
|
+
return {
|
|
104
|
+
id: launched.sandbox.id,
|
|
105
|
+
upstreamUrl: launched.upstreamUrl,
|
|
106
|
+
sandbox: launched.sandbox,
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
waitReady: async (instance, timeoutMs) => {
|
|
110
|
+
if (options.waitReady)
|
|
111
|
+
return options.waitReady(instance);
|
|
112
|
+
const budget = Math.max(0, timeoutMs ?? options.readinessTimeoutMs ?? DEFAULT_SANDBOX_READINESS_TIMEOUT_MS);
|
|
113
|
+
const pollMs = Math.max(1, options.readinessPollMs ?? DEFAULT_SANDBOX_READINESS_POLL_MS);
|
|
114
|
+
for (let waited = 0; waited <= budget; waited += pollMs) {
|
|
115
|
+
if (await readinessProbe(instance))
|
|
116
|
+
return true;
|
|
117
|
+
await new Promise((resolve) => {
|
|
118
|
+
setTimeout(resolve, pollMs);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
},
|
|
123
|
+
isServing: (instance) => readinessProbe(instance),
|
|
124
|
+
join: async (instance) => options.join?.(instance),
|
|
125
|
+
leave: async (instance) => options.leave?.(instance),
|
|
126
|
+
drain: async (instance, drainMs) => {
|
|
127
|
+
if (drainMs <= 0 || !instance.sandbox)
|
|
128
|
+
return;
|
|
129
|
+
const command = typeof options.drainCommand === 'function'
|
|
130
|
+
? options.drainCommand(drainMs)
|
|
131
|
+
: (options.drainCommand ?? sigtermNodeProcessesCommand(drainMs));
|
|
132
|
+
const result = await instance.sandbox.exec(command, {
|
|
133
|
+
timeout: drainMs + 15_000,
|
|
134
|
+
});
|
|
135
|
+
if (result.exitCode !== 0) {
|
|
136
|
+
throw new Error(`drain command exited ${result.exitCode}: ${result.stderr.trim().slice(0, 200)}`);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
destroy: async (instance) => {
|
|
140
|
+
await options.provider.destroy(instance.id);
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
if (options.list)
|
|
144
|
+
provider.list = options.list;
|
|
145
|
+
return provider;
|
|
146
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-deploy-rollout-sandbox",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Sandbox provider bond for @molecule/api-deploy-rollout: grow-then-shrink rolling deploys over any @molecule/api-code-sandbox provider (E2B, Docker, Fly).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc --watch",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"test:coverage": "vitest run --coverage"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"molecule",
|
|
27
|
+
"deploy",
|
|
28
|
+
"rollout",
|
|
29
|
+
"sandbox",
|
|
30
|
+
"e2b",
|
|
31
|
+
"docker"
|
|
32
|
+
],
|
|
33
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
34
|
+
"license": "Apache-2.0",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@molecule/api-code-sandbox": "^1.0.0",
|
|
40
|
+
"@molecule/api-deploy-rollout": "^1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@molecule/api-code-sandbox": "1.4.0",
|
|
44
|
+
"@molecule/api-deploy-rollout": "1.1.0",
|
|
45
|
+
"@types/node": "26.1.2",
|
|
46
|
+
"typescript": "6.0.3",
|
|
47
|
+
"vitest": "4.1.11"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
52
|
+
"directory": "packages/api/bonds/deploy-rollout/sandbox"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://www.molecule.dev/packages/api-deploy-rollout-sandbox",
|
|
55
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|