@dagger.io/dagger 0.0.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +88 -0
- package/dist/src/api/client.gen.d.ts +6123 -0
- package/dist/src/api/client.gen.d.ts.map +1 -0
- package/dist/src/api/client.gen.js +8494 -0
- package/dist/src/common/context.d.ts +12 -0
- package/dist/src/common/context.d.ts.map +1 -0
- package/dist/src/common/context.js +22 -0
- package/dist/src/common/errors/DaggerSDKError.d.ts +32 -0
- package/dist/src/common/errors/DaggerSDKError.d.ts.map +1 -0
- package/dist/src/common/errors/DaggerSDKError.js +26 -0
- package/dist/src/common/errors/DockerImageRefValidationError.d.ts +22 -0
- package/dist/src/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
- package/dist/src/common/errors/DockerImageRefValidationError.js +21 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.js +20 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.js +20 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.d.ts +16 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.js +16 -0
- package/dist/src/common/errors/ExecError.d.ts +42 -0
- package/dist/src/common/errors/ExecError.d.ts.map +1 -0
- package/dist/src/common/errors/ExecError.js +40 -0
- package/dist/src/common/errors/FunctionNotFound.d.ts +7 -0
- package/dist/src/common/errors/FunctionNotFound.d.ts.map +1 -0
- package/dist/src/common/errors/FunctionNotFound.js +9 -0
- package/dist/src/common/errors/GraphQLRequestError.d.ts +31 -0
- package/dist/src/common/errors/GraphQLRequestError.d.ts.map +1 -0
- package/dist/src/common/errors/GraphQLRequestError.js +30 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts +13 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.js +15 -0
- package/dist/src/common/errors/IntrospectionError.d.ts +7 -0
- package/dist/src/common/errors/IntrospectionError.d.ts.map +1 -0
- package/dist/src/common/errors/IntrospectionError.js +9 -0
- package/dist/src/common/errors/NotAwaitedRequestError.d.ts +13 -0
- package/dist/src/common/errors/NotAwaitedRequestError.d.ts.map +1 -0
- package/dist/src/common/errors/NotAwaitedRequestError.js +15 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.d.ts +21 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.js +20 -0
- package/dist/src/common/errors/UnknownDaggerError.d.ts +13 -0
- package/dist/src/common/errors/UnknownDaggerError.d.ts.map +1 -0
- package/dist/src/common/errors/UnknownDaggerError.js +15 -0
- package/dist/src/common/errors/errors-codes.d.ts +55 -0
- package/dist/src/common/errors/errors-codes.d.ts.map +1 -0
- package/dist/src/common/errors/errors-codes.js +47 -0
- package/dist/src/common/errors/index.d.ts +15 -0
- package/dist/src/common/errors/index.d.ts.map +1 -0
- package/dist/src/common/errors/index.js +14 -0
- package/dist/src/common/graphql/client.d.ts +3 -0
- package/dist/src/common/graphql/client.d.ts.map +1 -0
- package/dist/src/common/graphql/client.js +58 -0
- package/dist/src/common/graphql/compute_query.d.ts +37 -0
- package/dist/src/common/graphql/compute_query.d.ts.map +1 -0
- package/dist/src/common/graphql/compute_query.js +171 -0
- package/dist/src/common/graphql/connect.d.ts +8 -0
- package/dist/src/common/graphql/connect.d.ts.map +1 -0
- package/dist/src/common/graphql/connect.js +22 -0
- package/dist/src/common/graphql/connection.d.ts +14 -0
- package/dist/src/common/graphql/connection.d.ts.map +1 -0
- package/dist/src/common/graphql/connection.js +23 -0
- package/dist/src/common/utils.d.ts +70 -0
- package/dist/src/common/utils.d.ts.map +1 -0
- package/dist/src/common/utils.js +6 -0
- package/dist/src/connect.d.ts +28 -0
- package/dist/src/connect.d.ts.map +1 -0
- package/dist/src/connect.js +64 -0
- package/dist/src/connectOpts.d.ts +24 -0
- package/dist/src/connectOpts.d.ts.map +1 -0
- package/dist/src/connectOpts.js +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/src/module/decorators.d.ts +52 -0
- package/dist/src/module/decorators.d.ts.map +1 -0
- package/dist/src/module/decorators.js +55 -0
- package/dist/src/module/entrypoint/context.d.ts +8 -0
- package/dist/src/module/entrypoint/context.d.ts.map +1 -0
- package/dist/src/module/entrypoint/context.js +1 -0
- package/dist/src/module/entrypoint/entrypoint.d.ts +2 -0
- package/dist/src/module/entrypoint/entrypoint.d.ts.map +1 -0
- package/dist/src/module/entrypoint/entrypoint.js +92 -0
- package/dist/src/module/entrypoint/introspection_entrypoint.d.ts +2 -0
- package/dist/src/module/entrypoint/introspection_entrypoint.d.ts.map +1 -0
- package/dist/src/module/entrypoint/introspection_entrypoint.js +52 -0
- package/dist/src/module/entrypoint/invoke.d.ts +14 -0
- package/dist/src/module/entrypoint/invoke.d.ts.map +1 -0
- package/dist/src/module/entrypoint/invoke.js +66 -0
- package/dist/src/module/entrypoint/load.d.ts +53 -0
- package/dist/src/module/entrypoint/load.d.ts.map +1 -0
- package/dist/src/module/entrypoint/load.js +237 -0
- package/dist/src/module/entrypoint/register.d.ts +33 -0
- package/dist/src/module/entrypoint/register.d.ts.map +1 -0
- package/dist/src/module/entrypoint/register.js +227 -0
- package/dist/src/module/executor.d.ts +28 -0
- package/dist/src/module/executor.d.ts.map +1 -0
- package/dist/src/module/executor.js +171 -0
- package/dist/src/module/introspector/case_convertor.d.ts +2 -0
- package/dist/src/module/introspector/case_convertor.d.ts.map +1 -0
- package/dist/src/module/introspector/case_convertor.js +15 -0
- package/dist/src/module/introspector/dagger_module/argument.d.ts +50 -0
- package/dist/src/module/introspector/dagger_module/argument.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/argument.js +118 -0
- package/dist/src/module/introspector/dagger_module/constructor.d.ts +18 -0
- package/dist/src/module/introspector/dagger_module/constructor.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/constructor.js +38 -0
- package/dist/src/module/introspector/dagger_module/decorator.d.ts +8 -0
- package/dist/src/module/introspector/dagger_module/decorator.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/decorator.js +7 -0
- package/dist/src/module/introspector/dagger_module/enum.d.ts +41 -0
- package/dist/src/module/introspector/dagger_module/enum.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enum.js +63 -0
- package/dist/src/module/introspector/dagger_module/enumBase.d.ts +19 -0
- package/dist/src/module/introspector/dagger_module/enumBase.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enumBase.js +1 -0
- package/dist/src/module/introspector/dagger_module/enumClass.d.ts +41 -0
- package/dist/src/module/introspector/dagger_module/enumClass.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enumClass.js +69 -0
- package/dist/src/module/introspector/dagger_module/function.d.ts +39 -0
- package/dist/src/module/introspector/dagger_module/function.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/function.js +102 -0
- package/dist/src/module/introspector/dagger_module/index.d.ts +15 -0
- package/dist/src/module/introspector/dagger_module/index.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/index.js +14 -0
- package/dist/src/module/introspector/dagger_module/interface.d.ts +25 -0
- package/dist/src/module/introspector/dagger_module/interface.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/interface.js +56 -0
- package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts +35 -0
- package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/interfaceFunction.js +92 -0
- package/dist/src/module/introspector/dagger_module/locatable.d.ts +12 -0
- package/dist/src/module/introspector/dagger_module/locatable.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/locatable.js +14 -0
- package/dist/src/module/introspector/dagger_module/module.d.ts +118 -0
- package/dist/src/module/introspector/dagger_module/module.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/module.js +316 -0
- package/dist/src/module/introspector/dagger_module/object.d.ts +46 -0
- package/dist/src/module/introspector/dagger_module/object.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/object.js +113 -0
- package/dist/src/module/introspector/dagger_module/objectBase.d.ts +32 -0
- package/dist/src/module/introspector/dagger_module/objectBase.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/objectBase.js +1 -0
- package/dist/src/module/introspector/dagger_module/property.d.ts +36 -0
- package/dist/src/module/introspector/dagger_module/property.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/property.js +82 -0
- package/dist/src/module/introspector/dagger_module/reference.d.ts +13 -0
- package/dist/src/module/introspector/dagger_module/reference.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/reference.js +33 -0
- package/dist/src/module/introspector/dagger_module/typeObject.d.ts +49 -0
- package/dist/src/module/introspector/dagger_module/typeObject.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/typeObject.js +87 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts +34 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.js +60 -0
- package/dist/src/module/introspector/index.d.ts +3 -0
- package/dist/src/module/introspector/index.d.ts.map +1 -0
- package/dist/src/module/introspector/index.js +19 -0
- package/dist/src/module/introspector/typedef.d.ts +52 -0
- package/dist/src/module/introspector/typedef.d.ts.map +1 -0
- package/dist/src/module/introspector/typedef.js +1 -0
- package/dist/src/module/introspector/typescript_module/ast.d.ts +64 -0
- package/dist/src/module/introspector/typescript_module/ast.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/ast.js +476 -0
- package/dist/src/module/introspector/typescript_module/declarations.d.ts +15 -0
- package/dist/src/module/introspector/typescript_module/declarations.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/declarations.js +10 -0
- package/dist/src/module/introspector/typescript_module/index.d.ts +4 -0
- package/dist/src/module/introspector/typescript_module/index.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/index.js +3 -0
- package/dist/src/module/introspector/typescript_module/location.d.ts +6 -0
- package/dist/src/module/introspector/typescript_module/location.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/location.js +1 -0
- package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts +5 -0
- package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/typedef_utils.js +26 -0
- package/dist/src/module/introspector/utils/files.d.ts +5 -0
- package/dist/src/module/introspector/utils/files.d.ts.map +1 -0
- package/dist/src/module/introspector/utils/files.js +28 -0
- package/dist/src/module/registry.d.ts +109 -0
- package/dist/src/module/registry.d.ts.map +1 -0
- package/dist/src/module/registry.js +123 -0
- package/dist/src/provisioning/bin.d.ts +77 -0
- package/dist/src/provisioning/bin.d.ts.map +1 -0
- package/dist/src/provisioning/bin.js +353 -0
- package/dist/src/provisioning/default.d.ts +2 -0
- package/dist/src/provisioning/default.d.ts.map +1 -0
- package/dist/src/provisioning/default.js +2 -0
- package/dist/src/provisioning/engineconn.d.ts +30 -0
- package/dist/src/provisioning/engineconn.d.ts.map +1 -0
- package/dist/src/provisioning/engineconn.js +1 -0
- package/dist/src/provisioning/index.d.ts +4 -0
- package/dist/src/provisioning/index.d.ts.map +1 -0
- package/dist/src/provisioning/index.js +14 -0
- package/dist/src/telemetry/index.d.ts +3 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +2 -0
- package/dist/src/telemetry/init.d.ts +21 -0
- package/dist/src/telemetry/init.d.ts.map +1 -0
- package/dist/src/telemetry/init.js +86 -0
- package/dist/src/telemetry/live_processor.d.ts +12 -0
- package/dist/src/telemetry/live_processor.d.ts.map +1 -0
- package/dist/src/telemetry/live_processor.js +13 -0
- package/dist/src/telemetry/telemetry.d.ts +16 -0
- package/dist/src/telemetry/telemetry.d.ts.map +1 -0
- package/dist/src/telemetry/telemetry.js +38 -0
- package/dist/src/telemetry/tracer.d.ts +32 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -0
- package/dist/src/telemetry/tracer.js +54 -0
- package/package.json +74 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
export type Class = {
|
|
3
|
+
new (...args: any[]): any;
|
|
4
|
+
};
|
|
5
|
+
export type State = {
|
|
6
|
+
[property: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export type Args = Record<string, unknown>;
|
|
9
|
+
export type ArgumentOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* The contextual value to use for the argument.
|
|
12
|
+
*
|
|
13
|
+
* This should only be used for Directory/File or GitRepository/GitRef types.
|
|
14
|
+
*
|
|
15
|
+
* An absolute path would be related to the context source directory (the git repo root or the module source root).
|
|
16
|
+
* A relative path would be relative to the module source root.
|
|
17
|
+
*/
|
|
18
|
+
defaultPath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Patterns to ignore when loading the contextual argument value.
|
|
21
|
+
*
|
|
22
|
+
* This should only be used for Directory types.
|
|
23
|
+
*/
|
|
24
|
+
ignore?: string[];
|
|
25
|
+
};
|
|
26
|
+
export type FunctionOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* The caching behavior of this function.
|
|
29
|
+
* "never" means no caching.
|
|
30
|
+
* "session" means caching only for the duration of the current client's session.
|
|
31
|
+
* A duration string (e.g., "5m", "1h") means persistent caching for that duration.
|
|
32
|
+
* By default, caching is enabled with a long default set by the engine.
|
|
33
|
+
*/
|
|
34
|
+
cache?: "never" | "session" | string;
|
|
35
|
+
/**
|
|
36
|
+
* An optional alias to use for the function when exposed on the API.
|
|
37
|
+
*/
|
|
38
|
+
alias?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Registry stores class and method that have the @object decorator.
|
|
42
|
+
*
|
|
43
|
+
* This is a convenient way to make possible the invocation of class' function.
|
|
44
|
+
*
|
|
45
|
+
* The decorator @object store the class into the Registry, but also all the
|
|
46
|
+
* users method's name.
|
|
47
|
+
* It doesn't consider the `@func` decorator because this is
|
|
48
|
+
* used by the Dagger API to know what to expose or not.
|
|
49
|
+
* This might lead to unnecessary data register into the registry, but
|
|
50
|
+
* we use map as datastructure to optimize the searching process
|
|
51
|
+
* since we directly look through a key into the `class_` member of
|
|
52
|
+
* RegistryClass.
|
|
53
|
+
*/
|
|
54
|
+
export declare class Registry {
|
|
55
|
+
/**
|
|
56
|
+
* The definition of the @object decorator that should be on top of any
|
|
57
|
+
* class module that must be exposed to the Dagger API.
|
|
58
|
+
*/
|
|
59
|
+
object: () => (<T extends Class>(constructor: T) => T);
|
|
60
|
+
/**
|
|
61
|
+
* The definition of the @enum decorator that should be on top of any
|
|
62
|
+
* class module that must be exposed to the Dagger API as enumeration.
|
|
63
|
+
*
|
|
64
|
+
* @deprecated In favor of using TypeScript `enum` types.
|
|
65
|
+
*/
|
|
66
|
+
enumType: () => (<T extends Class>(constructor: T) => T);
|
|
67
|
+
/**
|
|
68
|
+
* The definition of @field decorator that should be on top of any
|
|
69
|
+
* class' property that must be exposed to the Dagger API.
|
|
70
|
+
*
|
|
71
|
+
* @deprecated In favor of `@func`
|
|
72
|
+
* @param alias The alias to use for the field when exposed on the API.
|
|
73
|
+
*/
|
|
74
|
+
field: (alias?: string) => ((target: object, propertyKey: string) => void);
|
|
75
|
+
/**
|
|
76
|
+
* The definition of @func decorator that should be on top of any
|
|
77
|
+
* class' method that must be exposed to the Dagger API.
|
|
78
|
+
*/
|
|
79
|
+
func: (opts?: FunctionOptions | string) => ((target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => void);
|
|
80
|
+
/**
|
|
81
|
+
* The definition of @check decorator that marks a function as a check.
|
|
82
|
+
*/
|
|
83
|
+
check: () => ((target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => void);
|
|
84
|
+
argument: (opts?: ArgumentOptions) => ((target: object, propertyKey: string | undefined, parameterIndex: number) => void);
|
|
85
|
+
/**
|
|
86
|
+
* Build a class that is part of the module itself so you can
|
|
87
|
+
* access its sub functions.
|
|
88
|
+
*
|
|
89
|
+
* If there's no class associated, return the object itself.
|
|
90
|
+
*/
|
|
91
|
+
buildClass(object: string, state: State): any;
|
|
92
|
+
/**
|
|
93
|
+
* getResult check for the object and method in the registry and call it
|
|
94
|
+
* with the given input and state.
|
|
95
|
+
*
|
|
96
|
+
* This is the function responsible for any module methods execution.
|
|
97
|
+
*
|
|
98
|
+
* @param object The class to look for
|
|
99
|
+
* @param method The method to call in the class
|
|
100
|
+
* @param state The current state of the class
|
|
101
|
+
* @param inputs The input to send to the method to call
|
|
102
|
+
*/
|
|
103
|
+
getResult(object: string, method: string, state: State, inputs: Args): Promise<any>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The default registry used in any module.
|
|
107
|
+
*/
|
|
108
|
+
export declare const registry: Registry;
|
|
109
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/module/registry.ts"],"names":[],"mappings":"AAIA,OAAO,kBAAkB,CAAA;AAIzB,MAAM,MAAM,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,CAAA;AAEjD,MAAM,MAAM,KAAK,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAE/C,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAU1C,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAA;IAEpC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;IACnB;;;OAGG;IACH,MAAM,QAAO,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,CAMpD;IAED;;;;;OAKG;IACH,QAAQ,QAAO,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,CAItD;IAED;;;;;;OAMG;IACH,KAAK,GAAI,QAAQ,MAAM,KAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC,CAIxE;IAED;;;OAGG;IACH,IAAI,GACF,OAAO,eAAe,GAAG,MAAM,KAC9B,CAAC,CACF,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,UAAU,CAAC,EAAE,kBAAkB,KAC5B,IAAI,CAAC,CAMT;IAED;;OAEG;IACH,KAAK,QAAO,CAAC,CACX,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,UAAU,CAAC,EAAE,kBAAkB,KAC5B,IAAI,CAAC,CAMT;IAED,QAAQ,GACN,OAAO,eAAe,KACrB,CAAC,CACF,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,cAAc,EAAE,MAAM,KACnB,IAAI,CAAC,CAMT;IAED;;;;;OAKG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG;IAY7C;;;;;;;;;;OAUG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GACX,OAAO,CAAC,GAAG,CAAC;CAiChB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAiB,CAAA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
// @experimentalDecorators
|
|
4
|
+
// @emitDecoratorMetadata
|
|
5
|
+
import "reflect-metadata";
|
|
6
|
+
import { UnknownDaggerError } from "../common/errors/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Registry stores class and method that have the @object decorator.
|
|
9
|
+
*
|
|
10
|
+
* This is a convenient way to make possible the invocation of class' function.
|
|
11
|
+
*
|
|
12
|
+
* The decorator @object store the class into the Registry, but also all the
|
|
13
|
+
* users method's name.
|
|
14
|
+
* It doesn't consider the `@func` decorator because this is
|
|
15
|
+
* used by the Dagger API to know what to expose or not.
|
|
16
|
+
* This might lead to unnecessary data register into the registry, but
|
|
17
|
+
* we use map as datastructure to optimize the searching process
|
|
18
|
+
* since we directly look through a key into the `class_` member of
|
|
19
|
+
* RegistryClass.
|
|
20
|
+
*/
|
|
21
|
+
export class Registry {
|
|
22
|
+
/**
|
|
23
|
+
* The definition of the @object decorator that should be on top of any
|
|
24
|
+
* class module that must be exposed to the Dagger API.
|
|
25
|
+
*/
|
|
26
|
+
object = () => {
|
|
27
|
+
return (constructor) => {
|
|
28
|
+
Reflect.defineMetadata(constructor.name, { class_: constructor }, this);
|
|
29
|
+
return constructor;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The definition of the @enum decorator that should be on top of any
|
|
34
|
+
* class module that must be exposed to the Dagger API as enumeration.
|
|
35
|
+
*
|
|
36
|
+
* @deprecated In favor of using TypeScript `enum` types.
|
|
37
|
+
*/
|
|
38
|
+
enumType = () => {
|
|
39
|
+
return (constructor) => {
|
|
40
|
+
return constructor;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The definition of @field decorator that should be on top of any
|
|
45
|
+
* class' property that must be exposed to the Dagger API.
|
|
46
|
+
*
|
|
47
|
+
* @deprecated In favor of `@func`
|
|
48
|
+
* @param alias The alias to use for the field when exposed on the API.
|
|
49
|
+
*/
|
|
50
|
+
field = (alias) => {
|
|
51
|
+
return (target, propertyKey) => {
|
|
52
|
+
// A placeholder to declare field in the registry.
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The definition of @func decorator that should be on top of any
|
|
57
|
+
* class' method that must be exposed to the Dagger API.
|
|
58
|
+
*/
|
|
59
|
+
func = (opts) => {
|
|
60
|
+
return (target, propertyKey, descriptor) => { };
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The definition of @check decorator that marks a function as a check.
|
|
64
|
+
*/
|
|
65
|
+
check = () => {
|
|
66
|
+
return (target, propertyKey, descriptor) => { };
|
|
67
|
+
};
|
|
68
|
+
argument = (opts) => {
|
|
69
|
+
return (target, propertyKey, parameterIndex) => { };
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Build a class that is part of the module itself so you can
|
|
73
|
+
* access its sub functions.
|
|
74
|
+
*
|
|
75
|
+
* If there's no class associated, return the object itself.
|
|
76
|
+
*/
|
|
77
|
+
buildClass(object, state) {
|
|
78
|
+
const resolver = Reflect.getMetadata(object, this);
|
|
79
|
+
if (!resolver) {
|
|
80
|
+
return object;
|
|
81
|
+
}
|
|
82
|
+
let r = Object.create(resolver.class_.prototype);
|
|
83
|
+
r = Object.assign(r, state);
|
|
84
|
+
return r;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* getResult check for the object and method in the registry and call it
|
|
88
|
+
* with the given input and state.
|
|
89
|
+
*
|
|
90
|
+
* This is the function responsible for any module methods execution.
|
|
91
|
+
*
|
|
92
|
+
* @param object The class to look for
|
|
93
|
+
* @param method The method to call in the class
|
|
94
|
+
* @param state The current state of the class
|
|
95
|
+
* @param inputs The input to send to the method to call
|
|
96
|
+
*/
|
|
97
|
+
async getResult(object, method, state, inputs) {
|
|
98
|
+
// Retrieve the resolver class from its key
|
|
99
|
+
const resolver = Reflect.getMetadata(object, this);
|
|
100
|
+
if (!resolver) {
|
|
101
|
+
throw new UnknownDaggerError(`${object} is not register as a resolver`, {});
|
|
102
|
+
}
|
|
103
|
+
// If method is nil, apply the constructor.
|
|
104
|
+
if (method === "") {
|
|
105
|
+
return new resolver.class_(...Object.values(inputs));
|
|
106
|
+
}
|
|
107
|
+
// Instantiate the class without calling the constructor
|
|
108
|
+
let r = Object.create(resolver.class_.prototype);
|
|
109
|
+
// Safety check to make sure the method called exist in the class
|
|
110
|
+
// to avoid the app to crash brutally.
|
|
111
|
+
if (!r[method]) {
|
|
112
|
+
throw new UnknownDaggerError(`${method} is not registered in the resolver ${object}`, {});
|
|
113
|
+
}
|
|
114
|
+
// Apply state to the class
|
|
115
|
+
r = Object.assign(r, state);
|
|
116
|
+
// Execute and return the result
|
|
117
|
+
return await r[method](...Object.values(inputs));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The default registry used in any module.
|
|
122
|
+
*/
|
|
123
|
+
export const registry = new Registry();
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ResultPromise } from "execa";
|
|
2
|
+
import { GraphQLClient } from "graphql-request";
|
|
3
|
+
import { ConnectOpts, EngineConn } from "./engineconn.js";
|
|
4
|
+
export type ExecaChildProcess = ResultPromise<{
|
|
5
|
+
stdio: "pipe";
|
|
6
|
+
reject: true;
|
|
7
|
+
cleanup: true;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Bin runs an engine session from a specified binary
|
|
11
|
+
*/
|
|
12
|
+
export declare class Bin implements EngineConn {
|
|
13
|
+
private _subProcess?;
|
|
14
|
+
private binPath?;
|
|
15
|
+
private cliVersion?;
|
|
16
|
+
private readonly cacheDir;
|
|
17
|
+
private readonly DAGGER_CLI_BIN_PREFIX;
|
|
18
|
+
constructor(binPath?: string, cliVersion?: string);
|
|
19
|
+
Addr(): string;
|
|
20
|
+
get subProcess(): ExecaChildProcess | undefined;
|
|
21
|
+
Connect(opts: ConnectOpts): Promise<GraphQLClient>;
|
|
22
|
+
private downloadCLI;
|
|
23
|
+
/**
|
|
24
|
+
* Traverse up the directory tree to find the package.json file and return the
|
|
25
|
+
* SDK version.
|
|
26
|
+
* @returns the SDK version or "n/a" if the version cannot be found.
|
|
27
|
+
*/
|
|
28
|
+
private getSDKVersion;
|
|
29
|
+
/**
|
|
30
|
+
* runEngineSession execute the engine binary and set up a GraphQL client that
|
|
31
|
+
* target this engine.
|
|
32
|
+
*/
|
|
33
|
+
private runEngineSession;
|
|
34
|
+
private readConnectParams;
|
|
35
|
+
Close(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* createCacheDir will create a cache directory on user
|
|
38
|
+
* host to store dagger binary.
|
|
39
|
+
*
|
|
40
|
+
* If set, it will use envPaths to determine system's cache directory,
|
|
41
|
+
* if not, it will use `$HOME/.cache` as base path.
|
|
42
|
+
* Nothing happens if the directory already exists.
|
|
43
|
+
*/
|
|
44
|
+
private createCacheDir;
|
|
45
|
+
/**
|
|
46
|
+
* buildBinPath create a path to output dagger cli binary.
|
|
47
|
+
*
|
|
48
|
+
* It will store it in the cache directory with a name composed
|
|
49
|
+
* of the base engine session as constant and the engine identifier.
|
|
50
|
+
*/
|
|
51
|
+
private buildBinPath;
|
|
52
|
+
/**
|
|
53
|
+
* buildExePath create a path to output dagger cli binary.
|
|
54
|
+
*/
|
|
55
|
+
private buildOsExePath;
|
|
56
|
+
/**
|
|
57
|
+
* normalizedArch returns the architecture name used by the rest of our SDKs.
|
|
58
|
+
*/
|
|
59
|
+
private normalizedArch;
|
|
60
|
+
/**
|
|
61
|
+
* normalizedOS returns the os name used by the rest of our SDKs.
|
|
62
|
+
*/
|
|
63
|
+
private normalizedOS;
|
|
64
|
+
private cliArchiveName;
|
|
65
|
+
private cliArchiveURL;
|
|
66
|
+
private cliChecksumURL;
|
|
67
|
+
private checksumMap;
|
|
68
|
+
private expectedChecksum;
|
|
69
|
+
private extractArchive;
|
|
70
|
+
/**
|
|
71
|
+
* Generate a unix timestamp in nanosecond
|
|
72
|
+
*/
|
|
73
|
+
private getRandomId;
|
|
74
|
+
}
|
|
75
|
+
export declare function _overrideCLIURL(url: string): void;
|
|
76
|
+
export declare function _overrideCLIChecksumsURL(url: string): void;
|
|
77
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../../src/provisioning/bin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,aAAa,EAAE,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAgB/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAA;AAMxE,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;IAC5C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,IAAI,CAAA;IACZ,OAAO,EAAE,IAAI,CAAA;CACd,CAAC,CAAA;AAEF;;GAEG;AACH,qBAAa,GAAI,YAAW,UAAU;IACpC,OAAO,CAAC,WAAW,CAAC,CAAmB;IAEvC,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,UAAU,CAAC,CAAQ;IAE3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGxB;IAED,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAW;gBAErC,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;IAKjD,IAAI,IAAI,MAAM;IAId,IAAI,UAAU,IAAI,iBAAiB,GAAG,SAAS,CAE9C;IAEK,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;YAgB1C,WAAW;IAkEzB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAqBrB;;;OAGG;YACW,gBAAgB;YA2EhB,iBAAiB;IA6BzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;YAOR,WAAW;YAkBX,gBAAgB;YAWhB,cAAc;IA4C5B;;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,353 @@
|
|
|
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 "../common/graphql/client.js";
|
|
15
|
+
let OVERRIDE_CLI_URL = "";
|
|
16
|
+
let OVERRIDE_CHECKSUMS_URL = "";
|
|
17
|
+
const CLI_HOST = "dl.dagger.io";
|
|
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 && 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 && 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 && 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(undefined));
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../src/provisioning/default.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,WAAW,CAAA"}
|