@dagger.io/dagger 0.3.0 → 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.
- package/README.md +72 -1
- package/dist/api/client.gen.d.ts +220 -128
- package/dist/api/client.gen.d.ts.map +1 -1
- package/dist/api/client.gen.js +280 -154
- package/dist/api/utils.d.ts +1 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/api/utils.js +43 -41
- package/dist/common/errors/DaggerSDKError.d.ts +4 -3
- package/dist/common/errors/DaggerSDKError.d.ts.map +1 -1
- package/dist/common/errors/DockerImageRefValidationError.d.ts +2 -2
- package/dist/common/errors/DockerImageRefValidationError.d.ts.map +1 -1
- package/dist/common/errors/DockerImageRefValidationError.js +3 -2
- package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
- package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
- package/dist/common/errors/EngineSessionConnectParamsParseError.js +16 -0
- package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
- package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
- package/dist/common/errors/EngineSessionConnectionTimeoutError.js +16 -0
- package/dist/common/errors/EngineSessionEOFErrorOptions.d.ts +16 -0
- package/dist/common/errors/EngineSessionEOFErrorOptions.d.ts.map +1 -0
- package/dist/common/errors/EngineSessionEOFErrorOptions.js +16 -0
- package/dist/common/errors/GraphQLRequestError.d.ts +2 -2
- package/dist/common/errors/GraphQLRequestError.d.ts.map +1 -1
- package/dist/common/errors/GraphQLRequestError.js +3 -2
- package/dist/common/errors/InitEngineSessionBinaryError.d.ts +2 -2
- package/dist/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -1
- package/dist/common/errors/InitEngineSessionBinaryError.js +3 -2
- package/dist/common/errors/TooManyNestedObjectsError.d.ts +2 -2
- package/dist/common/errors/TooManyNestedObjectsError.d.ts.map +1 -1
- package/dist/common/errors/TooManyNestedObjectsError.js +3 -2
- package/dist/common/errors/UnknownDaggerError.d.ts +2 -2
- package/dist/common/errors/UnknownDaggerError.d.ts.map +1 -1
- package/dist/common/errors/UnknownDaggerError.js +3 -2
- package/dist/common/errors/errors-codes.d.ts +43 -0
- package/dist/common/errors/errors-codes.d.ts.map +1 -0
- package/dist/common/errors/errors-codes.js +35 -0
- package/dist/common/errors/index.d.ts +4 -1
- package/dist/common/errors/index.d.ts.map +1 -1
- package/dist/common/errors/index.js +4 -1
- package/dist/common/utils.d.ts +3 -3
- package/dist/connect.d.ts +24 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +29 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/provisioning/{docker-provision/image.d.ts → bin.d.ts} +31 -29
- package/dist/provisioning/bin.d.ts.map +1 -0
- package/dist/provisioning/bin.js +328 -0
- package/dist/provisioning/default.d.ts +1 -1
- package/dist/provisioning/default.d.ts.map +1 -1
- package/dist/provisioning/default.js +1 -2
- package/dist/provisioning/engineconn.d.ts +1 -1
- package/dist/provisioning/engineconn.d.ts.map +1 -1
- package/dist/provisioning/index.d.ts +1 -2
- package/dist/provisioning/index.d.ts.map +1 -1
- package/dist/provisioning/index.js +1 -2
- package/package.json +18 -11
- package/dist/common/errors/EngineSessionPortParseError.d.ts +0 -25
- package/dist/common/errors/EngineSessionPortParseError.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionPortParseError.js +0 -20
- package/dist/provisioning/bin/bin.d.ts +0 -21
- package/dist/provisioning/bin/bin.d.ts.map +0 -1
- package/dist/provisioning/bin/bin.js +0 -116
- package/dist/provisioning/bin/index.d.ts +0 -2
- package/dist/provisioning/bin/index.d.ts.map +0 -1
- package/dist/provisioning/bin/index.js +0 -1
- package/dist/provisioning/docker-provision/image.d.ts.map +0 -1
- package/dist/provisioning/docker-provision/image.js +0 -275
- package/dist/provisioning/docker-provision/index.d.ts +0 -2
- package/dist/provisioning/docker-provision/index.d.ts.map +0 -1
- package/dist/provisioning/docker-provision/index.js +0 -1
- package/dist/provisioning/http/http.d.ts +0 -14
- package/dist/provisioning/http/http.d.ts.map +0 -1
- package/dist/provisioning/http/http.js +0 -33
- package/dist/provisioning/http/index.d.ts +0 -2
- package/dist/provisioning/http/index.d.ts.map +0 -1
- package/dist/provisioning/http/index.js +0 -1
- package/dist/provisioning/provisioner.d.ts +0 -11
- package/dist/provisioning/provisioner.d.ts.map +0 -1
- package/dist/provisioning/provisioner.js +0 -26
package/dist/connect.d.ts
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
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
|
/**
|
|
5
5
|
* ConnectOpts defines option used to connect to an engine.
|
|
6
6
|
*/
|
|
7
7
|
export interface ConnectOpts {
|
|
8
|
+
/**
|
|
9
|
+
* Use to overwrite Dagger workdir
|
|
10
|
+
* @defaultValue process.cwd()
|
|
11
|
+
*/
|
|
8
12
|
Workdir?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Use to overwrite Dagger config
|
|
15
|
+
* @defaultValue dagger.json
|
|
16
|
+
*/
|
|
9
17
|
ConfigPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Enable logs output
|
|
20
|
+
* @example
|
|
21
|
+
* LogOutput
|
|
22
|
+
* ```ts
|
|
23
|
+
* connect(async (client: Client) => {
|
|
24
|
+
const source = await client.host().workdir().id()
|
|
25
|
+
...
|
|
26
|
+
}, {LogOutput: process.stdout})
|
|
27
|
+
```
|
|
28
|
+
*/
|
|
10
29
|
LogOutput?: Writable;
|
|
11
30
|
}
|
|
12
31
|
export type CallbackFct = (client: Client) => Promise<void>;
|
|
32
|
+
export interface ConnectParams {
|
|
33
|
+
port: number;
|
|
34
|
+
session_token: string;
|
|
35
|
+
}
|
|
13
36
|
/**
|
|
14
37
|
* connect runs GraphQL server and initializes a
|
|
15
38
|
* GraphQL client to execute query on it through its callback.
|
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../connect.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../connect.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,MAAM,MAAM,qBAAqB,CAAA;AAGxC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAA;CACrB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE3D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,EAAE,EAAE,WAAW,EACf,MAAM,GAAE,WAAgB,GACvB,OAAO,CAAC,IAAI,CAAC,CAuCf"}
|
package/dist/connect.js
CHANGED
|
@@ -7,7 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
10
|
+
import Client from "./api/client.gen.js";
|
|
11
|
+
import { Bin, CLI_VERSION } from "./provisioning/index.js";
|
|
11
12
|
/**
|
|
12
13
|
* connect runs GraphQL server and initializes a
|
|
13
14
|
* GraphQL client to execute query on it through its callback.
|
|
@@ -18,9 +19,32 @@ export function connect(cb, config = {}) {
|
|
|
18
19
|
// Create config with default values that may be overridden
|
|
19
20
|
// by config if values are set.
|
|
20
21
|
const _config = Object.assign({ Workdir: process.env["DAGGER_WORKDIR"] || process.cwd(), ConfigPath: process.env["DAGGER_CONFIG"] || "./dagger.json" }, config);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let client;
|
|
23
|
+
let close = null;
|
|
24
|
+
// Prefer DAGGER_SESSION_PORT if set
|
|
25
|
+
const daggerSessionPort = process.env["DAGGER_SESSION_PORT"];
|
|
26
|
+
if (daggerSessionPort) {
|
|
27
|
+
const sessionToken = process.env["DAGGER_SESSION_TOKEN"];
|
|
28
|
+
if (!sessionToken) {
|
|
29
|
+
throw new Error("DAGGER_SESSION_TOKEN must be set when using DAGGER_SESSION_PORT");
|
|
30
|
+
}
|
|
31
|
+
client = new Client({
|
|
32
|
+
host: `http://127.0.0.1:${daggerSessionPort}/query`,
|
|
33
|
+
sessionToken: sessionToken,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Otherwise, prefer _EXPERIMENTAL_DAGGER_CLI_BIN, with fallback behavior of
|
|
38
|
+
// downloading the CLI and using that as the bin.
|
|
39
|
+
const cliBin = process.env["_EXPERIMENTAL_DAGGER_CLI_BIN"];
|
|
40
|
+
const engineConn = new Bin(cliBin, CLI_VERSION);
|
|
41
|
+
client = yield engineConn.Connect(_config);
|
|
42
|
+
close = () => engineConn.Close();
|
|
43
|
+
}
|
|
44
|
+
yield cb(client).finally(() => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (close) {
|
|
46
|
+
close();
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
25
49
|
});
|
|
26
50
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,5 @@ import Client from "./api/client.gen.js";
|
|
|
2
2
|
export { gql } from "graphql-tag";
|
|
3
3
|
export { GraphQLClient } from "graphql-request";
|
|
4
4
|
export { connect, ConnectOpts, CallbackFct } from "./connect.js";
|
|
5
|
-
export { getProvisioner } from "./provisioning/index.js";
|
|
6
5
|
export default Client;
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAA;AAExC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAA;AAExC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhE,eAAe,MAAM,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import Client from "../api/client.gen.js";
|
|
2
|
+
import { ConnectOpts, EngineConn } from "./engineconn.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Engine session from a pulled docker image.
|
|
4
|
+
* Bin runs an engine session from a specified binary
|
|
6
5
|
*/
|
|
7
|
-
export declare class
|
|
8
|
-
private imageRef;
|
|
9
|
-
private readonly cacheDir;
|
|
10
|
-
private readonly ENGINE_SESSION_BINARY_PREFIX;
|
|
6
|
+
export declare class Bin implements EngineConn {
|
|
11
7
|
private subProcess?;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
private binPath?;
|
|
9
|
+
private cliVersion?;
|
|
10
|
+
private readonly cacheDir;
|
|
11
|
+
private readonly DAGGER_CLI_BIN_PREFIX;
|
|
12
|
+
constructor(binPath?: string, cliVersion?: string);
|
|
17
13
|
Addr(): string;
|
|
18
14
|
Connect(opts: ConnectOpts): Promise<Client>;
|
|
15
|
+
private downloadCLI;
|
|
16
|
+
/**
|
|
17
|
+
* runEngineSession execute the engine binary and set up a GraphQL client that
|
|
18
|
+
* target this engine.
|
|
19
|
+
*/
|
|
20
|
+
private runEngineSession;
|
|
21
|
+
private readConnectParams;
|
|
22
|
+
Close(): Promise<void>;
|
|
19
23
|
/**
|
|
20
24
|
* createCacheDir will create a cache directory on user
|
|
21
25
|
* host to store dagger binary.
|
|
22
26
|
*
|
|
23
|
-
* If set, it will use
|
|
24
|
-
* as base path.
|
|
27
|
+
* If set, it will use envPaths to determine system's cache directory,
|
|
28
|
+
* if not, it will use `$HOME/.cache` as base path.
|
|
25
29
|
* Nothing happens if the directory already exists.
|
|
26
30
|
*/
|
|
27
31
|
private createCacheDir;
|
|
28
32
|
/**
|
|
29
|
-
* buildBinPath create a path to output
|
|
33
|
+
* buildBinPath create a path to output dagger cli binary.
|
|
30
34
|
*
|
|
31
35
|
* It will store it in the cache directory with a name composed
|
|
32
36
|
* of the base engine session as constant and the engine identifier.
|
|
@@ -40,19 +44,17 @@ export declare class DockerImage implements EngineConn {
|
|
|
40
44
|
* normalizedOS returns the os name used by the rest of our SDKs.
|
|
41
45
|
*/
|
|
42
46
|
private normalizedOS;
|
|
47
|
+
private cliArchiveName;
|
|
48
|
+
private cliArchiveURL;
|
|
49
|
+
private cliChecksumURL;
|
|
50
|
+
private checksumMap;
|
|
51
|
+
private expectedChecksum;
|
|
52
|
+
private extractArchive;
|
|
43
53
|
/**
|
|
44
|
-
*
|
|
45
|
-
* and copy it to the local host.
|
|
46
|
-
* This function automatically resolves host's platform to copy the correct
|
|
47
|
-
* binary.
|
|
48
|
-
*/
|
|
49
|
-
private pullEngineSessionBin;
|
|
50
|
-
/**
|
|
51
|
-
* runEngineSession execute the engine binary and set up a GraphQL client that
|
|
52
|
-
* target this engine.
|
|
54
|
+
* Generate a unix timestamp in nanosecond
|
|
53
55
|
*/
|
|
54
|
-
private
|
|
55
|
-
private readPort;
|
|
56
|
-
Close(): Promise<void>;
|
|
56
|
+
private getRandomId;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
export declare function _overrideCLIURL(url: string): void;
|
|
59
|
+
export declare function _overrideCLIChecksumsURL(url: string): void;
|
|
60
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../provisioning/bin.ts"],"names":[],"mappings":"AAWA,OAAO,MAAM,MAAM,sBAAsB,CAAA;AAQzC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAMzD;;GAEG;AACH,qBAAa,GAAI,YAAW,UAAU;IACpC,OAAO,CAAC,UAAU,CAAC,CAAmB;IAEtC,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,UAAU,CAAC,CAAQ;IAE3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2C;IAEpE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAW;gBAErC,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;IAKjD,IAAI,IAAI,MAAM;IAIR,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;YAOnC,WAAW;IA6DzB;;;OAGG;YACW,gBAAgB;YAgDhB,iBAAiB;IAmBzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,cAAc;YAOR,WAAW;YAkBX,gBAAgB;YAWhB,cAAc;IA2C5B;;OAEG;IACH,OAAO,CAAC,WAAW;CAGpB;AAGD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AAGD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE1D"}
|
|
@@ -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
|
|
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":"
|
|
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
|
|
3
|
-
export const DEFAULT_HOST = `docker-image://${DEFAULT_IMAGE_REF}`;
|
|
2
|
+
export const CLI_VERSION = "0.3.9";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineconn.d.ts","sourceRoot":"","sources":["../../provisioning/engineconn.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../provisioning/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dagger.io/dagger",
|
|
3
|
-
"version": "0.3.
|
|
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,31 +17,38 @@
|
|
|
17
17
|
"main": "dist/index.js",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@lifeomic/axios-fetch": "^3.0.1",
|
|
20
|
-
"
|
|
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.
|
|
25
|
+
"graphql-request": "^5.1.0",
|
|
24
26
|
"graphql-tag": "^2.12.6",
|
|
25
27
|
"node-color-log": "^10.0.2",
|
|
26
|
-
"node-fetch": "^3.3.0"
|
|
28
|
+
"node-fetch": "^3.3.0",
|
|
29
|
+
"tar": "^6.1.13"
|
|
27
30
|
},
|
|
28
31
|
"scripts": {
|
|
29
32
|
"build": "tsc",
|
|
33
|
+
"watch": "tsc -w",
|
|
30
34
|
"test": "mocha",
|
|
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
|
-
"@
|
|
38
|
-
"@typescript-eslint/
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"eslint
|
|
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.
|
|
43
|
-
"prettier": "^2.8.
|
|
49
|
+
"mocha": "^10.2.0",
|
|
50
|
+
"prettier": "^2.8.1",
|
|
44
51
|
"ts-node": "^10.9.1",
|
|
45
|
-
"typescript": "^4.9.
|
|
52
|
+
"typescript": "^4.9.4"
|
|
46
53
|
}
|
|
47
54
|
}
|