@dagger.io/dagger 0.2.1 → 0.3.1

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.
Files changed (81) hide show
  1. package/README.md +72 -1
  2. package/dist/api/client.gen.d.ts +332 -126
  3. package/dist/api/client.gen.d.ts.map +1 -1
  4. package/dist/api/client.gen.js +355 -272
  5. package/dist/api/utils.d.ts +1 -1
  6. package/dist/api/utils.d.ts.map +1 -1
  7. package/dist/api/utils.js +63 -43
  8. package/dist/common/errors/DaggerSDKError.d.ts +32 -0
  9. package/dist/common/errors/DaggerSDKError.d.ts.map +1 -0
  10. package/dist/common/errors/DaggerSDKError.js +22 -0
  11. package/dist/common/errors/DockerImageRefValidationError.d.ts +22 -0
  12. package/dist/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
  13. package/dist/common/errors/DockerImageRefValidationError.js +17 -0
  14. package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
  15. package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
  16. package/dist/common/errors/EngineSessionConnectParamsParseError.js +16 -0
  17. package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
  18. package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
  19. package/dist/common/errors/EngineSessionConnectionTimeoutError.js +16 -0
  20. package/dist/common/errors/EngineSessionEOFErrorOptions.d.ts +16 -0
  21. package/dist/common/errors/EngineSessionEOFErrorOptions.d.ts.map +1 -0
  22. package/dist/common/errors/EngineSessionEOFErrorOptions.js +16 -0
  23. package/dist/common/errors/GraphQLRequestError.d.ts +27 -0
  24. package/dist/common/errors/GraphQLRequestError.d.ts.map +1 -0
  25. package/dist/common/errors/GraphQLRequestError.js +17 -0
  26. package/dist/common/errors/InitEngineSessionBinaryError.d.ts +13 -0
  27. package/dist/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -0
  28. package/dist/common/errors/InitEngineSessionBinaryError.js +15 -0
  29. package/dist/common/errors/TooManyNestedObjectsError.d.ts +21 -0
  30. package/dist/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
  31. package/dist/common/errors/TooManyNestedObjectsError.js +16 -0
  32. package/dist/common/errors/UnknownDaggerError.d.ts +13 -0
  33. package/dist/common/errors/UnknownDaggerError.d.ts.map +1 -0
  34. package/dist/common/errors/UnknownDaggerError.js +15 -0
  35. package/dist/common/errors/errors-codes.d.ts +43 -0
  36. package/dist/common/errors/errors-codes.d.ts.map +1 -0
  37. package/dist/common/errors/errors-codes.js +35 -0
  38. package/dist/common/errors/index.d.ts +11 -0
  39. package/dist/common/errors/index.d.ts.map +1 -0
  40. package/dist/common/errors/index.js +10 -0
  41. package/dist/common/utils.d.ts +65 -0
  42. package/dist/common/utils.d.ts.map +1 -0
  43. package/dist/common/utils.js +2 -0
  44. package/dist/connect.d.ts +25 -3
  45. package/dist/connect.d.ts.map +1 -1
  46. package/dist/connect.js +29 -5
  47. package/dist/index.d.ts +1 -2
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +0 -1
  50. package/dist/provisioning/{docker-provision/image.d.ts → bin.d.ts} +31 -29
  51. package/dist/provisioning/bin.d.ts.map +1 -0
  52. package/dist/provisioning/bin.js +328 -0
  53. package/dist/provisioning/default.d.ts +1 -1
  54. package/dist/provisioning/default.d.ts.map +1 -1
  55. package/dist/provisioning/default.js +1 -2
  56. package/dist/provisioning/engineconn.d.ts +1 -1
  57. package/dist/provisioning/engineconn.d.ts.map +1 -1
  58. package/dist/provisioning/index.d.ts +1 -2
  59. package/dist/provisioning/index.d.ts.map +1 -1
  60. package/dist/provisioning/index.js +1 -2
  61. package/package.json +19 -15
  62. package/dist/provisioning/bin/bin.d.ts +0 -21
  63. package/dist/provisioning/bin/bin.d.ts.map +0 -1
  64. package/dist/provisioning/bin/bin.js +0 -112
  65. package/dist/provisioning/bin/index.d.ts +0 -2
  66. package/dist/provisioning/bin/index.d.ts.map +0 -1
  67. package/dist/provisioning/bin/index.js +0 -1
  68. package/dist/provisioning/docker-provision/image.d.ts.map +0 -1
  69. package/dist/provisioning/docker-provision/image.js +0 -269
  70. package/dist/provisioning/docker-provision/index.d.ts +0 -2
  71. package/dist/provisioning/docker-provision/index.d.ts.map +0 -1
  72. package/dist/provisioning/docker-provision/index.js +0 -1
  73. package/dist/provisioning/http/http.d.ts +0 -14
  74. package/dist/provisioning/http/http.d.ts.map +0 -1
  75. package/dist/provisioning/http/http.js +0 -33
  76. package/dist/provisioning/http/index.d.ts +0 -2
  77. package/dist/provisioning/http/index.d.ts.map +0 -1
  78. package/dist/provisioning/http/index.js +0 -1
  79. package/dist/provisioning/provisioner.d.ts +0 -11
  80. package/dist/provisioning/provisioner.d.ts.map +0 -1
  81. package/dist/provisioning/provisioner.js +0 -26
