@webiny/pulumi-sdk 5.25.0 → 5.26.0-beta.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/ApplicationBuilder.d.ts +39 -0
- package/ApplicationBuilder.js +37 -0
- package/ApplicationBuilder.js.map +1 -0
- package/ApplicationBuilderGeneric.d.ts +10 -0
- package/ApplicationBuilderGeneric.js +104 -0
- package/ApplicationBuilderGeneric.js.map +1 -0
- package/ApplicationBuilderLegacy.d.ts +4 -0
- package/ApplicationBuilderLegacy.js +91 -0
- package/ApplicationBuilderLegacy.js.map +1 -0
- package/ApplicationConfig.d.ts +16 -0
- package/ApplicationConfig.js +5 -0
- package/ApplicationConfig.js.map +1 -0
- package/ApplicationHook.d.ts +4 -0
- package/ApplicationHook.js +11 -0
- package/ApplicationHook.js.map +1 -0
- package/Pulumi.d.ts +40 -0
- package/Pulumi.js +132 -0
- package/Pulumi.js.map +1 -0
- package/PulumiApp.d.ts +76 -0
- package/PulumiApp.js +174 -0
- package/PulumiApp.js.map +1 -0
- package/PulumiAppModule.d.ts +17 -0
- package/PulumiAppModule.js +30 -0
- package/PulumiAppModule.js.map +1 -0
- package/PulumiResource.d.ts +22 -0
- package/PulumiResource.js +48 -0
- package/PulumiResource.js.map +1 -0
- package/index.d.ts +12 -40
- package/index.js +131 -102
- package/index.js.map +1 -1
- package/package.json +7 -6
- package/utils/getPulumiWorkDir.d.ts +1 -0
- package/utils/getPulumiWorkDir.js +14 -0
- package/utils/getPulumiWorkDir.js.map +1 -0
- package/utils/mergeAppHooks.d.ts +2 -0
- package/utils/mergeAppHooks.js +20 -0
- package/utils/mergeAppHooks.js.map +1 -0
- package/utils/tagResources.d.ts +5 -0
- package/utils/tagResources.js +52 -0
- package/utils/tagResources.js.map +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PreviewResult, RefreshResult, UpResult } from "@pulumi/pulumi/automation";
|
|
2
|
+
import { ApplicationHooks } from "./ApplicationConfig";
|
|
3
|
+
import { ApplicationHook } from "./ApplicationHook";
|
|
4
|
+
import { Pulumi } from "./Pulumi";
|
|
5
|
+
import { PulumiApp } from "./PulumiApp";
|
|
6
|
+
export interface ApplicationStackArgs {
|
|
7
|
+
/** Root path of the application */
|
|
8
|
+
appDir: string;
|
|
9
|
+
/** Root dir of the project */
|
|
10
|
+
projectDir: string;
|
|
11
|
+
pulumi: Pulumi;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
env: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ApplicationBuilderConfig extends Partial<ApplicationHooks> {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
cli?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export interface ApplicationStack {
|
|
22
|
+
app?: PulumiApp;
|
|
23
|
+
refresh(): Promise<RefreshResult | undefined>;
|
|
24
|
+
preview(): Promise<PreviewResult | undefined>;
|
|
25
|
+
up(): Promise<UpResult | undefined>;
|
|
26
|
+
}
|
|
27
|
+
export declare abstract class ApplicationBuilder<TConfig extends ApplicationBuilderConfig = ApplicationBuilderConfig> implements ApplicationBuilderConfig {
|
|
28
|
+
readonly config: TConfig;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly description?: string;
|
|
32
|
+
readonly cli?: Record<string, any>;
|
|
33
|
+
readonly onBeforeBuild?: ApplicationHook;
|
|
34
|
+
readonly onAfterBuild?: ApplicationHook;
|
|
35
|
+
readonly onBeforeDeploy?: ApplicationHook;
|
|
36
|
+
readonly onAfterDeploy?: ApplicationHook;
|
|
37
|
+
constructor(config: TConfig);
|
|
38
|
+
abstract createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ApplicationBuilder = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
class ApplicationBuilder {
|
|
13
|
+
// It needs to duplicate configuration props for backwards compatibility.
|
|
14
|
+
// There is a lot of CLI code, that depends on it.
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
(0, _defineProperty2.default)(this, "id", void 0);
|
|
18
|
+
(0, _defineProperty2.default)(this, "name", void 0);
|
|
19
|
+
(0, _defineProperty2.default)(this, "description", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "cli", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "onBeforeBuild", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "onAfterBuild", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "onBeforeDeploy", void 0);
|
|
24
|
+
(0, _defineProperty2.default)(this, "onAfterDeploy", void 0);
|
|
25
|
+
this.id = config.id;
|
|
26
|
+
this.name = config.name;
|
|
27
|
+
this.description = config.description;
|
|
28
|
+
this.cli = config.cli;
|
|
29
|
+
this.onBeforeBuild = config.onBeforeBuild;
|
|
30
|
+
this.onAfterBuild = config.onAfterBuild;
|
|
31
|
+
this.onBeforeDeploy = config.onBeforeDeploy;
|
|
32
|
+
this.onAfterDeploy = config.onAfterDeploy;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.ApplicationBuilder = ApplicationBuilder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ApplicationBuilder.ts"],"names":["ApplicationBuilder","constructor","config","id","name","description","cli","onBeforeBuild","onAfterBuild","onBeforeDeploy","onAfterDeploy"],"mappings":";;;;;;;;;;;AA8BO,MAAeA,kBAAf,CAGP;AACI;AACA;AAUAC,EAAAA,WAAW,CAAiBC,MAAjB,EAAkC;AAAA,SAAjBA,MAAiB,GAAjBA,MAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACzC,SAAKC,EAAL,GAAUD,MAAM,CAACC,EAAjB;AACA,SAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;AACA,SAAKC,WAAL,GAAmBH,MAAM,CAACG,WAA1B;AACA,SAAKC,GAAL,GAAWJ,MAAM,CAACI,GAAlB;AACA,SAAKC,aAAL,GAAqBL,MAAM,CAACK,aAA5B;AACA,SAAKC,YAAL,GAAoBN,MAAM,CAACM,YAA3B;AACA,SAAKC,cAAL,GAAsBP,MAAM,CAACO,cAA7B;AACA,SAAKC,aAAL,GAAqBR,MAAM,CAACQ,aAA5B;AACH;;AArBL","sourcesContent":["import { PreviewResult, RefreshResult, UpResult } from \"@pulumi/pulumi/automation\";\nimport { ApplicationHooks } from \"./ApplicationConfig\";\nimport { ApplicationHook } from \"./ApplicationHook\";\nimport { Pulumi } from \"./Pulumi\";\nimport { PulumiApp } from \"./PulumiApp\";\n\nexport interface ApplicationStackArgs {\n /** Root path of the application */\n appDir: string;\n /** Root dir of the project */\n projectDir: string;\n pulumi: Pulumi;\n debug?: boolean;\n env: string;\n}\n\nexport interface ApplicationBuilderConfig extends Partial<ApplicationHooks> {\n id: string;\n name: string;\n description?: string;\n cli?: Record<string, any>;\n}\n\nexport interface ApplicationStack {\n app?: PulumiApp;\n refresh(): Promise<RefreshResult | undefined>;\n preview(): Promise<PreviewResult | undefined>;\n up(): Promise<UpResult | undefined>;\n}\n\nexport abstract class ApplicationBuilder<\n TConfig extends ApplicationBuilderConfig = ApplicationBuilderConfig\n> implements ApplicationBuilderConfig\n{\n // It needs to duplicate configuration props for backwards compatibility.\n // There is a lot of CLI code, that depends on it.\n public readonly id: string;\n public readonly name: string;\n public readonly description?: string;\n public readonly cli?: Record<string, any>;\n public readonly onBeforeBuild?: ApplicationHook;\n public readonly onAfterBuild?: ApplicationHook;\n public readonly onBeforeDeploy?: ApplicationHook;\n public readonly onAfterDeploy?: ApplicationHook;\n\n constructor(public readonly config: TConfig) {\n this.id = config.id;\n this.name = config.name;\n this.description = config.description;\n this.cli = config.cli;\n this.onBeforeBuild = config.onBeforeBuild;\n this.onAfterBuild = config.onAfterBuild;\n this.onBeforeDeploy = config.onBeforeDeploy;\n this.onAfterDeploy = config.onAfterDeploy;\n }\n\n public abstract createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack>;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PulumiApp } from "./PulumiApp";
|
|
2
|
+
import { ApplicationBuilder, ApplicationBuilderConfig, ApplicationStack, ApplicationStackArgs } from "./ApplicationBuilder";
|
|
3
|
+
import { ApplicationContext } from "./ApplicationConfig";
|
|
4
|
+
export interface ApplicationGenericConfig extends ApplicationBuilderConfig {
|
|
5
|
+
app(ctx: ApplicationContext): Promise<PulumiApp> | PulumiApp;
|
|
6
|
+
}
|
|
7
|
+
export declare class ApplicationBuilderGeneric extends ApplicationBuilder<ApplicationGenericConfig> {
|
|
8
|
+
createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack>;
|
|
9
|
+
}
|
|
10
|
+
export declare function createGenericApplication(config: ApplicationGenericConfig): ApplicationBuilderGeneric;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ApplicationBuilderGeneric = void 0;
|
|
9
|
+
exports.createGenericApplication = createGenericApplication;
|
|
10
|
+
|
|
11
|
+
var _os = _interopRequireDefault(require("os"));
|
|
12
|
+
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
|
|
15
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
16
|
+
|
|
17
|
+
var _trimNewlines = _interopRequireDefault(require("trim-newlines"));
|
|
18
|
+
|
|
19
|
+
var _automation = require("@pulumi/pulumi/automation");
|
|
20
|
+
|
|
21
|
+
var _getPulumiWorkDir = require("./utils/getPulumiWorkDir");
|
|
22
|
+
|
|
23
|
+
var _ApplicationBuilder = require("./ApplicationBuilder");
|
|
24
|
+
|
|
25
|
+
class ApplicationBuilderGeneric extends _ApplicationBuilder.ApplicationBuilder {
|
|
26
|
+
async createOrSelectStack(args) {
|
|
27
|
+
const PULUMI_SECRETS_PROVIDER = process.env["PULUMI_SECRETS_PROVIDER"]; // Use ";" when on Windows. For Mac and Linux, use ":".
|
|
28
|
+
|
|
29
|
+
const PATH_SEPARATOR = _os.default.platform() === "win32" ? ";" : ":";
|
|
30
|
+
|
|
31
|
+
const relativePath = _path.default.relative(args.projectDir, args.appDir);
|
|
32
|
+
|
|
33
|
+
const pulumiWorkDir = (0, _getPulumiWorkDir.getPulumiWorkDir)(args.projectDir, relativePath);
|
|
34
|
+
|
|
35
|
+
if (!_fs.default.existsSync(pulumiWorkDir)) {
|
|
36
|
+
_fs.default.mkdirSync(pulumiWorkDir, {
|
|
37
|
+
recursive: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const app = await this.config.app({
|
|
42
|
+
env: args.env,
|
|
43
|
+
appDir: args.appDir,
|
|
44
|
+
projectDir: args.projectDir
|
|
45
|
+
});
|
|
46
|
+
const appController = app.createController();
|
|
47
|
+
const workspace = await _automation.LocalWorkspace.create({
|
|
48
|
+
program: () => appController.run(),
|
|
49
|
+
workDir: pulumiWorkDir,
|
|
50
|
+
projectSettings: {
|
|
51
|
+
name: this.config.name,
|
|
52
|
+
runtime: "nodejs",
|
|
53
|
+
description: this.config.description
|
|
54
|
+
},
|
|
55
|
+
secretsProvider: PULUMI_SECRETS_PROVIDER,
|
|
56
|
+
pulumiHome: args.pulumi.pulumiFolder,
|
|
57
|
+
envVars: {
|
|
58
|
+
WEBINY_ENV: args.env,
|
|
59
|
+
WEBINY_PROJECT_NAME: this.config.name,
|
|
60
|
+
// Add Pulumi CLI path to env variable, so the CLI would be properly resolved.
|
|
61
|
+
PATH: args.pulumi.pulumiFolder + PATH_SEPARATOR + (process.env.PATH ?? "")
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const stackName = args.env;
|
|
65
|
+
const stack = await _automation.Stack.createOrSelect(stackName, workspace);
|
|
66
|
+
const options = {
|
|
67
|
+
onOutput: line => console.log((0, _trimNewlines.default)(line)),
|
|
68
|
+
color: "always"
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
app,
|
|
72
|
+
|
|
73
|
+
async refresh() {
|
|
74
|
+
return await stack.refresh(options);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
async preview() {
|
|
78
|
+
return await stack.preview(options);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
async up() {
|
|
82
|
+
const result = await stack.up(options);
|
|
83
|
+
const outputs = {};
|
|
84
|
+
|
|
85
|
+
for (const key of Object.keys(result.outputs)) {
|
|
86
|
+
outputs[key] = result.outputs[key].value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await appController.deployFinished({
|
|
90
|
+
outputs
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.ApplicationBuilderGeneric = ApplicationBuilderGeneric;
|
|
101
|
+
|
|
102
|
+
function createGenericApplication(config) {
|
|
103
|
+
return new ApplicationBuilderGeneric(config);
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ApplicationBuilderGeneric.ts"],"names":["ApplicationBuilderGeneric","ApplicationBuilder","createOrSelectStack","args","PULUMI_SECRETS_PROVIDER","process","env","PATH_SEPARATOR","os","platform","relativePath","path","relative","projectDir","appDir","pulumiWorkDir","fs","existsSync","mkdirSync","recursive","app","config","appController","createController","workspace","LocalWorkspace","create","program","run","workDir","projectSettings","name","runtime","description","secretsProvider","pulumiHome","pulumi","pulumiFolder","envVars","WEBINY_ENV","WEBINY_PROJECT_NAME","PATH","stackName","stack","Stack","createOrSelect","options","onOutput","line","console","log","color","refresh","preview","up","result","outputs","key","Object","keys","value","deployFinished","createGenericApplication"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AAYO,MAAMA,yBAAN,SAAwCC,sCAAxC,CAAqF;AACxD,QAAnBC,mBAAmB,CAACC,IAAD,EAAwD;AACpF,UAAMC,uBAAuB,GAAGC,OAAO,CAACC,GAAR,CAAY,yBAAZ,CAAhC,CADoF,CAGpF;;AACA,UAAMC,cAAc,GAAGC,YAAGC,QAAH,OAAkB,OAAlB,GAA4B,GAA5B,GAAkC,GAAzD;;AAEA,UAAMC,YAAY,GAAGC,cAAKC,QAAL,CAAcT,IAAI,CAACU,UAAnB,EAA+BV,IAAI,CAACW,MAApC,CAArB;;AACA,UAAMC,aAAa,GAAG,wCAAiBZ,IAAI,CAACU,UAAtB,EAAkCH,YAAlC,CAAtB;;AAEA,QAAI,CAACM,YAAGC,UAAH,CAAcF,aAAd,CAAL,EAAmC;AAC/BC,kBAAGE,SAAH,CAAaH,aAAb,EAA4B;AAAEI,QAAAA,SAAS,EAAE;AAAb,OAA5B;AACH;;AAED,UAAMC,GAAG,GAAG,MAAM,KAAKC,MAAL,CAAYD,GAAZ,CAAgB;AAC9Bd,MAAAA,GAAG,EAAEH,IAAI,CAACG,GADoB;AAE9BQ,MAAAA,MAAM,EAAEX,IAAI,CAACW,MAFiB;AAG9BD,MAAAA,UAAU,EAAEV,IAAI,CAACU;AAHa,KAAhB,CAAlB;AAMA,UAAMS,aAAa,GAAGF,GAAG,CAACG,gBAAJ,EAAtB;AAEA,UAAMC,SAAS,GAAG,MAAMC,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GAAW;AACP,cAAMC,MAAM,GAAG,MAAMZ,KAAK,CAACW,EAAN,CAASR,OAAT,CAArB;AAEA,cAAMU,OAA4B,GAAG,EAArC;;AACA,aAAK,MAAMC,GAAX,IAAkBC,MAAM,CAACC,IAAP,CAAYJ,MAAM,CAACC,OAAnB,CAAlB,EAA+C;AAC3CA,UAAAA,OAAO,CAACC,GAAD,CAAP,GAAeF,MAAM,CAACC,OAAP,CAAeC,GAAf,EAAoBG,KAAnC;AACH;;AAED,cAAMtC,aAAa,CAACuC,cAAd,CAA6B;AAAEL,UAAAA;AAAF,SAA7B,CAAN;AACA,eAAOD,MAAP;AACH;;AAlBE,KAAP;AAoBH;;AAtEuF;;;;AAyErF,SAASO,wBAAT,CAAkCzC,MAAlC,EAAoE;AACvE,SAAO,IAAIrB,yBAAJ,CAA8BqB,MAA9B,CAAP;AACH","sourcesContent":["import os from \"os\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport trimNewlines from \"trim-newlines\";\nimport { LocalWorkspace, Stack, UpOptions } from \"@pulumi/pulumi/automation\";\n\nimport { PulumiApp } from \"./PulumiApp\";\nimport { getPulumiWorkDir } from \"./utils/getPulumiWorkDir\";\nimport {\n ApplicationBuilder,\n ApplicationBuilderConfig,\n ApplicationStack,\n ApplicationStackArgs\n} from \"./ApplicationBuilder\";\nimport { ApplicationContext } from \"./ApplicationConfig\";\n\nexport interface ApplicationGenericConfig extends ApplicationBuilderConfig {\n app(ctx: ApplicationContext): Promise<PulumiApp> | PulumiApp;\n}\n\nexport class ApplicationBuilderGeneric extends ApplicationBuilder<ApplicationGenericConfig> {\n public async createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack> {\n const PULUMI_SECRETS_PROVIDER = process.env[\"PULUMI_SECRETS_PROVIDER\"];\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const relativePath = path.relative(args.projectDir, args.appDir);\n const pulumiWorkDir = getPulumiWorkDir(args.projectDir, relativePath);\n\n if (!fs.existsSync(pulumiWorkDir)) {\n fs.mkdirSync(pulumiWorkDir, { recursive: true });\n }\n\n const app = await this.config.app({\n env: args.env,\n appDir: args.appDir,\n projectDir: args.projectDir\n });\n\n const appController = app.createController();\n\n const workspace = await LocalWorkspace.create({\n program: () => appController.run(),\n workDir: pulumiWorkDir,\n projectSettings: {\n name: this.config.name,\n runtime: \"nodejs\",\n description: this.config.description\n },\n secretsProvider: PULUMI_SECRETS_PROVIDER,\n pulumiHome: args.pulumi.pulumiFolder,\n envVars: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n // Add Pulumi CLI path to env variable, so the CLI would be properly resolved.\n PATH: args.pulumi.pulumiFolder + PATH_SEPARATOR + (process.env.PATH ?? \"\")\n }\n });\n\n const stackName = args.env;\n\n const stack = await Stack.createOrSelect(stackName, workspace);\n\n type SharedOptions = Pick<UpOptions, \"onOutput\" | \"color\" | \"onEvent\">;\n const options: SharedOptions = {\n onOutput: line => console.log(trimNewlines(line)),\n color: \"always\"\n };\n\n return {\n app,\n async refresh() {\n return await stack.refresh(options);\n },\n async preview() {\n return await stack.preview(options);\n },\n async up() {\n const result = await stack.up(options);\n\n const outputs: Record<string, any> = {};\n for (const key of Object.keys(result.outputs)) {\n outputs[key] = result.outputs[key].value;\n }\n\n await appController.deployFinished({ outputs });\n return result;\n }\n };\n }\n}\n\nexport function createGenericApplication(config: ApplicationGenericConfig) {\n return new ApplicationBuilderGeneric(config);\n}\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ApplicationBuilderLegacy = void 0;
|
|
7
|
+
|
|
8
|
+
var _ApplicationBuilder = require("./ApplicationBuilder");
|
|
9
|
+
|
|
10
|
+
class ApplicationBuilderLegacy extends _ApplicationBuilder.ApplicationBuilder {
|
|
11
|
+
async createOrSelectStack(args) {
|
|
12
|
+
const PULUMI_SECRETS_PROVIDER = String(process.env["PULUMI_SECRETS_PROVIDER"]);
|
|
13
|
+
const PULUMI_CONFIG_PASSPHRASE = String(process.env["PULUMI_CONFIG_PASSPHRASE"]);
|
|
14
|
+
const DEBUG = args.debug ?? false;
|
|
15
|
+
await args.pulumi.run({
|
|
16
|
+
command: ["stack", "select", args.env],
|
|
17
|
+
args: {
|
|
18
|
+
create: true,
|
|
19
|
+
secretsProvider: PULUMI_SECRETS_PROVIDER
|
|
20
|
+
},
|
|
21
|
+
execa: {
|
|
22
|
+
env: {
|
|
23
|
+
PULUMI_CONFIG_PASSPHRASE
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
refresh: async () => {
|
|
29
|
+
await args.pulumi.run({
|
|
30
|
+
command: "refresh",
|
|
31
|
+
args: {
|
|
32
|
+
debug: DEBUG
|
|
33
|
+
},
|
|
34
|
+
execa: {
|
|
35
|
+
stdio: "inherit",
|
|
36
|
+
env: {
|
|
37
|
+
WEBINY_ENV: args.env,
|
|
38
|
+
WEBINY_PROJECT_NAME: this.config.name,
|
|
39
|
+
PULUMI_CONFIG_PASSPHRASE
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return undefined;
|
|
44
|
+
},
|
|
45
|
+
preview: async () => {
|
|
46
|
+
await args.pulumi.run({
|
|
47
|
+
command: "preview",
|
|
48
|
+
args: {
|
|
49
|
+
debug: DEBUG // Preview command does not accept "--secrets-provider" argument.
|
|
50
|
+
// secretsProvider: PULUMI_SECRETS_PROVIDER
|
|
51
|
+
|
|
52
|
+
},
|
|
53
|
+
execa: {
|
|
54
|
+
stdio: "inherit",
|
|
55
|
+
env: {
|
|
56
|
+
WEBINY_ENV: args.env,
|
|
57
|
+
WEBINY_PROJECT_NAME: this.config.name,
|
|
58
|
+
PULUMI_CONFIG_PASSPHRASE
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return undefined;
|
|
63
|
+
},
|
|
64
|
+
up: async () => {
|
|
65
|
+
await args.pulumi.run({
|
|
66
|
+
command: "up",
|
|
67
|
+
args: {
|
|
68
|
+
yes: true,
|
|
69
|
+
skipPreview: true,
|
|
70
|
+
secretsProvider: PULUMI_SECRETS_PROVIDER,
|
|
71
|
+
debug: DEBUG
|
|
72
|
+
},
|
|
73
|
+
execa: {
|
|
74
|
+
// We pipe "stderr" so that we can intercept potential received error messages,
|
|
75
|
+
// and hopefully, show extra information / help to the user.
|
|
76
|
+
stdio: ["inherit", "inherit", "pipe"],
|
|
77
|
+
env: {
|
|
78
|
+
WEBINY_ENV: args.env,
|
|
79
|
+
WEBINY_PROJECT_NAME: this.config.name,
|
|
80
|
+
PULUMI_CONFIG_PASSPHRASE
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
exports.ApplicationBuilderLegacy = ApplicationBuilderLegacy;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ApplicationBuilderLegacy.ts"],"names":["ApplicationBuilderLegacy","ApplicationBuilder","createOrSelectStack","args","PULUMI_SECRETS_PROVIDER","String","process","env","PULUMI_CONFIG_PASSPHRASE","DEBUG","debug","pulumi","run","command","create","secretsProvider","execa","refresh","stdio","WEBINY_ENV","WEBINY_PROJECT_NAME","config","name","undefined","preview","up","yes","skipPreview"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,wBAAN,SAAuCC,sCAAvC,CAA0D;AAC7B,QAAnBC,mBAAmB,CAACC,IAAD,EAAwD;AACpF,UAAMC,uBAAuB,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAR,CAAY,yBAAZ,CAAD,CAAtC;AACA,UAAMC,wBAAwB,GAAGH,MA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,cAAAA,mBAAmB,EAAE,KAAKC,MAAL,CAAYC,IAFhC;AAGDd,cAAAA;AAHC;AAFF;AAPW,SAAhB,CAAN;AAiBA,eAAOe,SAAP;AACH,OAtCE;AAuCHE,MAAAA,EAAE,EAAE,YAAY;AACZ,cAAMtB,IAAI,CAACQ,MAAL,CAAYC,GAAZ,CAAgB;AAClBC,UAAAA,OAAO,EAAE,IADS;AAElBV,UAAAA,IAAI,EAAE;AACFuB,YAAAA,GAAG,EAAE,IADH;AAEFC,YAAAA,WAAW,EAAE,IAFX;AAGFZ,YAAAA,eAAe,EAAEX,uBAHf;AAIFM,YAAAA,KAAK,EAAED;AAJL,WAFY;AAQlBO,UAAAA,KAAK,EAAE;AACH;AACA;AACAE,YAAAA,KAAK,EAAE,CAAC,SAAD,EAAY,SAAZ,EAAuB,MAAvB,CAHJ;AAIHX,YAAAA,GAAG,EAAE;AACDY,cAAAA,UAAU,EAAEhB,IAAI,CAACI,GADhB;AAEDa,cAAAA,mBAAmB,EAAE,KAAKC,MAAL,CAAYC,IAFhC;AAGDd,cAAAA;AAHC;AAJF;AARW,SAAhB,CAAN;AAoBA,eAAOe,SAAP;AACH;AA7DE,KAAP;AA+DH;;AAlF4D","sourcesContent":["import { ApplicationBuilder, ApplicationStack, ApplicationStackArgs } from \"./ApplicationBuilder\";\n\nexport class ApplicationBuilderLegacy extends ApplicationBuilder {\n public async createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack> {\n const PULUMI_SECRETS_PROVIDER = String(process.env[\"PULUMI_SECRETS_PROVIDER\"]);\n const PULUMI_CONFIG_PASSPHRASE = String(process.env[\"PULUMI_CONFIG_PASSPHRASE\"]);\n const DEBUG = args.debug ?? false;\n\n await args.pulumi.run({\n command: [\"stack\", \"select\", args.env],\n args: {\n create: true,\n secretsProvider: PULUMI_SECRETS_PROVIDER\n },\n execa: {\n env: {\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return {\n refresh: async () => {\n await args.pulumi.run({\n command: \"refresh\",\n args: {\n debug: DEBUG\n },\n execa: {\n stdio: \"inherit\",\n env: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return undefined;\n },\n preview: async () => {\n await args.pulumi.run({\n command: \"preview\",\n args: {\n debug: DEBUG\n // Preview command does not accept \"--secrets-provider\" argument.\n // secretsProvider: PULUMI_SECRETS_PROVIDER\n },\n execa: {\n stdio: \"inherit\",\n env: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return undefined;\n },\n up: async () => {\n await args.pulumi.run({\n command: \"up\",\n args: {\n yes: true,\n skipPreview: true,\n secretsProvider: PULUMI_SECRETS_PROVIDER,\n debug: DEBUG\n },\n execa: {\n // We pipe \"stderr\" so that we can intercept potential received error messages,\n // and hopefully, show extra information / help to the user.\n stdio: [\"inherit\", \"inherit\", \"pipe\"],\n env: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return undefined;\n }\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ApplicationHook } from "./ApplicationHook";
|
|
2
|
+
import { PulumiApp } from "./PulumiApp";
|
|
3
|
+
export interface ApplicationContext {
|
|
4
|
+
env: string;
|
|
5
|
+
appDir: string;
|
|
6
|
+
projectDir: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ApplicationHooks {
|
|
9
|
+
onBeforeBuild: ApplicationHook;
|
|
10
|
+
onAfterBuild: ApplicationHook;
|
|
11
|
+
onBeforeDeploy: ApplicationHook;
|
|
12
|
+
onAfterDeploy: ApplicationHook;
|
|
13
|
+
}
|
|
14
|
+
export interface ApplicationConfig<TApp extends PulumiApp> extends Partial<ApplicationHooks> {
|
|
15
|
+
config?(app: TApp, ctx: ApplicationContext): Promise<void> | void;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ApplicationHook.ts"],"names":["defineAppHook","appHook"],"mappings":";;;;;;;AAAA;AAKO,SAASA,aAAT,CAAuBC,OAAvB,EAAiD;AACpD,SAAOA,OAAP;AACH","sourcesContent":["// TODO add typing to deploy hooks\nexport interface ApplicationHook {\n (params: any, context: any): Promise<void> | void;\n}\n\nexport function defineAppHook(appHook: ApplicationHook) {\n return appHook;\n}\n"]}
|
package/Pulumi.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import execa from "execa";
|
|
2
|
+
declare type Command = string | string[];
|
|
3
|
+
interface PulumiArgs {
|
|
4
|
+
[key: string]: string | boolean;
|
|
5
|
+
}
|
|
6
|
+
interface ExecaArgs {
|
|
7
|
+
env?: {
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
interface Options {
|
|
13
|
+
args?: PulumiArgs;
|
|
14
|
+
execa?: ExecaArgs;
|
|
15
|
+
beforePulumiInstall?: () => any;
|
|
16
|
+
afterPulumiInstall?: () => any;
|
|
17
|
+
pulumiFolder?: string;
|
|
18
|
+
}
|
|
19
|
+
interface RunArgs {
|
|
20
|
+
command: Command;
|
|
21
|
+
args?: PulumiArgs;
|
|
22
|
+
execa?: ExecaArgs;
|
|
23
|
+
beforePulumiInstall?: () => any;
|
|
24
|
+
afterPulumiInstall?: () => any;
|
|
25
|
+
}
|
|
26
|
+
interface InstallArgs {
|
|
27
|
+
beforePulumiInstall?: () => any;
|
|
28
|
+
afterPulumiInstall?: () => any;
|
|
29
|
+
}
|
|
30
|
+
export declare const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
31
|
+
export declare class Pulumi {
|
|
32
|
+
options: Options;
|
|
33
|
+
pulumiFolder: string;
|
|
34
|
+
pulumiDownloadFolder: string;
|
|
35
|
+
pulumiBinaryPath: string;
|
|
36
|
+
constructor(options?: Options);
|
|
37
|
+
run(rawArgs: RunArgs): execa.ExecaChildProcess<string>;
|
|
38
|
+
install(rawArgs?: InstallArgs): Promise<boolean>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
package/Pulumi.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Pulumi = exports.FLAG_NON_INTERACTIVE = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _set2 = _interopRequireDefault(require("lodash/set"));
|
|
13
|
+
|
|
14
|
+
var _kebabCase2 = _interopRequireDefault(require("lodash/kebabCase"));
|
|
15
|
+
|
|
16
|
+
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
17
|
+
|
|
18
|
+
var _os = _interopRequireDefault(require("os"));
|
|
19
|
+
|
|
20
|
+
var _execa = _interopRequireDefault(require("execa"));
|
|
21
|
+
|
|
22
|
+
var path = _interopRequireWildcard(require("path"));
|
|
23
|
+
|
|
24
|
+
var _downloadBinaries = _interopRequireDefault(require("./downloadBinaries"));
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
+
|
|
34
|
+
const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
35
|
+
exports.FLAG_NON_INTERACTIVE = FLAG_NON_INTERACTIVE;
|
|
36
|
+
|
|
37
|
+
class Pulumi {
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
40
|
+
(0, _defineProperty2.default)(this, "pulumiFolder", void 0);
|
|
41
|
+
(0, _defineProperty2.default)(this, "pulumiDownloadFolder", void 0);
|
|
42
|
+
(0, _defineProperty2.default)(this, "pulumiBinaryPath", void 0);
|
|
43
|
+
this.options = options;
|
|
44
|
+
this.pulumiDownloadFolder = path.join(options.pulumiFolder || process.cwd(), "pulumi-cli", _os.default.platform());
|
|
45
|
+
this.pulumiFolder = path.join(this.pulumiDownloadFolder, "pulumi");
|
|
46
|
+
this.pulumiBinaryPath = path.join(this.pulumiFolder, "pulumi");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
run(rawArgs) {
|
|
50
|
+
const args = (0, _merge2.default)({}, this.options, rawArgs);
|
|
51
|
+
|
|
52
|
+
if (!Array.isArray(args.command)) {
|
|
53
|
+
args.command = [args.command];
|
|
54
|
+
} // 1. Prepare Pulumi args.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const finalArgs = [];
|
|
58
|
+
|
|
59
|
+
for (const key in args.args) {
|
|
60
|
+
const value = args.args[key];
|
|
61
|
+
|
|
62
|
+
if (!value) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
for (let i = 0; i < value.length; i++) {
|
|
68
|
+
finalArgs.push(`--${(0, _kebabCase2.default)(key)}`, value[i]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof value === "boolean") {
|
|
75
|
+
finalArgs.push(`--${(0, _kebabCase2.default)(key)}`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
finalArgs.push(`--${(0, _kebabCase2.default)(key)}`, value);
|
|
80
|
+
} // Prepare execa args.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if (!args.execa) {
|
|
84
|
+
args.execa = {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
(0, _set2.default)(args.execa, "env.PULUMI_SKIP_UPDATE_CHECK", "true");
|
|
88
|
+
(0, _set2.default)(args.execa, "env.PULUMI_HOME", this.pulumiFolder); // Use ";" when on Windows. For Mac and Linux, use ":".
|
|
89
|
+
|
|
90
|
+
const PATH_SEPARATOR = _os.default.platform() === "win32" ? ";" : ":";
|
|
91
|
+
|
|
92
|
+
const execaArgs = _objectSpread(_objectSpread({}, args.execa), {}, {
|
|
93
|
+
env: _objectSpread(_objectSpread({}, args.execa.env || {}), {}, {
|
|
94
|
+
/**
|
|
95
|
+
* Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this
|
|
96
|
+
* commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,
|
|
97
|
+
* we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve
|
|
98
|
+
* plugins necessary for custom resources and dynamic providers to work.
|
|
99
|
+
*/
|
|
100
|
+
PATH: process.env.PATH + PATH_SEPARATOR + this.pulumiFolder
|
|
101
|
+
})
|
|
102
|
+
}); // We want to keep the "interactive" output format of the Pulumi command when `--preview` flag is passed in.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
const flags = args.command && args.command.includes("preview") ? [] : [FLAG_NON_INTERACTIVE];
|
|
106
|
+
return (0, _execa.default)(this.pulumiBinaryPath, [...args.command, ...finalArgs, ...flags], execaArgs);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async install(rawArgs) {
|
|
110
|
+
const args = (0, _merge2.default)({}, this.options, rawArgs);
|
|
111
|
+
const installed = await (0, _downloadBinaries.default)(this.pulumiDownloadFolder, args.beforePulumiInstall, args.afterPulumiInstall);
|
|
112
|
+
|
|
113
|
+
if (installed) {
|
|
114
|
+
const {
|
|
115
|
+
version
|
|
116
|
+
} = require("@pulumi/aws/package.json");
|
|
117
|
+
|
|
118
|
+
await (0, _execa.default)(this.pulumiBinaryPath, ["plugin", "install", "resource", "aws", version], {
|
|
119
|
+
stdio: "inherit",
|
|
120
|
+
env: {
|
|
121
|
+
PULUMI_HOME: this.pulumiFolder,
|
|
122
|
+
PULUMI_SKIP_UPDATE_CHECK: "true"
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return installed;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
exports.Pulumi = Pulumi;
|
package/Pulumi.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Pulumi.ts"],"names":["FLAG_NON_INTERACTIVE","Pulumi","constructor","options","pulumiDownloadFolder","path","join","pulumiFolder","process","cwd","os","platform","pulumiBinaryPath","run","rawArgs","args","Array","isArray","command","finalArgs","key","value","i","length","push","execa","PATH_SEPARATOR","execaArgs","env","PATH","flags","includes","install","installed","beforePulumiInstall","afterPulumiInstall","version","require","stdio","PULUMI_HOME","PULUMI_SKIP_UPDATE_CHECK"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;AAsCO,MAAMA,oBAAoB,GAAG,mBAA7B;;;AAEA,MAAMC,MAAN,CAAa;AAKhBC,EAAAA,WAAW,CAACC,OAAgB,GAAG,EAApB,EAAwB;AAAA;AAAA;AAAA;AAAA;AAC/B,SAAKA,OAAL,GAAeA,OAAf;AAEA,SAAKC,oBAAL,GAA4BC,IAAI,CAACC,IAAL,CACxBH,OAAO,CAACI,YAAR,IAAwBC,OAAO,CAACC,GAAR,EADA,EAExB,YAFwB,EAGxBC,YAAGC,QAAH,EAHwB,CAA5B;AAMA,SAAKJ,YAAL,GAAoBF,IAAI,CAACC,IAAL,CAAU,KAAKF,oBAAf,EAAqC,QAArC,CAApB;AACA,SAAKQ,gBAAL,GAAwBP,IAAI,CAACC,IAAL,CAAU,KAAKC,YAAf,EAA6B,QAA7B,CAAxB;AACH;;AAEDM,EAAAA,GAAG,CAACC,OAAD,EAAmB;AAClB,UAAMC,IAAI,GAAG,qBAAM,EAAN,EAAU,KAAKZ,OAAf,EAAwBW,OAAxB,CAAb;;AAEA,QAAI,CAACE,KAAK,CAACC,OAAN,CAAcF,IAAI,CAACG,OAAnB,CAAL,EAAkC;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AAL,CAAWG,GAAX,IAAkB,EADvB;AAEC;AAChB;AACA;AACA;AACA;AACA;AACgBC,QAAAA,IAAI,EAAErB,OAAO,CAACoB,GAAR,CAAYC,IAAZ,GAAmBH,cAAnB,GAAoC,KAAKnB;AARhD;AAFQ,MAAf,CAzCkB,CAuDlB;;;AACA,UAAMuB,KAAK,GACPf,IAAI,CAACG,OAAL,IAAgBH,IAAI,CAACG,OAAL,CAAaa,QAAb,CAAsB,SAAtB,CAAhB,GAAmD,EAAnD,GAAwD,CAAC/B,oBAAD,CAD5D;AAGA,WAAO,oBAAM,KAAKY,gBAAX,EAA6B,CAAC,GAAGG,IAAI,CAACG,OAAT,EAAkB,GAAGC,SAArB,EAAgC,GAAGW,KAAnC,CAA7B,EAAwEH,SAAxE,CAAP;AACH;;AAEY,QAAPK,OAAO,CAAClB,OAAD,EAA0C;AACnD,UAAMC,IAAI,GAAG,qBAAM,EAAN,EAAU,KAAKZ,OAAf,EAAwBW,OAAxB,CAAb;AAEA,UAAMmB,SAAS,GAAG,MAAM,+BACpB,KAAK7B,oBADe,EAEpBW,IAAI,CAACmB,mBAFe,EAGpBnB,IAAI,CAACoB,kBAHe,CAAxB;;AAMA,QAAIF,SAAJ,EAAe;AACX,YAAM;AAAEG,QAAAA;AAAF,UAAcC,OAAO,CAAC,0BAAD,CAA3B;;AACA,YAAM,oBAAM,KAAKzB,gBAAX,EAA6B,CAAC,QAAD,EAAW,SAAX,EAAsB,UAAtB,EAAkC,KAAlC,EAAyCwB,OAAzC,CAA7B,EAAgF;AAClFE,QAAAA,KAAK,EAAE,SAD2E;AAElFV,QAAAA,GAAG,EAAE;AACDW,UAAAA,WAAW,EAAE,KAAKhC,YADjB;AAEDiC,UAAAA,wBAAwB,EAAE;AAFzB;AAF6E,OAAhF,CAAN;AAOH;;AAED,WAAOP,SAAP;AACH;;AArGe","sourcesContent":["import os from \"os\";\nimport execa from \"execa\";\nimport * as path from \"path\";\nimport { merge, kebabCase, set } from \"lodash\";\nimport downloadBinaries from \"./downloadBinaries\";\n\ntype Command = string | string[];\ninterface PulumiArgs {\n [key: string]: string | boolean;\n}\ninterface ExecaArgs {\n env?: {\n [key: string]: string | undefined;\n };\n [key: string]: any;\n}\n\ninterface Options {\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n\n // A folder into which the Pulumi CLI, along with all of its meta data and config files, will be set up.\n // It's recommended this folder is not checked in into a code repository, since the Pulumi CLI can store\n // sensitive information here, for example - user's Pulumi Service credentials.\n pulumiFolder?: string;\n}\n\ninterface RunArgs {\n command: Command;\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\ninterface InstallArgs {\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport const FLAG_NON_INTERACTIVE = \"--non-interactive\";\n\nexport class Pulumi {\n options: Options;\n pulumiFolder: string;\n pulumiDownloadFolder: string;\n pulumiBinaryPath: string;\n constructor(options: Options = {}) {\n this.options = options;\n\n this.pulumiDownloadFolder = path.join(\n options.pulumiFolder || process.cwd(),\n \"pulumi-cli\",\n os.platform()\n );\n\n this.pulumiFolder = path.join(this.pulumiDownloadFolder, \"pulumi\");\n this.pulumiBinaryPath = path.join(this.pulumiFolder, \"pulumi\");\n }\n\n run(rawArgs: RunArgs) {\n const args = merge({}, this.options, rawArgs);\n\n if (!Array.isArray(args.command)) {\n args.command = [args.command];\n }\n\n // 1. Prepare Pulumi args.\n const finalArgs = [];\n for (const key in args.args) {\n const value = args.args[key];\n if (!value) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n finalArgs.push(`--${kebabCase(key)}`, value[i]);\n }\n continue;\n }\n\n if (typeof value === \"boolean\") {\n finalArgs.push(`--${kebabCase(key)}`);\n continue;\n }\n\n finalArgs.push(`--${kebabCase(key)}`, value);\n }\n\n // Prepare execa args.\n if (!args.execa) {\n args.execa = {};\n }\n\n set(args.execa, \"env.PULUMI_SKIP_UPDATE_CHECK\", \"true\");\n set(args.execa, \"env.PULUMI_HOME\", this.pulumiFolder);\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const execaArgs = {\n ...args.execa,\n env: {\n ...(args.execa.env || {}),\n /**\n * Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this\n * commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,\n * we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve\n * plugins necessary for custom resources and dynamic providers to work.\n */\n PATH: process.env.PATH + PATH_SEPARATOR + this.pulumiFolder\n }\n };\n\n // We want to keep the \"interactive\" output format of the Pulumi command when `--preview` flag is passed in.\n const flags =\n args.command && args.command.includes(\"preview\") ? [] : [FLAG_NON_INTERACTIVE];\n\n return execa(this.pulumiBinaryPath, [...args.command, ...finalArgs, ...flags], execaArgs);\n }\n\n async install(rawArgs?: InstallArgs): Promise<boolean> {\n const args = merge({}, this.options, rawArgs);\n\n const installed = await downloadBinaries(\n this.pulumiDownloadFolder,\n args.beforePulumiInstall,\n args.afterPulumiInstall\n );\n\n if (installed) {\n const { version } = require(\"@pulumi/aws/package.json\");\n await execa(this.pulumiBinaryPath, [\"plugin\", \"install\", \"resource\", \"aws\", version], {\n stdio: \"inherit\",\n env: {\n PULUMI_HOME: this.pulumiFolder,\n PULUMI_SKIP_UPDATE_CHECK: \"true\"\n }\n });\n }\n\n return installed;\n }\n}\n"]}
|
package/PulumiApp.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
import { ApplicationContext } from "./ApplicationConfig";
|
|
3
|
+
import { PulumiAppModuleDefinition } from "./PulumiAppModule";
|
|
4
|
+
import { ResourceArgs, ResourceConstructor, ResourceType } from "./PulumiResource";
|
|
5
|
+
export interface CreateResourceParams<TCtor extends ResourceConstructor> {
|
|
6
|
+
name: string;
|
|
7
|
+
config: ResourceArgs<TCtor>;
|
|
8
|
+
opts?: pulumi.CustomResourceOptions;
|
|
9
|
+
}
|
|
10
|
+
export interface PulumiAppResource<T extends ResourceConstructor> {
|
|
11
|
+
name: string;
|
|
12
|
+
readonly config: ResourceConfigProxy<ResourceArgs<T>>;
|
|
13
|
+
readonly opts: pulumi.CustomResourceOptions;
|
|
14
|
+
readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;
|
|
15
|
+
}
|
|
16
|
+
export interface PulumiAppParams {
|
|
17
|
+
name: string;
|
|
18
|
+
ctx: ApplicationContext;
|
|
19
|
+
}
|
|
20
|
+
export interface ResourceHandler {
|
|
21
|
+
(resource: PulumiAppResource<ResourceConstructor>): void;
|
|
22
|
+
}
|
|
23
|
+
export declare type ResourceConfigProxy<T extends object> = {
|
|
24
|
+
readonly [K in keyof T]-?: ResourceConfigSetter<T[K]>;
|
|
25
|
+
};
|
|
26
|
+
export interface ResourceConfigSetter<T> {
|
|
27
|
+
(value: T): void;
|
|
28
|
+
(fcn: ResourceConfigModifier<T>): void;
|
|
29
|
+
}
|
|
30
|
+
export interface ResourceConfigModifier<T> {
|
|
31
|
+
(value: pulumi.Unwrap<T>): T | void;
|
|
32
|
+
}
|
|
33
|
+
interface DeployEventParams {
|
|
34
|
+
outputs: Record<string, any>;
|
|
35
|
+
}
|
|
36
|
+
interface DeployEventHandler {
|
|
37
|
+
(params: DeployEventParams): Promise<void> | void;
|
|
38
|
+
}
|
|
39
|
+
export declare abstract class PulumiApp<TConfig = unknown> {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly ctx: ApplicationContext;
|
|
42
|
+
private readonly resourceHandlers;
|
|
43
|
+
private readonly afterDeployHandlers;
|
|
44
|
+
private readonly handlers;
|
|
45
|
+
private readonly outputs;
|
|
46
|
+
private readonly modules;
|
|
47
|
+
constructor(params: PulumiAppParams);
|
|
48
|
+
abstract setup(config: TConfig): Promise<void> | void;
|
|
49
|
+
onResource(handler: ResourceHandler): void;
|
|
50
|
+
onAfterDeploy(handler: DeployEventHandler): void;
|
|
51
|
+
addResource<T extends ResourceConstructor>(ctor: T, params: CreateResourceParams<T>): PulumiAppResource<T>;
|
|
52
|
+
addOutput<T>(name: string, output: T): void;
|
|
53
|
+
addOutputs(outputs: Record<string, unknown>): void;
|
|
54
|
+
addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;
|
|
55
|
+
addModule<TModule, TConfig>(def: PulumiAppModuleDefinition<TModule, TConfig>, config: TConfig): TModule;
|
|
56
|
+
addHandler<T>(handler: () => Promise<T> | T): pulumi.Output<pulumi.Unwrap<T>>;
|
|
57
|
+
getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;
|
|
58
|
+
getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
|
|
59
|
+
optional: false;
|
|
60
|
+
}): TModule;
|
|
61
|
+
getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
|
|
62
|
+
optional: true;
|
|
63
|
+
}): TModule | null;
|
|
64
|
+
createController(): {
|
|
65
|
+
run: () => Promise<Record<string, any>>;
|
|
66
|
+
deployFinished: (params: DeployEventParams) => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
private runProgram;
|
|
69
|
+
private deployFinished;
|
|
70
|
+
}
|
|
71
|
+
export interface CreateAppParams<TOutput extends Record<string, unknown>, TConfig = void> {
|
|
72
|
+
name: string;
|
|
73
|
+
config(app: PulumiApp, config: TConfig): TOutput | Promise<TOutput>;
|
|
74
|
+
}
|
|
75
|
+
export declare function defineApp<TOutput extends Record<string, unknown>, TConfig = void>(params: CreateAppParams<TOutput, TConfig>): new (ctx: ApplicationContext) => PulumiApp<TConfig> & TOutput;
|
|
76
|
+
export {};
|