@colony2/jobdb 0.0.1 → 0.0.8
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 +184 -0
- package/README.md +139 -0
- package/install.js +6 -0
- package/lib.js +259 -0
- package/package.json +88 -9
- package/run-jobdb.js +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
36
|
+
below).
|
|
37
|
+
|
|
38
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
39
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
40
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
41
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
42
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
43
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
44
|
+
|
|
45
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
46
|
+
version of the Work and any modifications or additions to that Work or
|
|
47
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
48
|
+
inclusion in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes of this
|
|
50
|
+
definition, "submitted" means any form of electronic, verbal, or written
|
|
51
|
+
communication sent to the Licensor or its representatives, including but not
|
|
52
|
+
limited to communication on electronic mailing lists, source code control
|
|
53
|
+
systems, and issue tracking systems that are managed by, or on behalf of, the
|
|
54
|
+
Licensor for the purpose of discussing and improving the Work, but excluding
|
|
55
|
+
communication that is conspicuously marked or otherwise designated in writing by
|
|
56
|
+
the copyright owner as "Not a Contribution."
|
|
57
|
+
|
|
58
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
59
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
60
|
+
incorporated within the Work.
|
|
61
|
+
|
|
62
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
63
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
64
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
65
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
66
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
67
|
+
Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
70
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
71
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
72
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
73
|
+
transfer the Work, where such license applies only to those patent claims
|
|
74
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
75
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
|
76
|
+
which such Contribution(s) was submitted. If You institute patent litigation
|
|
77
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
78
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
79
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
80
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
81
|
+
such litigation is filed.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
84
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
85
|
+
Source or Object form, provided that You meet the following conditions:
|
|
86
|
+
|
|
87
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
88
|
+
this License; and
|
|
89
|
+
|
|
90
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
91
|
+
You changed the files; and
|
|
92
|
+
|
|
93
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
94
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
95
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
96
|
+
of the Derivative Works; and
|
|
97
|
+
|
|
98
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
99
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
106
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
|
|
112
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
113
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
114
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
115
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
116
|
+
with the conditions stated in this License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
119
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
120
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
121
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
122
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
123
|
+
executed with Licensor regarding such Contributions.
|
|
124
|
+
|
|
125
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
126
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
127
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
128
|
+
reproducing the content of the NOTICE file.
|
|
129
|
+
|
|
130
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
131
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
132
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
133
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
134
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
135
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
136
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
137
|
+
associated with Your exercise of permissions under this License.
|
|
138
|
+
|
|
139
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
140
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
141
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
142
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
143
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
144
|
+
arising as a result of this License or out of the use or inability to use the
|
|
145
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
146
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
147
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
148
|
+
damages.
|
|
149
|
+
|
|
150
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
151
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
152
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
153
|
+
and/or rights consistent with this License. However, in accepting such
|
|
154
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
155
|
+
responsibility, not on behalf of any other Contributor, and only if You agree to
|
|
156
|
+
indemnify, defend, and hold each Contributor harmless for any liability incurred
|
|
157
|
+
by, or claims asserted against, such Contributor by reason of your accepting any
|
|
158
|
+
such warranty or additional liability.
|
|
159
|
+
|
|
160
|
+
END OF TERMS AND CONDITIONS
|
|
161
|
+
|
|
162
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
163
|
+
|
|
164
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
165
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
166
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
167
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
168
|
+
recommend that a file or class name and description of purpose be included on
|
|
169
|
+
the same "printed page" as the copyright notice for easier identification within
|
|
170
|
+
third-party archives.
|
|
171
|
+
|
|
172
|
+
Copyright [yyyy] [name of copyright owner]
|
|
173
|
+
|
|
174
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
175
|
+
you may not use this file except in compliance with the License.
|
|
176
|
+
You may obtain a copy of the License at
|
|
177
|
+
|
|
178
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
179
|
+
|
|
180
|
+
Unless required by applicable law or agreed to in writing, software
|
|
181
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
182
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
183
|
+
See the License for the specific language governing permissions and
|
|
184
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# jobdb
|
|
2
|
+
|
|
3
|
+
`jobdb` is a runtime server for durable jobs. The installed `jobdb` command
|
|
4
|
+
serves the JobDB runtime REST API over HTTP using one of the available storage
|
|
5
|
+
backends.
|
|
6
|
+
|
|
7
|
+
Use the server when you want a standalone runtime process that workers and other
|
|
8
|
+
clients can talk to over the remote runtime protocol.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install the CLI with npm:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g @colony2/jobdb
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Verify the command is available:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
jobdb --help
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
Run the default SQLite-backed server:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
jobdb --listen 127.0.0.1:9047 --db jobdb.db
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This starts the runtime API at `http://127.0.0.1:9047`. SQLite is the default
|
|
33
|
+
backend and persists runtime state in `jobdb.db`; large artifacts are stored in a
|
|
34
|
+
blob directory that defaults to `<db>.blobs`.
|
|
35
|
+
|
|
36
|
+
The explicit SQLite subcommand is equivalent:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
jobdb sqlite --listen 127.0.0.1:9047 --db jobdb.db
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Stop the server with `Ctrl-C` or `SIGTERM`; the command shuts the HTTP server
|
|
43
|
+
down before closing backend resources.
|
|
44
|
+
|
|
45
|
+
## Backend Options
|
|
46
|
+
|
|
47
|
+
### SQLite
|
|
48
|
+
|
|
49
|
+
SQLite is the default embedded durable backend.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
jobdb sqlite \
|
|
53
|
+
--listen 127.0.0.1:9047 \
|
|
54
|
+
--db ./jobdb.db \
|
|
55
|
+
--blob-dir ./jobdb.blobs
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Flags:
|
|
59
|
+
|
|
60
|
+
- `--db`: SQLite database path. Defaults to `jobdb.db`.
|
|
61
|
+
- `--blob-dir`: directory for large artifacts. Defaults to `<db>.blobs`.
|
|
62
|
+
- `--sqlite-dsn`: SQLite DSN. Overrides `--db` and `JOBDB_SQLITE_DSN`.
|
|
63
|
+
- `--listen`: HTTP listen address. Defaults to `127.0.0.1:9047`.
|
|
64
|
+
|
|
65
|
+
Environment:
|
|
66
|
+
|
|
67
|
+
- `JOBDB_SQLITE_DSN`: SQLite DSN used when `--sqlite-dsn` is not set.
|
|
68
|
+
|
|
69
|
+
### Toy
|
|
70
|
+
|
|
71
|
+
The toy backend is in-memory. It is useful for local experiments and tests, not
|
|
72
|
+
for durable execution.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
jobdb toy --listen 127.0.0.1:9047
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Direct
|
|
79
|
+
|
|
80
|
+
The direct backend uses Postgres-backed `pgwf` for job state and an embedded
|
|
81
|
+
Strata daemon for chapter and artifact storage. It installs or verifies the
|
|
82
|
+
`pgwf` schema on startup.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
JOBDB_POSTGRES_DSN='postgres://user:pass@localhost:5432/jobdb?sslmode=disable' \
|
|
86
|
+
jobdb direct --listen 127.0.0.1:9047
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Flags:
|
|
90
|
+
|
|
91
|
+
- `--postgres-dsn`: Postgres DSN for `pgwf` state.
|
|
92
|
+
- `--listen`: HTTP listen address. Defaults to `127.0.0.1:9047`.
|
|
93
|
+
|
|
94
|
+
Environment:
|
|
95
|
+
|
|
96
|
+
- `JOBDB_POSTGRES_DSN`: Postgres DSN used when `--postgres-dsn` is not set.
|
|
97
|
+
|
|
98
|
+
## Runtime API
|
|
99
|
+
|
|
100
|
+
The server exposes the JobDB runtime REST API. The wire contract is documented
|
|
101
|
+
in [openapi/jobdb-runtime.yaml](openapi/jobdb-runtime.yaml).
|
|
102
|
+
|
|
103
|
+
Go clients normally use the remote runtime adapter:
|
|
104
|
+
|
|
105
|
+
```go
|
|
106
|
+
runtime, err := remoteruntime.New("http://127.0.0.1:9047", nil)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
See [pkg/jobdb/README.md](pkg/jobdb/README.md) for the Go runtime API, data
|
|
110
|
+
types, and runtime package reference.
|
|
111
|
+
|
|
112
|
+
## Go Workflow Workers
|
|
113
|
+
|
|
114
|
+
Workflow workers are intentionally documented separately from the server. If you
|
|
115
|
+
are writing job workers, task workers, or a process that runs worker loops, use
|
|
116
|
+
the `pkg/workflow` package.
|
|
117
|
+
|
|
118
|
+
See [pkg/workflow/README.md](pkg/workflow/README.md).
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
The CLI source lives in `cmd/jobdb`. To run it directly from a checkout:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
go run ./cmd/jobdb --listen 127.0.0.1:9047 --db jobdb.db
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Run the full test suite:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
go test ./...
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Useful references:
|
|
135
|
+
|
|
136
|
+
- [pkg/jobdb/README.md](pkg/jobdb/README.md): runtime API, data types, and backend packages.
|
|
137
|
+
- [pkg/workflow/README.md](pkg/workflow/README.md): workflow SDK, workers, and engines.
|
|
138
|
+
- [docs/API-SURFACE.md](docs/API-SURFACE.md): supported public packages.
|
|
139
|
+
- [docs/SPEC-OpenAPI-Runtime-Contract.md](docs/SPEC-OpenAPI-Runtime-Contract.md): runtime REST contract notes.
|
package/install.js
ADDED
package/lib.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// This file was generated by GoReleaser. DO NOT EDIT.
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import http from "http";
|
|
5
|
+
import https from "https";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import JSZip from "jszip";
|
|
8
|
+
import { x as tarExtract } from "tar";
|
|
9
|
+
import { ProxyAgent } from "proxy-agent";
|
|
10
|
+
import { spawnSync } from "child_process";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
|
|
13
|
+
const { archives, name, version } = JSON.parse(
|
|
14
|
+
fs.readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const agent = new ProxyAgent();
|
|
18
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
|
|
20
|
+
const getArchive = () => {
|
|
21
|
+
let target = `${process.platform}-${process.arch}`;
|
|
22
|
+
const archive = archives[target];
|
|
23
|
+
if (!archive) {
|
|
24
|
+
throw new Error(`No archive available for ${target}`);
|
|
25
|
+
}
|
|
26
|
+
return archive;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const binDir = path.join(__dirname, "bin");
|
|
30
|
+
|
|
31
|
+
async function extractTar(tarPath, binaries, dir, wrappedIn) {
|
|
32
|
+
try {
|
|
33
|
+
const filesToExtract = wrappedIn
|
|
34
|
+
? binaries.map((bin) =>
|
|
35
|
+
path.join(wrappedIn, bin).replace(/\\/g, "/"),
|
|
36
|
+
)
|
|
37
|
+
: binaries;
|
|
38
|
+
|
|
39
|
+
await tarExtract({
|
|
40
|
+
file: tarPath,
|
|
41
|
+
cwd: dir,
|
|
42
|
+
filter: (path) => filesToExtract.includes(path),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// If wrapped, move files from wrapped directory to bin directory
|
|
46
|
+
if (wrappedIn) {
|
|
47
|
+
const wrappedDir = path.join(dir, wrappedIn);
|
|
48
|
+
for (const binary of binaries) {
|
|
49
|
+
const srcPath = path.join(wrappedDir, binary);
|
|
50
|
+
const destPath = path.join(dir, binary);
|
|
51
|
+
if (fs.existsSync(srcPath)) {
|
|
52
|
+
fs.renameSync(srcPath, destPath);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Clean up empty wrapped directory
|
|
56
|
+
try {
|
|
57
|
+
fs.rmSync(wrappedDir, { recursive: true, force: true });
|
|
58
|
+
} catch (err) {
|
|
59
|
+
// Ignore cleanup errors
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log(`Successfully extracted ${binaries} to "${dir}"`);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
throw new Error(`Extraction failed: ${err.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function extractZip(zipPath, binaries, dir, wrappedIn) {
|
|
70
|
+
try {
|
|
71
|
+
const zipData = fs.readFileSync(zipPath);
|
|
72
|
+
const zip = await JSZip.loadAsync(zipData);
|
|
73
|
+
|
|
74
|
+
for (const binary of binaries) {
|
|
75
|
+
const binaryPath = wrappedIn
|
|
76
|
+
? path.join(wrappedIn, binary).replace(/\\/g, "/")
|
|
77
|
+
: binary;
|
|
78
|
+
|
|
79
|
+
if (!zip.files[binaryPath]) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Error: ${binaryPath} does not exist in ${zipPath}`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const content = await zip.files[binaryPath].async("nodebuffer");
|
|
86
|
+
if (!fs.existsSync(dir)) {
|
|
87
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
const file = path.join(dir, binary);
|
|
90
|
+
fs.writeFileSync(file, content);
|
|
91
|
+
fs.chmodSync(file, "755");
|
|
92
|
+
console.log(`Successfully extracted "${binary}" to "${dir}"`);
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
throw new Error(`Extraction failed: ${err.message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const run = async (bin) => {
|
|
100
|
+
await install();
|
|
101
|
+
if (process.platform === "win32") {
|
|
102
|
+
bin += ".exe";
|
|
103
|
+
}
|
|
104
|
+
const [, , ...args] = process.argv;
|
|
105
|
+
let result = spawnSync(path.join(binDir, bin), args, {
|
|
106
|
+
cwd: process.cwd(),
|
|
107
|
+
stdio: "inherit",
|
|
108
|
+
});
|
|
109
|
+
if (result.error) {
|
|
110
|
+
console.error(result.error);
|
|
111
|
+
}
|
|
112
|
+
return result.status;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const install = async () => {
|
|
116
|
+
try {
|
|
117
|
+
let archive = getArchive();
|
|
118
|
+
if (await exists(archive)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let tmp = fs.mkdtempSync("archive-");
|
|
122
|
+
let archivePath = path.join(tmp, archive.name);
|
|
123
|
+
await download(archive.url, archivePath);
|
|
124
|
+
verify(archivePath, archive.checksum);
|
|
125
|
+
|
|
126
|
+
if (!fs.existsSync(binDir)) {
|
|
127
|
+
fs.mkdirSync(binDir);
|
|
128
|
+
}
|
|
129
|
+
switch (archive.format) {
|
|
130
|
+
case "binary":
|
|
131
|
+
const bin = path.join(binDir, archive.bins[0]);
|
|
132
|
+
fs.copyFileSync(archivePath, bin);
|
|
133
|
+
fs.chmodSync(bin, 0o755);
|
|
134
|
+
break;
|
|
135
|
+
case "zip":
|
|
136
|
+
await extractZip(
|
|
137
|
+
archivePath,
|
|
138
|
+
archive.bins,
|
|
139
|
+
binDir,
|
|
140
|
+
archive.wrappedIn,
|
|
141
|
+
);
|
|
142
|
+
break;
|
|
143
|
+
case "tar":
|
|
144
|
+
case "tar.gz":
|
|
145
|
+
case "tgz":
|
|
146
|
+
await extractTar(
|
|
147
|
+
archivePath,
|
|
148
|
+
archive.bins,
|
|
149
|
+
binDir,
|
|
150
|
+
archive.wrappedIn,
|
|
151
|
+
);
|
|
152
|
+
break;
|
|
153
|
+
case "tar.zst":
|
|
154
|
+
case "tzst":
|
|
155
|
+
case "tar.xz":
|
|
156
|
+
case "txz":
|
|
157
|
+
default:
|
|
158
|
+
throw new Error(`unsupported format: ${archive.format}`);
|
|
159
|
+
}
|
|
160
|
+
console.log(`Installed ${name} ${version} to ${binDir}`);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
throw new Error(`Installation failed: ${err.message}`);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const verify = (filename, checksum) => {
|
|
167
|
+
if (checksum.algorithm == "" || checksum.digest == "") {
|
|
168
|
+
console.warn("Warning: No checksum provided for verification");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
let digest = crypto
|
|
172
|
+
.createHash(checksum.algorithm)
|
|
173
|
+
.update(fs.readFileSync(filename))
|
|
174
|
+
.digest("hex");
|
|
175
|
+
if (digest != checksum.digest) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`${filename}: ${checksum.algorithm} does not match, expected ${checksum.digest}, got ${digest}`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const download = async (url, filename, maxRedirects = 10) => {
|
|
183
|
+
try {
|
|
184
|
+
console.log(`Downloading ${url} to ${filename}...`);
|
|
185
|
+
const dir = path.dirname(filename);
|
|
186
|
+
if (!fs.existsSync(dir)) {
|
|
187
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
const parsedUrl = new URL(url);
|
|
192
|
+
const mod = parsedUrl.protocol === "https:" ? https : http;
|
|
193
|
+
|
|
194
|
+
const request = mod.get(url, { agent }, (response) => {
|
|
195
|
+
if (
|
|
196
|
+
response.statusCode >= 300 &&
|
|
197
|
+
response.statusCode < 400 &&
|
|
198
|
+
response.headers.location
|
|
199
|
+
) {
|
|
200
|
+
if (maxRedirects <= 0) {
|
|
201
|
+
reject(new Error("Too many redirects"));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
download(response.headers.location, filename, maxRedirects - 1)
|
|
205
|
+
.then(resolve)
|
|
206
|
+
.catch(reject);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (response.statusCode !== 200) {
|
|
211
|
+
reject(
|
|
212
|
+
new Error(
|
|
213
|
+
`HTTP ${response.statusCode}: ${response.statusMessage}`,
|
|
214
|
+
),
|
|
215
|
+
);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const writer = fs.createWriteStream(filename);
|
|
220
|
+
response.pipe(writer);
|
|
221
|
+
|
|
222
|
+
writer.on("finish", () => {
|
|
223
|
+
console.log(`Download complete: ${filename}`);
|
|
224
|
+
resolve(dir);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
writer.on("error", (err) => {
|
|
228
|
+
console.error(`Error writing file: ${err.message}`);
|
|
229
|
+
reject(err);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
request.on("error", (err) => {
|
|
234
|
+
reject(new Error(`Request failed: ${err.message}`));
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
request.setTimeout(300000, () => {
|
|
238
|
+
request.destroy();
|
|
239
|
+
reject(new Error("Request timed out"));
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
} catch (err) {
|
|
243
|
+
throw new Error(`Download failed: ${err.message}`);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
function exists(archive) {
|
|
248
|
+
if (!fs.existsSync(binDir)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return archive.bins.every((bin) => fs.existsSync(path.join(binDir, bin)));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export {
|
|
255
|
+
install,
|
|
256
|
+
run,
|
|
257
|
+
getArchive,
|
|
258
|
+
download,
|
|
259
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colony2/jobdb",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.8",
|
|
5
|
+
"description": "jobdb job system",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"postinstall": "node install.js",
|
|
8
|
+
"run": "node run-jobdb.js"
|
|
8
9
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/colony-2/jobdb.git"
|
|
13
|
+
},
|
|
14
|
+
"author": {
|
|
15
|
+
"email": "noreply@colony2.com",
|
|
16
|
+
"name": "Colony 2"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/colony-2/jobdb/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/colony-2/jobdb",
|
|
23
|
+
"bin": {
|
|
24
|
+
"jobdb": "run-jobdb.js"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"jszip": "3.10.1",
|
|
28
|
+
"proxy-agent": "8.0.1",
|
|
29
|
+
"tar": "7.5.15"
|
|
30
|
+
},
|
|
31
|
+
"archives": {
|
|
32
|
+
"darwin-arm64": {
|
|
33
|
+
"name": "jobdb_0.0.8_Darwin_arm64.tar.gz",
|
|
34
|
+
"url": "https://github.com/colony-2/jobdb/releases/download/v0.0.8/jobdb_0.0.8_Darwin_arm64.tar.gz",
|
|
35
|
+
"bins": [
|
|
36
|
+
"jobdb"
|
|
37
|
+
],
|
|
38
|
+
"format": "tar.gz",
|
|
39
|
+
"checksum": {
|
|
40
|
+
"algorithm": "sha256",
|
|
41
|
+
"digest": "480b53c0d81c78097f412e4436059cab1098c67e7ce3448838d276895db8a68b"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"darwin-x64": {
|
|
45
|
+
"name": "jobdb_0.0.8_Darwin_x86_64.tar.gz",
|
|
46
|
+
"url": "https://github.com/colony-2/jobdb/releases/download/v0.0.8/jobdb_0.0.8_Darwin_x86_64.tar.gz",
|
|
47
|
+
"bins": [
|
|
48
|
+
"jobdb"
|
|
49
|
+
],
|
|
50
|
+
"format": "tar.gz",
|
|
51
|
+
"checksum": {
|
|
52
|
+
"algorithm": "sha256",
|
|
53
|
+
"digest": "558e930d85bdb9b7599a6e67f546015e063ff969c681c9717ad6a7a13c50b63c"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"linux-arm64": {
|
|
57
|
+
"name": "jobdb_0.0.8_Linux_arm64.tar.gz",
|
|
58
|
+
"url": "https://github.com/colony-2/jobdb/releases/download/v0.0.8/jobdb_0.0.8_Linux_arm64.tar.gz",
|
|
59
|
+
"bins": [
|
|
60
|
+
"jobdb"
|
|
61
|
+
],
|
|
62
|
+
"format": "tar.gz",
|
|
63
|
+
"checksum": {
|
|
64
|
+
"algorithm": "sha256",
|
|
65
|
+
"digest": "89a52c995a080fb86357fc030378d7b1d402b8be1a69c32e368ae105058b68fc"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"linux-x64": {
|
|
69
|
+
"name": "jobdb_0.0.8_Linux_x86_64.tar.gz",
|
|
70
|
+
"url": "https://github.com/colony-2/jobdb/releases/download/v0.0.8/jobdb_0.0.8_Linux_x86_64.tar.gz",
|
|
71
|
+
"bins": [
|
|
72
|
+
"jobdb"
|
|
73
|
+
],
|
|
74
|
+
"format": "tar.gz",
|
|
75
|
+
"checksum": {
|
|
76
|
+
"algorithm": "sha256",
|
|
77
|
+
"digest": "d8406e066f086dd6890d3f5e143cc5135d5d2dfa2fa18f1b37f2fb3bfe4e1611"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"engines": {
|
|
82
|
+
"node": "\u003e=14.0.0"
|
|
83
|
+
},
|
|
84
|
+
"keywords": [
|
|
85
|
+
"sandbox",
|
|
86
|
+
"docker",
|
|
87
|
+
"ai",
|
|
88
|
+
"agent",
|
|
89
|
+
"cli",
|
|
90
|
+
"security"
|
|
91
|
+
]
|
|
92
|
+
}
|