@@ -0,0 +1,328 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
11
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
+ var m = o[Symbol.asyncIterator], i;
13
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
14
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
+ };
17
+ import AdmZip from "adm-zip";
18
+ import * as crypto from "crypto";
19
+ import envPaths from "env-paths";
20
+ import { execaCommand } from "execa";
21
+ import * as fs from "fs";
22
+ import fetch from "node-fetch";
23
+ import * as os from "os";
24
+ import * as path from "path";
25
+ import readline from "readline";
26
+ import * as tar from "tar";
27
+ import Client from "../api/client.gen.js";
28
+ import { EngineSessionConnectionTimeoutError, EngineSessionConnectParamsParseError, EngineSessionEOFError, InitEngineSessionBinaryError, } from "../common/errors/index.js";
29
+ const CLI_HOST = "dl.dagger.io";
30
+ let OVERRIDE_CLI_URL;
31
+ let OVERRIDE_CHECKSUMS_URL;
32
+ /**
33
+ * Bin runs an engine session from a specified binary
34
+ */
35
+ export class Bin {
36
+ constructor(binPath, cliVersion) {
37
+ this.cacheDir = envPaths("dagger", { suffix: "" }).cache;
38
+ this.DAGGER_CLI_BIN_PREFIX = "dagger";
39
+ this.binPath = binPath;
40
+ this.cliVersion = cliVersion;
41
+ }
42
+ Addr() {
43
+ return "http://dagger";
44
+ }
45
+ Connect(opts) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ if (!this.binPath) {
48
+ this.binPath = yield this.downloadCLI();
49
+ }
50
+ return this.runEngineSession(this.binPath, opts);
51
+ });
52
+ }
53
+ downloadCLI() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ if (!this.cliVersion) {
56
+ throw new Error("cliVersion is not set");
57
+ }
58
+ const binPath = this.buildBinPath();
59
+ // Create a temporary bin file path
60
+ this.createCacheDir();
61
+ const tmpBinDownloadDir = fs.mkdtempSync(path.join(this.cacheDir, `temp-${this.getRandomId()}`));
62
+ const tmpBinPath = path.join(tmpBinDownloadDir, "dagger");
63
+ try {
64
+ // download an archive and use appropriate extraction depending on platforms (zip on windows, tar.gz on other platforms)
65
+ const actualChecksum = yield this.extractArchive(tmpBinDownloadDir, this.normalizedOS());
66
+ const expectedChecksum = yield this.expectedChecksum();
67
+ if (actualChecksum !== expectedChecksum) {
68
+ throw new Error(`checksum mismatch: expected ${expectedChecksum}, got ${actualChecksum}`);
69
+ }
70
+ fs.chmodSync(tmpBinPath, 0o700);
71
+ fs.renameSync(tmpBinPath, binPath);
72
+ fs.rmSync(tmpBinDownloadDir, { recursive: true });
73
+ }
74
+ catch (e) {
75
+ fs.rmSync(tmpBinDownloadDir, { recursive: true });
76
+ throw new InitEngineSessionBinaryError(`failed to download dagger cli binary: ${e}`, { cause: e });
77
+ }
78
+ // Remove all temporary binary files
79
+ // Ignore current dagger cli or other files that have not be
80
+ // created by this SDK.
81
+ try {
82
+ const files = fs.readdirSync(this.cacheDir);
83
+ files.forEach((file) => {
84
+ const filePath = `${this.cacheDir}/${file}`;
85
+ if (filePath === binPath ||
86
+ !file.startsWith(this.DAGGER_CLI_BIN_PREFIX)) {
87
+ return;
88
+ }
89
+ fs.unlinkSync(filePath);
90
+ });
91
+ }
92
+ catch (e) {
93
+ // Log the error but do not interrupt program.
94
+ console.error("could not clean up temporary binary files");
95
+ }
96
+ return binPath;
97
+ });
98
+ }
99
+ /**
100
+ * runEngineSession execute the engine binary and set up a GraphQL client that
101
+ * target this engine.
102
+ */
103
+ runEngineSession(binPath, opts) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const args = [binPath, "session"];
106
+ if (opts.Workdir) {
107
+ args.push("--workdir", opts.Workdir);
108
+ }
109
+ if (opts.Project) {
110
+ args.push("--project", opts.Project);
111
+ }
112
+ this.subProcess = execaCommand(args.join(" "), {
113
+ stderr: opts.LogOutput || "ignore",
114
+ reject: true,
115
+ // Kill the process if parent exit.
116
+ cleanup: true,
117
+ });
118
+ const stdoutReader = readline.createInterface({
119
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
120
+ input: this.subProcess.stdout,
121
+ });
122
+ const timeOutDuration = 300000;
123
+ const connectParams = (yield Promise.race([
124
+ this.readConnectParams(stdoutReader),
125
+ new Promise((_, reject) => {
126
+ setTimeout(() => {
127
+ reject(new EngineSessionConnectionTimeoutError("timeout reading connect params from engine session", { timeOutDuration }));
128
+ }, timeOutDuration).unref(); // long timeout to account for extensions, though that should be optimized in future
129
+ }),
130
+ ]));
131
+ return new Client({
132
+ host: `127.0.0.1:${connectParams.port}`,
133
+ sessionToken: connectParams.session_token,
134
+ });
135
+ });
136
+ }
137
+ readConnectParams(stdoutReader) {
138
+ var _a, stdoutReader_1, stdoutReader_1_1;
139
+ var _b, e_1, _c, _d;
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ try {
142
+ for (_a = true, stdoutReader_1 = __asyncValues(stdoutReader); stdoutReader_1_1 = yield stdoutReader_1.next(), _b = stdoutReader_1_1.done, !_b;) {
143
+ _d = stdoutReader_1_1.value;
144
+ _a = false;
145
+ try {
146
+ const line = _d;
147
+ // parse the the line as json-encoded connect params
148
+ const connectParams = JSON.parse(line);
149
+ if (connectParams.port && connectParams.session_token) {
150
+ return connectParams;
151
+ }
152
+ throw new EngineSessionConnectParamsParseError(`invalid connect params: ${line}`, { parsedLine: line });
153
+ }
154
+ finally {
155
+ _a = true;
156
+ }
157
+ }
158
+ }
159
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
160
+ finally {
161
+ try {
162
+ if (!_a && !_b && (_c = stdoutReader_1.return)) yield _c.call(stdoutReader_1);
163
+ }
164
+ finally { if (e_1) throw e_1.error; }
165
+ }
166
+ throw new EngineSessionEOFError("No line was found to parse the engine connect params");
167
+ });
168
+ }
169
+ Close() {
170
+ var _a;
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ if ((_a = this.subProcess) === null || _a === void 0 ? void 0 : _a.pid) {
173
+ this.subProcess.kill("SIGTERM", {
174
+ forceKillAfterTimeout: 2000,
175
+ });
176
+ }
177
+ });
178
+ }
179
+ /**
180
+ * createCacheDir will create a cache directory on user
181
+ * host to store dagger binary.
182
+ *
183
+ * If set, it will use envPaths to determine system's cache directory,
184
+ * if not, it will use `$HOME/.cache` as base path.
185
+ * Nothing happens if the directory already exists.
186
+ */
187
+ createCacheDir() {
188
+ fs.mkdirSync(this.cacheDir, { mode: 0o700, recursive: true });
189
+ }
190
+ /**
191
+ * buildBinPath create a path to output dagger cli binary.
192
+ *
193
+ * It will store it in the cache directory with a name composed
194
+ * of the base engine session as constant and the engine identifier.
195
+ */
196
+ buildBinPath() {
197
+ const binPath = `${this.cacheDir}/${this.DAGGER_CLI_BIN_PREFIX}-${this.cliVersion}`;
198
+ switch (this.normalizedOS()) {
199
+ case "windows":
200
+ return `${binPath}.exe`;
201
+ default:
202
+ return binPath;
203
+ }
204
+ }
205
+ /**
206
+ * normalizedArch returns the architecture name used by the rest of our SDKs.
207
+ */
208
+ normalizedArch() {
209
+ switch (os.arch()) {
210
+ case "x64":
211
+ return "amd64";
212
+ default:
213
+ return os.arch();
214
+ }
215
+ }
216
+ /**
217
+ * normalizedOS returns the os name used by the rest of our SDKs.
218
+ */
219
+ normalizedOS() {
220
+ switch (os.platform()) {
221
+ case "win32":
222
+ return "windows";
223
+ default:
224
+ return os.platform();
225
+ }
226
+ }
227
+ cliArchiveName() {
228
+ if (OVERRIDE_CLI_URL) {
229
+ return path.basename(new URL(OVERRIDE_CLI_URL).pathname);
230
+ }
231
+ let ext = "tar.gz";
232
+ if (this.normalizedOS() === "windows") {
233
+ ext = "zip";
234
+ }
235
+ return `dagger_v${this.cliVersion}_${this.normalizedOS()}_${this.normalizedArch()}.${ext}`;
236
+ }
237
+ cliArchiveURL() {
238
+ if (OVERRIDE_CLI_URL) {
239
+ return OVERRIDE_CLI_URL;
240
+ }
241
+ return `https://${CLI_HOST}/dagger/releases/${this.cliVersion}/${this.cliArchiveName()}`;
242
+ }
243
+ cliChecksumURL() {
244
+ if (OVERRIDE_CHECKSUMS_URL) {
245
+ return OVERRIDE_CHECKSUMS_URL;
246
+ }
247
+ return `https://${CLI_HOST}/dagger/releases/${this.cliVersion}/checksums.txt`;
248
+ }
249
+ checksumMap() {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ // download checksums.txt
252
+ const checksums = yield fetch(this.cliChecksumURL());
253
+ if (!checksums.ok) {
254
+ throw new Error(`failed to download checksums.txt from ${this.cliChecksumURL()}`);
255
+ }
256
+ const checksumsText = yield checksums.text();
257
+ // iterate over lines filling in map of filename -> checksum
258
+ const checksumMap = new Map();
259
+ for (const line of checksumsText.split("\n")) {
260
+ const [checksum, filename] = line.split(/\s+/);
261
+ checksumMap.set(filename, checksum);
262
+ }
263
+ return checksumMap;
264
+ });
265
+ }
266
+ expectedChecksum() {
267
+ return __awaiter(this, void 0, void 0, function* () {
268
+ const checksumMap = yield this.checksumMap();
269
+ const expectedChecksum = checksumMap.get(this.cliArchiveName());
270
+ if (!expectedChecksum) {
271
+ throw new Error(`failed to find checksum for ${this.cliArchiveName()} in checksums.txt`);
272
+ }
273
+ return expectedChecksum;
274
+ });
275
+ }
276
+ extractArchive(destDir, os) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ // extract the dagger binary in the cli archive and return the archive of the .zip for windows and .tar.gz for other plateforms
279
+ const archiveResp = yield fetch(this.cliArchiveURL());
280
+ if (!archiveResp.ok) {
281
+ throw new Error(`failed to download dagger cli archive from ${this.cliArchiveURL()}`);
282
+ }
283
+ if (!archiveResp.body) {
284
+ throw new Error("archive response body is null");
285
+ }
286
+ // create a temporary file to store the archive
287
+ const archivePath = `${destDir}/${os === "windows" ? "dagger.zip" : "dagger.tar.gz"}`;
288
+ const archiveFile = fs.createWriteStream(archivePath);
289
+ yield new Promise((resolve, reject) => {
290
+ var _a, _b;
291
+ (_a = archiveResp.body) === null || _a === void 0 ? void 0 : _a.pipe(archiveFile);
292
+ (_b = archiveResp.body) === null || _b === void 0 ? void 0 : _b.on("error", reject);
293
+ archiveFile.on("finish", resolve);
294
+ });
295
+ const actualChecksum = crypto
296
+ .createHash("sha256")
297
+ .update(fs.readFileSync(archivePath))
298
+ .digest("hex");
299
+ if (os === "windows") {
300
+ const zip = new AdmZip(archivePath);
301
+ // extract just dagger.exe to the destdir
302
+ zip.extractEntryTo("dagger.exe", destDir, false, true);
303
+ }
304
+ else {
305
+ tar.extract({
306
+ cwd: destDir,
307
+ file: archivePath,
308
+ sync: true,
309
+ });
310
+ }
311
+ return actualChecksum;
312
+ });
313
+ }
314
+ /**
315
+ * Generate a unix timestamp in nanosecond
316
+ */
317
+ getRandomId() {
318
+ return process.hrtime.bigint().toString();
319
+ }
320
+ }
321
+ // Only meant for tests
322
+ export function _overrideCLIURL(url) {
323
+ OVERRIDE_CLI_URL = url;
324
+ }
325
+ // Only meant for tests
326
+ export function _overrideCLIChecksumsURL(url) {
327
+ OVERRIDE_CHECKSUMS_URL = url;
328
+ }
@@ -1,2 +1,2 @@
1
- export declare const DEFAULT_HOST: string;
1
+ export declare const CLI_VERSION = "0.3.9";
2
2
  //# sourceMappingURL=default.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../provisioning/default.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,QAAwC,CAAA"}
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../provisioning/default.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,UAAU,CAAA"}
@@ -1,3 +1,2 @@
1
1
  // Code generated by dagger. DO NOT EDIT.
