@dagger.io/dagger 0.13.1 → 0.13.3
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/package.json +1 -1
- package/dist/api/client.gen.d.ts +0 -3668
- package/dist/api/client.gen.d.ts.map +0 -1
- package/dist/api/client.gen.js +0 -7133
- package/dist/api/utils.d.ts +0 -28
- package/dist/api/utils.d.ts.map +0 -1
- package/dist/api/utils.js +0 -170
- package/dist/common/errors/DaggerSDKError.d.ts +0 -32
- package/dist/common/errors/DaggerSDKError.d.ts.map +0 -1
- package/dist/common/errors/DaggerSDKError.js +0 -26
- package/dist/common/errors/DockerImageRefValidationError.d.ts +0 -22
- package/dist/common/errors/DockerImageRefValidationError.d.ts.map +0 -1
- package/dist/common/errors/DockerImageRefValidationError.js +0 -21
- package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts +0 -21
- package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionConnectParamsParseError.js +0 -20
- package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts +0 -21
- package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionConnectionTimeoutError.js +0 -20
- package/dist/common/errors/EngineSessionErrorOptions.d.ts +0 -16
- package/dist/common/errors/EngineSessionErrorOptions.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionErrorOptions.js +0 -16
- package/dist/common/errors/ExecError.d.ts +0 -37
- package/dist/common/errors/ExecError.d.ts.map +0 -1
- package/dist/common/errors/ExecError.js +0 -38
- package/dist/common/errors/GraphQLRequestError.d.ts +0 -26
- package/dist/common/errors/GraphQLRequestError.d.ts.map +0 -1
- package/dist/common/errors/GraphQLRequestError.js +0 -25
- package/dist/common/errors/InitEngineSessionBinaryError.d.ts +0 -13
- package/dist/common/errors/InitEngineSessionBinaryError.d.ts.map +0 -1
- package/dist/common/errors/InitEngineSessionBinaryError.js +0 -15
- package/dist/common/errors/NotAwaitedRequestError.d.ts +0 -13
- package/dist/common/errors/NotAwaitedRequestError.d.ts.map +0 -1
- package/dist/common/errors/NotAwaitedRequestError.js +0 -15
- package/dist/common/errors/TooManyNestedObjectsError.d.ts +0 -21
- package/dist/common/errors/TooManyNestedObjectsError.d.ts.map +0 -1
- package/dist/common/errors/TooManyNestedObjectsError.js +0 -20
- package/dist/common/errors/UnknownDaggerError.d.ts +0 -13
- package/dist/common/errors/UnknownDaggerError.d.ts.map +0 -1
- package/dist/common/errors/UnknownDaggerError.js +0 -15
- package/dist/common/errors/errors-codes.d.ts +0 -51
- package/dist/common/errors/errors-codes.d.ts.map +0 -1
- package/dist/common/errors/errors-codes.js +0 -43
- package/dist/common/errors/index.d.ts +0 -13
- package/dist/common/errors/index.d.ts.map +0 -1
- package/dist/common/errors/index.js +0 -12
- package/dist/common/utils.d.ts +0 -68
- package/dist/common/utils.d.ts.map +0 -1
- package/dist/common/utils.js +0 -2
- package/dist/connect.d.ts +0 -32
- package/dist/connect.d.ts.map +0 -1
- package/dist/connect.js +0 -66
- package/dist/connectOpts.d.ts +0 -24
- package/dist/connectOpts.d.ts.map +0 -1
- package/dist/connectOpts.js +0 -1
- package/dist/context/builder.d.ts +0 -9
- package/dist/context/builder.d.ts.map +0 -1
- package/dist/context/builder.js +0 -34
- package/dist/context/context.d.ts +0 -40
- package/dist/context/context.d.ts.map +0 -1
- package/dist/context/context.js +0 -53
- package/dist/entrypoint/context.d.ts +0 -8
- package/dist/entrypoint/context.d.ts.map +0 -1
- package/dist/entrypoint/context.js +0 -1
- package/dist/entrypoint/entrypoint.d.ts +0 -2
- package/dist/entrypoint/entrypoint.d.ts.map +0 -1
- package/dist/entrypoint/entrypoint.js +0 -68
- package/dist/entrypoint/invoke.d.ts +0 -13
- package/dist/entrypoint/invoke.d.ts.map +0 -1
- package/dist/entrypoint/invoke.js +0 -40
- package/dist/entrypoint/load.d.ts +0 -56
- package/dist/entrypoint/load.d.ts.map +0 -1
- package/dist/entrypoint/load.js +0 -198
- package/dist/entrypoint/register.d.ts +0 -7
- package/dist/entrypoint/register.d.ts.map +0 -1
- package/dist/entrypoint/register.js +0 -140
- package/dist/graphql/client.d.ts +0 -3
- package/dist/graphql/client.d.ts.map +0 -1
- package/dist/graphql/client.js +0 -25
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -7
- package/dist/introspector/decorators/decorators.d.ts +0 -44
- package/dist/introspector/decorators/decorators.d.ts.map +0 -1
- package/dist/introspector/decorators/decorators.js +0 -47
- package/dist/introspector/registry/registry.d.ts +0 -89
- package/dist/introspector/registry/registry.d.ts.map +0 -1
- package/dist/introspector/registry/registry.js +0 -115
- package/dist/introspector/scanner/abtractions/argument.d.ts +0 -104
- package/dist/introspector/scanner/abtractions/argument.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/argument.js +0 -207
- package/dist/introspector/scanner/abtractions/constructor.d.ts +0 -17
- package/dist/introspector/scanner/abtractions/constructor.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/constructor.js +0 -40
- package/dist/introspector/scanner/abtractions/enum.d.ts +0 -33
- package/dist/introspector/scanner/abtractions/enum.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/enum.js +0 -73
- package/dist/introspector/scanner/abtractions/enumValue.d.ts +0 -24
- package/dist/introspector/scanner/abtractions/enumValue.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/enumValue.js +0 -51
- package/dist/introspector/scanner/abtractions/method.d.ts +0 -67
- package/dist/introspector/scanner/abtractions/method.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/method.js +0 -132
- package/dist/introspector/scanner/abtractions/module.d.ts +0 -26
- package/dist/introspector/scanner/abtractions/module.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/module.js +0 -103
- package/dist/introspector/scanner/abtractions/object.d.ts +0 -52
- package/dist/introspector/scanner/abtractions/object.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/object.js +0 -118
- package/dist/introspector/scanner/abtractions/property.d.ts +0 -55
- package/dist/introspector/scanner/abtractions/property.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/property.js +0 -110
- package/dist/introspector/scanner/abtractions/typeToTypedef.d.ts +0 -8
- package/dist/introspector/scanner/abtractions/typeToTypedef.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/typeToTypedef.js +0 -85
- package/dist/introspector/scanner/scan.d.ts +0 -14
- package/dist/introspector/scanner/scan.d.ts.map +0 -1
- package/dist/introspector/scanner/scan.js +0 -26
- package/dist/introspector/scanner/typeDefs.d.ts +0 -45
- package/dist/introspector/scanner/typeDefs.d.ts.map +0 -1
- package/dist/introspector/scanner/typeDefs.js +0 -1
- package/dist/introspector/scanner/utils.d.ts +0 -22
- package/dist/introspector/scanner/utils.d.ts.map +0 -1
- package/dist/introspector/scanner/utils.js +0 -101
- package/dist/introspector/utils/files.d.ts +0 -5
- package/dist/introspector/utils/files.d.ts.map +0 -1
- package/dist/introspector/utils/files.js +0 -28
- package/dist/provisioning/bin.d.ts +0 -77
- package/dist/provisioning/bin.d.ts.map +0 -1
- package/dist/provisioning/bin.js +0 -353
- package/dist/provisioning/default.d.ts +0 -2
- package/dist/provisioning/default.d.ts.map +0 -1
- package/dist/provisioning/default.js +0 -2
- package/dist/provisioning/engineconn.d.ts +0 -28
- package/dist/provisioning/engineconn.d.ts.map +0 -1
- package/dist/provisioning/engineconn.js +0 -1
- package/dist/provisioning/index.d.ts +0 -4
- package/dist/provisioning/index.d.ts.map +0 -1
- package/dist/provisioning/index.js +0 -3
- package/dist/telemetry/attributes.d.ts +0 -5
- package/dist/telemetry/attributes.d.ts.map +0 -1
- package/dist/telemetry/attributes.js +0 -4
- package/dist/telemetry/index.d.ts +0 -3
- package/dist/telemetry/index.d.ts.map +0 -1
- package/dist/telemetry/index.js +0 -2
- package/dist/telemetry/init.d.ts +0 -21
- package/dist/telemetry/init.d.ts.map +0 -1
- package/dist/telemetry/init.js +0 -66
- package/dist/telemetry/telemetry.d.ts +0 -16
- package/dist/telemetry/telemetry.d.ts.map +0 -1
- package/dist/telemetry/telemetry.js +0 -38
- package/dist/telemetry/tracer.d.ts +0 -32
- package/dist/telemetry/tracer.d.ts.map +0 -1
- package/dist/telemetry/tracer.js +0 -54
package/dist/provisioning/bin.js
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import AdmZip from "adm-zip";
|
|
2
|
-
import * as crypto from "crypto";
|
|
3
|
-
import envPaths from "env-paths";
|
|
4
|
-
import { execa } from "execa";
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
import fetch from "node-fetch";
|
|
7
|
-
import * as os from "os";
|
|
8
|
-
import * as path from "path";
|
|
9
|
-
import * as process from "process";
|
|
10
|
-
import readline from "readline";
|
|
11
|
-
import * as tar from "tar";
|
|
12
|
-
import { fileURLToPath } from "url";
|
|
13
|
-
import { EngineSessionConnectionTimeoutError, EngineSessionConnectParamsParseError, EngineSessionError, InitEngineSessionBinaryError, } from "../common/errors/index.js";
|
|
14
|
-
import { createGQLClient } from "../graphql/client.js";
|
|
15
|
-
const CLI_HOST = "dl.dagger.io";
|
|
16
|
-
let OVERRIDE_CLI_URL;
|
|
17
|
-
let OVERRIDE_CHECKSUMS_URL;
|
|
18
|
-
/**
|
|
19
|
-
* Bin runs an engine session from a specified binary
|
|
20
|
-
*/
|
|
21
|
-
export class Bin {
|
|
22
|
-
_subProcess;
|
|
23
|
-
binPath;
|
|
24
|
-
cliVersion;
|
|
25
|
-
cacheDir = path.join(`${process.env.XDG_CACHE_HOME?.trim() || envPaths("", { suffix: "" }).cache}`, "dagger");
|
|
26
|
-
DAGGER_CLI_BIN_PREFIX = "dagger";
|
|
27
|
-
constructor(binPath, cliVersion) {
|
|
28
|
-
this.binPath = binPath;
|
|
29
|
-
this.cliVersion = cliVersion;
|
|
30
|
-
}
|
|
31
|
-
Addr() {
|
|
32
|
-
return "http://dagger";
|
|
33
|
-
}
|
|
34
|
-
get subProcess() {
|
|
35
|
-
return this._subProcess;
|
|
36
|
-
}
|
|
37
|
-
async Connect(opts) {
|
|
38
|
-
if (!this.binPath) {
|
|
39
|
-
if (opts.LogOutput) {
|
|
40
|
-
opts.LogOutput.write("Downloading CLI... ");
|
|
41
|
-
}
|
|
42
|
-
this.binPath = await this.downloadCLI();
|
|
43
|
-
if (opts.LogOutput) {
|
|
44
|
-
opts.LogOutput.write("OK!\n");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return this.runEngineSession(this.binPath, opts);
|
|
48
|
-
}
|
|
49
|
-
async downloadCLI() {
|
|
50
|
-
if (!this.cliVersion) {
|
|
51
|
-
throw new Error("cliVersion is not set");
|
|
52
|
-
}
|
|
53
|
-
const binPath = this.buildBinPath();
|
|
54
|
-
// Create a temporary bin file path
|
|
55
|
-
this.createCacheDir();
|
|
56
|
-
const tmpBinDownloadDir = fs.mkdtempSync(path.join(this.cacheDir, `temp-${this.getRandomId()}`));
|
|
57
|
-
const tmpBinPath = this.buildOsExePath(tmpBinDownloadDir, this.DAGGER_CLI_BIN_PREFIX);
|
|
58
|
-
try {
|
|
59
|
-
// download an archive and use appropriate extraction depending on platforms (zip on windows, tar.gz on other platforms)
|
|
60
|
-
const actualChecksum = await this.extractArchive(tmpBinDownloadDir, this.normalizedOS());
|
|
61
|
-
const expectedChecksum = await this.expectedChecksum();
|
|
62
|
-
if (actualChecksum !== expectedChecksum) {
|
|
63
|
-
throw new Error(`checksum mismatch: expected ${expectedChecksum}, got ${actualChecksum}`);
|
|
64
|
-
}
|
|
65
|
-
fs.chmodSync(tmpBinPath, 0o700);
|
|
66
|
-
fs.renameSync(tmpBinPath, binPath);
|
|
67
|
-
fs.rmSync(tmpBinDownloadDir, { recursive: true });
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
fs.rmSync(tmpBinDownloadDir, { recursive: true });
|
|
71
|
-
throw new InitEngineSessionBinaryError(`failed to download dagger cli binary: ${e}`, {
|
|
72
|
-
cause: e,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
// Remove all temporary binary files
|
|
76
|
-
// Ignore current dagger cli or other files that have not be
|
|
77
|
-
// created by this SDK.
|
|
78
|
-
try {
|
|
79
|
-
const files = fs.readdirSync(this.cacheDir);
|
|
80
|
-
files.forEach((file) => {
|
|
81
|
-
const filePath = path.join(this.cacheDir, file);
|
|
82
|
-
if (filePath === binPath ||
|
|
83
|
-
!file.startsWith(this.DAGGER_CLI_BIN_PREFIX)) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
fs.unlinkSync(filePath);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// Log the error but do not interrupt program.
|
|
91
|
-
console.error("could not clean up temporary binary files");
|
|
92
|
-
}
|
|
93
|
-
return binPath;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Traverse up the directory tree to find the package.json file and return the
|
|
97
|
-
* SDK version.
|
|
98
|
-
* @returns the SDK version or "n/a" if the version cannot be found.
|
|
99
|
-
*/
|
|
100
|
-
getSDKVersion() {
|
|
101
|
-
const currentFileUrl = import.meta.url;
|
|
102
|
-
const currentFilePath = fileURLToPath(currentFileUrl);
|
|
103
|
-
let currentPath = path.dirname(currentFilePath);
|
|
104
|
-
while (currentPath !== path.parse(currentPath).root) {
|
|
105
|
-
const packageJsonPath = path.join(currentPath, "package.json");
|
|
106
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
107
|
-
try {
|
|
108
|
-
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
|
|
109
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
110
|
-
return packageJson.version;
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
return "n/a";
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
currentPath = path.join(currentPath, "..");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* runEngineSession execute the engine binary and set up a GraphQL client that
|
|
123
|
-
* target this engine.
|
|
124
|
-
*/
|
|
125
|
-
async runEngineSession(binPath, opts) {
|
|
126
|
-
const args = ["session"];
|
|
127
|
-
const sdkVersion = this.getSDKVersion();
|
|
128
|
-
const flagsAndValues = [
|
|
129
|
-
{ flag: "--workdir", value: opts.Workdir },
|
|
130
|
-
{ flag: "--project", value: opts.Project },
|
|
131
|
-
{ flag: "--label", value: "dagger.io/sdk.name:nodejs" },
|
|
132
|
-
{ flag: "--label", value: `dagger.io/sdk.version:${sdkVersion}` },
|
|
133
|
-
];
|
|
134
|
-
flagsAndValues.forEach((pair) => {
|
|
135
|
-
if (pair.value) {
|
|
136
|
-
args.push(pair.flag, pair.value);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
if (opts.LogOutput) {
|
|
140
|
-
opts.LogOutput.write("Creating new Engine session... ");
|
|
141
|
-
}
|
|
142
|
-
this._subProcess = execa(binPath, args, {
|
|
143
|
-
stdio: "pipe",
|
|
144
|
-
reject: true,
|
|
145
|
-
// Kill the process if parent exit.
|
|
146
|
-
cleanup: true,
|
|
147
|
-
// Set a long timeout to give time for any cache exports to pack layers up
|
|
148
|
-
// which currently has to happen synchronously with the session.
|
|
149
|
-
forceKillAfterDelay: 300000,
|
|
150
|
-
});
|
|
151
|
-
// Log the output if the user wants to.
|
|
152
|
-
if (opts.LogOutput) {
|
|
153
|
-
this._subProcess.stderr?.pipe(opts.LogOutput);
|
|
154
|
-
}
|
|
155
|
-
const stdoutReader = readline.createInterface({
|
|
156
|
-
input: this._subProcess?.stdout,
|
|
157
|
-
});
|
|
158
|
-
const timeOutDuration = 300000;
|
|
159
|
-
if (opts.LogOutput) {
|
|
160
|
-
opts.LogOutput.write("OK!\nEstablishing connection to Engine... ");
|
|
161
|
-
}
|
|
162
|
-
const connectParams = (await Promise.race([
|
|
163
|
-
this.readConnectParams(stdoutReader),
|
|
164
|
-
new Promise((_, reject) => {
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
reject(new EngineSessionConnectionTimeoutError("Engine connection timeout", {
|
|
167
|
-
timeOutDuration,
|
|
168
|
-
}));
|
|
169
|
-
}, timeOutDuration).unref(); // long timeout to account for extensions, though that should be optimized in future
|
|
170
|
-
}),
|
|
171
|
-
]));
|
|
172
|
-
if (opts.LogOutput) {
|
|
173
|
-
opts.LogOutput.write("OK!\n");
|
|
174
|
-
}
|
|
175
|
-
return createGQLClient(connectParams.port, connectParams.session_token);
|
|
176
|
-
}
|
|
177
|
-
async readConnectParams(stdoutReader) {
|
|
178
|
-
for await (const line of stdoutReader) {
|
|
179
|
-
// parse the line as json-encoded connect params
|
|
180
|
-
const connectParams = JSON.parse(line);
|
|
181
|
-
if (connectParams.port && connectParams.session_token) {
|
|
182
|
-
return connectParams;
|
|
183
|
-
}
|
|
184
|
-
throw new EngineSessionConnectParamsParseError(`invalid connect params: ${line}`, {
|
|
185
|
-
parsedLine: line,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
// Need to find a better way to handle this part
|
|
189
|
-
// At this stage something wrong happened, `for await` didn't return anything
|
|
190
|
-
// await the subprocess to catch the error
|
|
191
|
-
try {
|
|
192
|
-
await this.subProcess;
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
this.subProcess?.catch((e) => {
|
|
196
|
-
throw new EngineSessionError(e.stderr);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
async Close() {
|
|
201
|
-
if (this.subProcess?.pid) {
|
|
202
|
-
this.subProcess.kill("SIGTERM");
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* createCacheDir will create a cache directory on user
|
|
207
|
-
* host to store dagger binary.
|
|
208
|
-
*
|
|
209
|
-
* If set, it will use envPaths to determine system's cache directory,
|
|
210
|
-
* if not, it will use `$HOME/.cache` as base path.
|
|
211
|
-
* Nothing happens if the directory already exists.
|
|
212
|
-
*/
|
|
213
|
-
createCacheDir() {
|
|
214
|
-
fs.mkdirSync(this.cacheDir, { mode: 0o700, recursive: true });
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* buildBinPath create a path to output dagger cli binary.
|
|
218
|
-
*
|
|
219
|
-
* It will store it in the cache directory with a name composed
|
|
220
|
-
* of the base engine session as constant and the engine identifier.
|
|
221
|
-
*/
|
|
222
|
-
buildBinPath() {
|
|
223
|
-
return this.buildOsExePath(this.cacheDir, `${this.DAGGER_CLI_BIN_PREFIX}-${this.cliVersion}`);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* buildExePath create a path to output dagger cli binary.
|
|
227
|
-
*/
|
|
228
|
-
buildOsExePath(destinationDir, filename) {
|
|
229
|
-
const binPath = path.join(destinationDir, filename);
|
|
230
|
-
switch (this.normalizedOS()) {
|
|
231
|
-
case "windows":
|
|
232
|
-
return `${binPath}.exe`;
|
|
233
|
-
default:
|
|
234
|
-
return binPath;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* normalizedArch returns the architecture name used by the rest of our SDKs.
|
|
239
|
-
*/
|
|
240
|
-
normalizedArch() {
|
|
241
|
-
switch (os.arch()) {
|
|
242
|
-
case "x64":
|
|
243
|
-
return "amd64";
|
|
244
|
-
default:
|
|
245
|
-
return os.arch();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* normalizedOS returns the os name used by the rest of our SDKs.
|
|
250
|
-
*/
|
|
251
|
-
normalizedOS() {
|
|
252
|
-
switch (os.platform()) {
|
|
253
|
-
case "win32":
|
|
254
|
-
return "windows";
|
|
255
|
-
default:
|
|
256
|
-
return os.platform();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
cliArchiveName() {
|
|
260
|
-
if (OVERRIDE_CLI_URL) {
|
|
261
|
-
return path.basename(new URL(OVERRIDE_CLI_URL).pathname);
|
|
262
|
-
}
|
|
263
|
-
let ext = "tar.gz";
|
|
264
|
-
if (this.normalizedOS() === "windows") {
|
|
265
|
-
ext = "zip";
|
|
266
|
-
}
|
|
267
|
-
return `dagger_v${this.cliVersion}_${this.normalizedOS()}_${this.normalizedArch()}.${ext}`;
|
|
268
|
-
}
|
|
269
|
-
cliArchiveURL() {
|
|
270
|
-
if (OVERRIDE_CLI_URL) {
|
|
271
|
-
return OVERRIDE_CLI_URL;
|
|
272
|
-
}
|
|
273
|
-
return `https://${CLI_HOST}/dagger/releases/${this.cliVersion}/${this.cliArchiveName()}`;
|
|
274
|
-
}
|
|
275
|
-
cliChecksumURL() {
|
|
276
|
-
if (OVERRIDE_CHECKSUMS_URL) {
|
|
277
|
-
return OVERRIDE_CHECKSUMS_URL;
|
|
278
|
-
}
|
|
279
|
-
return `https://${CLI_HOST}/dagger/releases/${this.cliVersion}/checksums.txt`;
|
|
280
|
-
}
|
|
281
|
-
async checksumMap() {
|
|
282
|
-
// download checksums.txt
|
|
283
|
-
const checksums = await fetch(this.cliChecksumURL());
|
|
284
|
-
if (!checksums.ok) {
|
|
285
|
-
throw new Error(`failed to download checksums.txt from ${this.cliChecksumURL()}`);
|
|
286
|
-
}
|
|
287
|
-
const checksumsText = await checksums.text();
|
|
288
|
-
// iterate over lines filling in map of filename -> checksum
|
|
289
|
-
const checksumMap = new Map();
|
|
290
|
-
for (const line of checksumsText.split("\n")) {
|
|
291
|
-
const [checksum, filename] = line.split(/\s+/);
|
|
292
|
-
checksumMap.set(filename, checksum);
|
|
293
|
-
}
|
|
294
|
-
return checksumMap;
|
|
295
|
-
}
|
|
296
|
-
async expectedChecksum() {
|
|
297
|
-
const checksumMap = await this.checksumMap();
|
|
298
|
-
const expectedChecksum = checksumMap.get(this.cliArchiveName());
|
|
299
|
-
if (!expectedChecksum) {
|
|
300
|
-
throw new Error(`failed to find checksum for ${this.cliArchiveName()} in checksums.txt`);
|
|
301
|
-
}
|
|
302
|
-
return expectedChecksum;
|
|
303
|
-
}
|
|
304
|
-
async extractArchive(destDir, os) {
|
|
305
|
-
// extract the dagger binary in the cli archive and return the archive of the .zip for windows and .tar.gz for other plateforms
|
|
306
|
-
const archiveResp = await fetch(this.cliArchiveURL());
|
|
307
|
-
if (!archiveResp.ok) {
|
|
308
|
-
throw new Error(`failed to download dagger cli archive from ${this.cliArchiveURL()}`);
|
|
309
|
-
}
|
|
310
|
-
if (!archiveResp.body) {
|
|
311
|
-
throw new Error("archive response body is null");
|
|
312
|
-
}
|
|
313
|
-
// create a temporary file to store the archive
|
|
314
|
-
const archivePath = path.join(destDir, os === "windows" ? "dagger.zip" : "dagger.tar.gz");
|
|
315
|
-
const archiveFile = fs.createWriteStream(archivePath);
|
|
316
|
-
await new Promise((resolve, reject) => {
|
|
317
|
-
archiveResp.body?.pipe(archiveFile);
|
|
318
|
-
archiveResp.body?.on("error", reject);
|
|
319
|
-
archiveFile.on("finish", resolve);
|
|
320
|
-
});
|
|
321
|
-
const actualChecksum = crypto
|
|
322
|
-
.createHash("sha256")
|
|
323
|
-
.update(fs.readFileSync(archivePath))
|
|
324
|
-
.digest("hex");
|
|
325
|
-
if (os === "windows") {
|
|
326
|
-
const zip = new AdmZip(archivePath);
|
|
327
|
-
// extract just dagger.exe to the destdir
|
|
328
|
-
zip.extractEntryTo("dagger.exe", destDir, false, true);
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
tar.extract({
|
|
332
|
-
cwd: destDir,
|
|
333
|
-
file: archivePath,
|
|
334
|
-
sync: true,
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
return actualChecksum;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Generate a unix timestamp in nanosecond
|
|
341
|
-
*/
|
|
342
|
-
getRandomId() {
|
|
343
|
-
return process.hrtime.bigint().toString();
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
// Only meant for tests
|
|
347
|
-
export function _overrideCLIURL(url) {
|
|
348
|
-
OVERRIDE_CLI_URL = url;
|
|
349
|
-
}
|
|
350
|
-
// Only meant for tests
|
|
351
|
-
export function _overrideCLIChecksumsURL(url) {
|
|
352
|
-
OVERRIDE_CHECKSUMS_URL = url;
|
|
353
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../provisioning/default.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,WAAW,CAAA"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { GraphQLClient } from "graphql-request";
|
|
2
|
-
import { Writable } from "node:stream";
|
|
3
|
-
export interface ConnectOpts {
|
|
4
|
-
Workdir?: string;
|
|
5
|
-
Project?: string;
|
|
6
|
-
LogOutput?: Writable;
|
|
7
|
-
Timeout?: number;
|
|
8
|
-
}
|
|
9
|
-
export interface ConnectParams {
|
|
10
|
-
port: number;
|
|
11
|
-
session_token: string;
|
|
12
|
-
}
|
|
13
|
-
export interface EngineConn {
|
|
14
|
-
/**
|
|
15
|
-
* Addr returns the connector address.
|
|
16
|
-
*/
|
|
17
|
-
Addr: () => string;
|
|
18
|
-
/**
|
|
19
|
-
* Connect initializes a ready to use GraphQL Client that
|
|
20
|
-
* points to the engine.
|
|
21
|
-
*/
|
|
22
|
-
Connect: (opts: ConnectOpts) => Promise<GraphQLClient>;
|
|
23
|
-
/**
|
|
24
|
-
* Close stops the current connection.
|
|
25
|
-
*/
|
|
26
|
-
Close: () => Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=engineconn.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engineconn.d.ts","sourceRoot":"","sources":["../../provisioning/engineconn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,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,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,MAAM,CAAA;IAElB;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;IAEtD;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../telemetry/attributes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,6BAA6B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/telemetry/index.js
DELETED
package/dist/telemetry/init.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A wrapper around the OpenTelemetry SDK to configure it for Dagger.
|
|
3
|
-
*/
|
|
4
|
-
export declare class DaggerOtelConfigurator {
|
|
5
|
-
private is_configured;
|
|
6
|
-
private sdk?;
|
|
7
|
-
/**
|
|
8
|
-
* Initialize the Open Telemetry SDK if enabled or not already configured.
|
|
9
|
-
*/
|
|
10
|
-
initialize(): void;
|
|
11
|
-
configure(): void;
|
|
12
|
-
/**
|
|
13
|
-
* Shutdown the Open Telemetry SDK to flush traces and metrics and close the connection.
|
|
14
|
-
*/
|
|
15
|
-
close(): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Setup environment for auto-configuring the SDK.
|
|
18
|
-
*/
|
|
19
|
-
setupEnv(): void;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../telemetry/init.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,aAAa,CAAQ;IAE7B,OAAO,CAAC,GAAG,CAAC,CAAS;IAErB;;OAEG;IACH,UAAU;IAQV,SAAS;IAoBT;;OAEG;IACG,KAAK;IAMX;;OAEG;IACH,QAAQ;CAeT"}
|
package/dist/telemetry/init.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { getEnvWithoutDefaults } from "@opentelemetry/core";
|
|
2
|
-
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
3
|
-
const SERVICE_NAME = "dagger-typescript-sdk";
|
|
4
|
-
const env = getEnvWithoutDefaults();
|
|
5
|
-
/*
|
|
6
|
-
* Look for variables prefixed with OTel to see if OpenTelemetry is configured.
|
|
7
|
-
*/
|
|
8
|
-
function otelConfigured() {
|
|
9
|
-
return Object.keys(process.env).some((key) => key.startsWith("OTEL_"));
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A wrapper around the OpenTelemetry SDK to configure it for Dagger.
|
|
13
|
-
*/
|
|
14
|
-
export class DaggerOtelConfigurator {
|
|
15
|
-
is_configured = false;
|
|
16
|
-
sdk;
|
|
17
|
-
/**
|
|
18
|
-
* Initialize the Open Telemetry SDK if enabled or not already configured.
|
|
19
|
-
*/
|
|
20
|
-
initialize() {
|
|
21
|
-
if (this.is_configured) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
this.configure();
|
|
25
|
-
this.is_configured = true;
|
|
26
|
-
}
|
|
27
|
-
configure() {
|
|
28
|
-
if (!otelConfigured()) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (env.OTEL_SDK_DISABLED) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
this.setupEnv();
|
|
35
|
-
// Create the node SDK with the context manager, the resource and the exporter.
|
|
36
|
-
this.sdk = new NodeSDK({
|
|
37
|
-
serviceName: SERVICE_NAME,
|
|
38
|
-
});
|
|
39
|
-
// Register the SDK to the OpenTelemetry API
|
|
40
|
-
this.sdk.start();
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Shutdown the Open Telemetry SDK to flush traces and metrics and close the connection.
|
|
44
|
-
*/
|
|
45
|
-
async close() {
|
|
46
|
-
if (this.sdk) {
|
|
47
|
-
this.sdk.shutdown();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Setup environment for auto-configuring the SDK.
|
|
52
|
-
*/
|
|
53
|
-
setupEnv() {
|
|
54
|
-
// TODO: The insecure flag should be set by the shim instead of the SDK.
|
|
55
|
-
Object.entries(process.env).forEach(([key, value]) => {
|
|
56
|
-
if (key.startsWith("OTEL_") &&
|
|
57
|
-
key.endsWith("_ENDPOINT") &&
|
|
58
|
-
value?.startsWith("http://")) {
|
|
59
|
-
const insecure = key.replace(/_ENDPOINT$/, "_INSECURE");
|
|
60
|
-
if (process.env[insecure] === undefined) {
|
|
61
|
-
process.env[insecure] = "true";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as opentelemetry from "@opentelemetry/api";
|
|
2
|
-
import { Tracer } from "./tracer.js";
|
|
3
|
-
export declare function initialize(): void;
|
|
4
|
-
export declare function close(): Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Return a tracer to use with Dagger.
|
|
7
|
-
*
|
|
8
|
-
* The tracer is automatically initialized if not already done.
|
|
9
|
-
* As a conveniance function, you can use `withTracingSpan` that automatically close
|
|
10
|
-
* the span at the end of the function.
|
|
11
|
-
*
|
|
12
|
-
* You can add a custom name to the tracer based on your application.
|
|
13
|
-
*/
|
|
14
|
-
export declare function getTracer(name?: string): Tracer;
|
|
15
|
-
export declare function getContext(): opentelemetry.Context;
|
|
16
|
-
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../telemetry/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAGnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAMpC,wBAAgB,UAAU,SAEzB;AAED,wBAAsB,KAAK,kBAE1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAqB,GAAG,MAAM,CAG3D;AAED,wBAAgB,UAAU,0BAgBzB"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as opentelemetry from "@opentelemetry/api";
|
|
2
|
-
import { DaggerOtelConfigurator } from "./init.js";
|
|
3
|
-
import { Tracer } from "./tracer.js";
|
|
4
|
-
const DAGGER_TRACER_NAME = "dagger.io/sdk.typescript";
|
|
5
|
-
const configurator = new DaggerOtelConfigurator();
|
|
6
|
-
export function initialize() {
|
|
7
|
-
configurator.initialize();
|
|
8
|
-
}
|
|
9
|
-
export async function close() {
|
|
10
|
-
await configurator.close();
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Return a tracer to use with Dagger.
|
|
14
|
-
*
|
|
15
|
-
* The tracer is automatically initialized if not already done.
|
|
16
|
-
* As a conveniance function, you can use `withTracingSpan` that automatically close
|
|
17
|
-
* the span at the end of the function.
|
|
18
|
-
*
|
|
19
|
-
* You can add a custom name to the tracer based on your application.
|
|
20
|
-
*/
|
|
21
|
-
export function getTracer(name = DAGGER_TRACER_NAME) {
|
|
22
|
-
initialize();
|
|
23
|
-
return new Tracer(name);
|
|
24
|
-
}
|
|
25
|
-
export function getContext() {
|
|
26
|
-
const ctx = opentelemetry.context.active();
|
|
27
|
-
const spanCtx = opentelemetry.trace.getSpanContext(ctx);
|
|
28
|
-
if (spanCtx && opentelemetry.trace.isSpanContextValid(spanCtx)) {
|
|
29
|
-
return ctx;
|
|
30
|
-
}
|
|
31
|
-
const parentID = process.env.TRACEPARENT;
|
|
32
|
-
if (parentID) {
|
|
33
|
-
return opentelemetry.propagation.extract(ctx, {
|
|
34
|
-
traceparent: parentID,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return ctx;
|
|
38
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as opentelemetry from "@opentelemetry/api";
|
|
2
|
-
/**
|
|
3
|
-
* Tracer encapsulates the OpenTelemetry Tracer.
|
|
4
|
-
*/
|
|
5
|
-
export declare class Tracer {
|
|
6
|
-
private tracer;
|
|
7
|
-
constructor(name: string);
|
|
8
|
-
startSpan(name: string, attributes?: opentelemetry.Attributes): opentelemetry.Span;
|
|
9
|
-
/**
|
|
10
|
-
* Execute the functions with a custom span with the given name using startActiveSpan.
|
|
11
|
-
* The function executed will use the parent context of the function (it can be another span
|
|
12
|
-
* or the main function).
|
|
13
|
-
*
|
|
14
|
-
* @param name The name of the span
|
|
15
|
-
* @param fn The functions to execute
|
|
16
|
-
*
|
|
17
|
-
* startActiveSpan returns the result of the executed functions.
|
|
18
|
-
*
|
|
19
|
-
* The span is automatically ended when the function is done.
|
|
20
|
-
* The span is automatically marked as an error if the function throws an error.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```
|
|
25
|
-
* return getTracer().startActiveSpan(name, async () => {
|
|
26
|
-
* return this.containerEcho("test").stdout()
|
|
27
|
-
* })
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
startActiveSpan<T>(name: string, fn: (span: opentelemetry.Span) => Promise<T>, attributes?: opentelemetry.Attributes): Promise<T>;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=tracer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../telemetry/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAsB;gBAExB,IAAI,EAAE,MAAM;IAIjB,SAAS,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,aAAa,CAAC,UAAU,GACpC,aAAa,CAAC,IAAI;IAIrB;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,eAAe,CAAC,CAAC,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAC5C,UAAU,CAAC,EAAE,aAAa,CAAC,UAAU;CAoBxC"}
|