2
- const DEFAULT_IMAGE_REF = "ghcr.io/dagger/engine:v0.3.7@sha256:9ad18aca71b1b1bae137d3ac5b8d1c62bd548d4f3b01c42b48120fdbc1490f22";
3
- export const DEFAULT_HOST = `docker-image://${DEFAULT_IMAGE_REF}`;
2
+ export const CLI_VERSION = "0.3.9";
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import Client from "../api/client.gen.js";
3
2
  import { Writable } from "node:stream";
3
+ import Client from "../api/client.gen.js";
4
4
  export interface ConnectOpts {
5
5
  Workdir?: string;
6
6
  Project?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"engineconn.d.ts","sourceRoot":"","sources":["../../provisioning/engineconn.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,sBAAsB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,QAAQ,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,MAAM,CAAA;IAElB;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAE/C;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B"}
1
+ {"version":3,"file":"engineconn.d.ts","sourceRoot":"","sources":["../../provisioning/engineconn.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,MAAM,MAAM,sBAAsB,CAAA;AAEzC,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,QAAQ,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,MAAM,CAAA;IAElB;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAE/C;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B"}
@@ -1,5 +1,4 @@
1
- export * from "./docker-provision/index.js";
2
1
  export * from "./default.js";
3
2
  export * from "./engineconn.js";
4
- export * from "./provisioner.js";
3
+ export * from "./bin.js";
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../provisioning/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../provisioning/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA"}
@@ -1,4 +1,3 @@
1
- export * from "./docker-provision/index.js";
2
1
  export * from "./default.js";
3
2
  export * from "./engineconn.js";
4
- export * from "./provisioner.js";
3
+ export * from "./bin.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dagger.io/dagger",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "author": "hello@dagger.io",
5
5
  "license": "Apache-2.0",
6
6
  "types": "./dist/index.d.ts",
@@ -17,34 +17,38 @@
17
17
  "main": "dist/index.js",
18
18
  "dependencies": {
19
19
  "@lifeomic/axios-fetch": "^3.0.1",
20
- "axios": "^1.2.0",
20
+ "adm-zip": "^0.5.10",
21
+ "axios": "^1.2.2",
22
+ "env-paths": "^3.0.0",
21
23
  "execa": "^6.1.0",
22
24
  "graphql": "^16.5.0",
23
- "graphql-request": "^5.0.0",
25
+ "graphql-request": "^5.1.0",
24
26
  "graphql-tag": "^2.12.6",
25
- "node-fetch": "^3.3.0"
27
+ "node-color-log": "^10.0.2",
28
+ "node-fetch": "^3.3.0",
29
+ "tar": "^6.1.13"
26
30
  },
27
31
  "scripts": {
28
32
  "build": "tsc",
33
+ "watch": "tsc -w",
29
34
  "test": "mocha",
30
- "gen:typedoc": "yarn typedoc",
31
35
  "lint": "yarn eslint --max-warnings=0 .",
32
36
  "fmt": "yarn eslint --fix"
33
37
  },
34
38
  "devDependencies": {
39
+ "@trivago/prettier-plugin-sort-imports": "^4.0.0",
40
+ "@types/adm-zip": "^0.5.0",
35
41
  "@types/mocha": "latest",
36
42
  "@types/node": "~16",
37
- "@typescript-eslint/eslint-plugin": "^5.45.0",
38
- "@typescript-eslint/parser": "^5.45.0",
39
- "eslint": "^8.28.0",
40
- "eslint-config-prettier": "^8.5.0",
43
+ "@types/tar": "^6.1.3",
44
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
45
+ "@typescript-eslint/parser": "^5.47.0",
46
+ "eslint": "^8.31.0",
47
+ "eslint-config-prettier": "^8.6.0",
41
48
  "eslint-plugin-prettier": "^4.2.1",
42
- "mocha": "^10.1.0",
43
- "prettier": "^2.8.0",
49
+ "mocha": "^10.2.0",
50
+ "prettier": "^2.8.1",
44
51
  "ts-node": "^10.9.1",
45
- "typedoc": "^0.23.21",
46
- "typedoc-plugin-markdown": "^3.13.6",
47
- "typedoc-plugin-missing-exports": "^1.0.0",
48
- "typescript": "^4.9.3"
52
+ "typescript": "^4.9.4"
49
53
  }
50
54
  }
@@ -1,21 +0,0 @@
1
- import { ConnectOpts, EngineConn } from "../engineconn.js";
2
- import Client from "../../api/client.gen.js";
3
- /**
4
- * Bin runs an engine session from a specified binary
5
- */
6
- export declare class Bin implements EngineConn {
7
- private subProcess?;
8
- private path;
9
- constructor(u: URL);
10
- Addr(): string;
11
- Connect(opts: ConnectOpts): Promise<Client>;
12
- /**
13
- * runEngineSession execute the engine binary and set up a GraphQL client that
14
- * target this engine.
15
- * TODO:(sipsma) dedupe this with equivalent code in image.ts
16
- */
17
- private runEngineSession;
18
- private readPort;
19
- Close(): Promise<void>;
20
- }
21
- //# sourceMappingURL=bin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../../provisioning/bin/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG1D,OAAO,MAAM,MAAM,yBAAyB,CAAA;AAE5C;;GAEG;AACH,qBAAa,GAAI,YAAW,UAAU;IACpC,OAAO,CAAC,UAAU,CAAC,CAAmB;IAEtC,OAAO,CAAC,IAAI,CAAQ;gBAER,CAAC,EAAE,GAAG;IAQlB,IAAI,IAAI,MAAM;IAIR,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjD;;;;OAIG;YACW,gBAAgB;YAqChB,QAAQ;IAShB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
@@ -1,112 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __asyncValues = (this && this.__asyncValues) || function (o) {
11
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
- var m = o[Symbol.asyncIterator], i;
13
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
14
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
- };
17
- import readline from "readline";
18
- import { execaCommand } from "execa";
19
- import Client from "../../api/client.gen.js";
20
- /**
21
- * Bin runs an engine session from a specified binary
22
- */
23
- export class Bin {
24
- constructor(u) {
25
- this.path = u.host + u.pathname;
26
- if (this.path == "") {
27
- // this results in execa looking for it in the $PATH
28
- this.path = "dagger-engine-session";
29
- }
30
- }
31
- Addr() {
32
- return "http://dagger";
33
- }
34
- Connect(opts) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return this.runEngineSession(this.path, opts);
37
- });
38
- }
39
- /**
40
- * runEngineSession execute the engine binary and set up a GraphQL client that
41
- * target this engine.
42
- * TODO:(sipsma) dedupe this with equivalent code in image.ts
43
- */
44
- runEngineSession(engineSessionBinPath, opts) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const engineSessionArgs = [engineSessionBinPath];
47
- if (opts.Workdir) {
48
- engineSessionArgs.push("--workdir", opts.Workdir);
49
- }
50
- if (opts.Project) {
51
- engineSessionArgs.push("--project", opts.Project);
52
- }
53
- this.subProcess = execaCommand(engineSessionArgs.join(" "), {
54
- stderr: opts.LogOutput || "ignore",
55
- // Kill the process if parent exit.
56
- cleanup: true,
57
- });
58
- const stdoutReader = readline.createInterface({
59
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
- input: this.subProcess.stdout,
61
- });
62
- const port = yield Promise.race([
63
- this.readPort(stdoutReader),
64
- new Promise((_, reject) => {
65
- setTimeout(() => {
66
- reject(new Error("timeout reading port from engine session"));
67
- }, 300000).unref(); // long timeout to account for extensions, though that should be optimized in future
68
- }),
69
- ]);
70
- return new Client({ host: `127.0.0.1:${port}` });
71
- });
72
- }
73
- readPort(stdoutReader) {
74
- var _a, stdoutReader_1, stdoutReader_1_1;
75
- var _b, e_1, _c, _d;
76
- return __awaiter(this, void 0, void 0, function* () {
77
- try {
78
- for (_a = true, stdoutReader_1 = __asyncValues(stdoutReader); stdoutReader_1_1 = yield stdoutReader_1.next(), _b = stdoutReader_1_1.done, !_b;) {
79
- _d = stdoutReader_1_1.value;
80
- _a = false;
81
- try {
82
- const line = _d;
83
- // Read line as a port number
84
- const port = parseInt(line);
85
- return port;
86
- }
87
- finally {
88
- _a = true;
89
- }
90
- }
91
- }
92
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
93
- finally {
94
- try {
95
- if (!_a && !_b && (_c = stdoutReader_1.return)) yield _c.call(stdoutReader_1);
96
- }
97
- finally { if (e_1) throw e_1.error; }
98
- }
99
- throw new Error("failed to read port from engine session");
100
- });
101
- }
102
- Close() {
103
- var _a;
104
- return __awaiter(this, void 0, void 0, function* () {
105
- if ((_a = this.subProcess) === null || _a === void 0 ? void 0 : _a.pid) {
106
- this.subProcess.kill("SIGTERM", {
107
- forceKillAfterTimeout: 2000,
108
- });
109
- }
110
- });
111
- }
112
- }
@@ -1,2 +0,0 @@
1
- export * from "./bin.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../provisioning/bin/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -1 +0,0 @@
1
- export * from "./bin.js";
@@ -1 +0,0 @@
1
- {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../provisioning/docker-provision/image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAM1D,OAAO,MAAM,MAAM,yBAAyB,CAAA;AAqD5C;;;GAGG;AACH,qBAAa,WAAY,YAAW,UAAU;IAC5C,OAAO,CAAC,QAAQ,CAAU;IAE1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGxB;IAED,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAA0B;IAEvE,OAAO,CAAC,UAAU,CAAC,CAAmB;gBAE1B,CAAC,EAAE,GAAG;IAIlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB,IAAI,IAAI,MAAM;IAIR,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAWjD;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IA+D5B;;;OAGG;YACW,gBAAgB;YA4ChB,QAAQ;IAShB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}