hereya-cli 0.19.0 → 0.21.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/README.md +52 -30
- package/dist/commands/add/index.js +18 -5
- package/dist/commands/deploy/index.js +31 -10
- package/dist/commands/down/index.js +15 -6
- package/dist/commands/remove/index.js +14 -5
- package/dist/commands/run/index.js +2 -2
- package/dist/commands/undeploy/index.js +20 -7
- package/dist/commands/up/index.js +20 -7
- package/dist/commands/workspace/install/index.js +8 -3
- package/dist/commands/workspace/uninstall/index.js +8 -3
- package/dist/executor/interface.d.ts +2 -0
- package/dist/executor/local.js +2 -0
- package/dist/iac/cdk.js +12 -8
- package/dist/iac/common.d.ts +2 -0
- package/dist/iac/terraform.d.ts +2 -1
- package/dist/iac/terraform.js +25 -14
- package/dist/infrastructure/aws.js +3 -1
- package/dist/infrastructure/common.d.ts +2 -0
- package/dist/infrastructure/index.d.ts +2 -0
- package/dist/infrastructure/index.js +4 -0
- package/dist/infrastructure/local.js +2 -0
- package/dist/lib/log.d.ts +12 -3
- package/dist/lib/log.js +21 -12
- package/dist/lib/shell.d.ts +14 -7
- package/dist/lib/shell.js +74 -21
- package/oclif.manifest.json +10 -10
- package/package.json +1 -1
|
@@ -5,14 +5,19 @@ import { getBackend } from '../../backend/index.js';
|
|
|
5
5
|
import { getExecutor } from '../../executor/index.js';
|
|
6
6
|
import { getConfigManager } from '../../lib/config/index.js';
|
|
7
7
|
import { getEnvManager } from '../../lib/env/index.js';
|
|
8
|
+
import { getLogger, isDebug, setDebug } from '../../lib/log.js';
|
|
8
9
|
import { getParameterManager } from '../../lib/parameter/index.js';
|
|
9
|
-
import { delay
|
|
10
|
+
import { delay } from '../../lib/shell.js';
|
|
10
11
|
export default class Undeploy extends Command {
|
|
11
12
|
static description = 'Undeploy a hereya project by removing all resources.';
|
|
12
13
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
13
14
|
static flags = {
|
|
14
15
|
chdir: Flags.string({
|
|
15
|
-
description:
|
|
16
|
+
description: `
|
|
17
|
+
Directory where the command will be executed.
|
|
18
|
+
If not specified, it defaults to the current working directory.
|
|
19
|
+
Alternatively, you can define the project root by setting the HEREYA_PROJECT_ROOT_DIR environment variable.
|
|
20
|
+
`,
|
|
16
21
|
required: false,
|
|
17
22
|
}),
|
|
18
23
|
debug: Flags.boolean({
|
|
@@ -96,7 +101,10 @@ export default class Undeploy extends Command {
|
|
|
96
101
|
skip: (ctx) => ctx.deployPackages.length === 0,
|
|
97
102
|
async task(ctx, task) {
|
|
98
103
|
return task.newListr(ctx.deployPackages.map((packageName) => ({
|
|
99
|
-
|
|
104
|
+
rendererOptions: {
|
|
105
|
+
persistentOutput: isDebug(),
|
|
106
|
+
},
|
|
107
|
+
async task(_, task) {
|
|
100
108
|
const parameterManager = getParameterManager();
|
|
101
109
|
const { parameters } = await parameterManager.getPackageParameters({
|
|
102
110
|
package: packageName,
|
|
@@ -110,6 +118,7 @@ export default class Undeploy extends Command {
|
|
|
110
118
|
const { executor } = executor$;
|
|
111
119
|
const destroyOutput = await executor.destroy({
|
|
112
120
|
isDeploying: true,
|
|
121
|
+
logger: getLogger(task),
|
|
113
122
|
package: packageName,
|
|
114
123
|
parameters,
|
|
115
124
|
project: ctx.configOutput.config.project,
|
|
@@ -122,7 +131,7 @@ export default class Undeploy extends Command {
|
|
|
122
131
|
}
|
|
123
132
|
},
|
|
124
133
|
title: `Destroying package ${packageName}`,
|
|
125
|
-
})), { concurrent: false });
|
|
134
|
+
})), { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
126
135
|
},
|
|
127
136
|
title: 'Destroying deployment packages',
|
|
128
137
|
},
|
|
@@ -130,7 +139,10 @@ export default class Undeploy extends Command {
|
|
|
130
139
|
skip: (ctx) => !ctx.packages || ctx.packages.length === 0,
|
|
131
140
|
async task(ctx, task) {
|
|
132
141
|
return task.newListr(ctx.packages.map((packageName) => ({
|
|
133
|
-
|
|
142
|
+
rendererOptions: {
|
|
143
|
+
persistentOutput: isDebug(),
|
|
144
|
+
},
|
|
145
|
+
async task(_, task) {
|
|
134
146
|
const parameterManager = getParameterManager();
|
|
135
147
|
const { parameters } = await parameterManager.getPackageParameters({
|
|
136
148
|
package: packageName,
|
|
@@ -144,6 +156,7 @@ export default class Undeploy extends Command {
|
|
|
144
156
|
const { executor } = executor$;
|
|
145
157
|
const destroyOutput = await executor.destroy({
|
|
146
158
|
isDeploying: true,
|
|
159
|
+
logger: getLogger(task),
|
|
147
160
|
package: packageName,
|
|
148
161
|
parameters,
|
|
149
162
|
project: ctx.configOutput.config.project,
|
|
@@ -159,7 +172,7 @@ export default class Undeploy extends Command {
|
|
|
159
172
|
ctx.destroyed = output;
|
|
160
173
|
},
|
|
161
174
|
title: `Destroying ${packageName}`,
|
|
162
|
-
})), { concurrent: true });
|
|
175
|
+
})), { concurrent: true, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
163
176
|
},
|
|
164
177
|
title: `Destroying packages`,
|
|
165
178
|
},
|
|
@@ -194,7 +207,7 @@ export default class Undeploy extends Command {
|
|
|
194
207
|
},
|
|
195
208
|
title: 'Saving state',
|
|
196
209
|
},
|
|
197
|
-
], { concurrent: false });
|
|
210
|
+
], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
198
211
|
},
|
|
199
212
|
},
|
|
200
213
|
]);
|
|
@@ -4,14 +4,19 @@ import { getBackend } from '../../backend/index.js';
|
|
|
4
4
|
import { getExecutor } from '../../executor/index.js';
|
|
5
5
|
import { getConfigManager } from '../../lib/config/index.js';
|
|
6
6
|
import { getEnvManager } from '../../lib/env/index.js';
|
|
7
|
+
import { getLogger, isDebug, setDebug } from '../../lib/log.js';
|
|
7
8
|
import { getParameterManager } from '../../lib/parameter/index.js';
|
|
8
|
-
import { delay
|
|
9
|
+
import { delay } from '../../lib/shell.js';
|
|
9
10
|
export default class Up extends Command {
|
|
10
11
|
static description = 'Provision all packages in the project.';
|
|
11
12
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
12
13
|
static flags = {
|
|
13
14
|
chdir: Flags.string({
|
|
14
|
-
description:
|
|
15
|
+
description: `
|
|
16
|
+
Directory where the command will be executed.
|
|
17
|
+
If not specified, it defaults to the current working directory.
|
|
18
|
+
Alternatively, you can define the project root by setting the HEREYA_PROJECT_ROOT_DIR environment variable.
|
|
19
|
+
`,
|
|
15
20
|
required: false,
|
|
16
21
|
}),
|
|
17
22
|
debug: Flags.boolean({
|
|
@@ -83,7 +88,10 @@ export default class Up extends Command {
|
|
|
83
88
|
return;
|
|
84
89
|
}
|
|
85
90
|
return task.newListr(removedPackages.map((packageName) => ({
|
|
86
|
-
|
|
91
|
+
rendererOptions: {
|
|
92
|
+
persistentOutput: isDebug(),
|
|
93
|
+
},
|
|
94
|
+
async task(_, task) {
|
|
87
95
|
const parameterManager = getParameterManager();
|
|
88
96
|
const { parameters } = await parameterManager.getPackageParameters({
|
|
89
97
|
package: packageName,
|
|
@@ -97,6 +105,7 @@ export default class Up extends Command {
|
|
|
97
105
|
const { executor } = executor$;
|
|
98
106
|
const destroyOutput = await executor.destroy({
|
|
99
107
|
isDeploying: flags.deploy,
|
|
108
|
+
logger: getLogger(task),
|
|
100
109
|
package: packageName,
|
|
101
110
|
parameters,
|
|
102
111
|
project: configOutput.config.project,
|
|
@@ -112,7 +121,7 @@ export default class Up extends Command {
|
|
|
112
121
|
ctx.removed = output;
|
|
113
122
|
},
|
|
114
123
|
title: `Destroying ${packageName}`,
|
|
115
|
-
})), { concurrent: true });
|
|
124
|
+
})), { concurrent: true, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
116
125
|
},
|
|
117
126
|
title: `Destroying removed packages`,
|
|
118
127
|
},
|
|
@@ -123,7 +132,10 @@ export default class Up extends Command {
|
|
|
123
132
|
return;
|
|
124
133
|
}
|
|
125
134
|
return task.newListr(ctx.packages.map((packageName) => ({
|
|
126
|
-
|
|
135
|
+
rendererOptions: {
|
|
136
|
+
persistentOutput: isDebug(),
|
|
137
|
+
},
|
|
138
|
+
async task(_, task) {
|
|
127
139
|
const parameterManager = getParameterManager();
|
|
128
140
|
const { parameters } = await parameterManager.getPackageParameters({
|
|
129
141
|
package: packageName,
|
|
@@ -137,6 +149,7 @@ export default class Up extends Command {
|
|
|
137
149
|
const { executor } = executor$;
|
|
138
150
|
const provisionOutput = await executor.provision({
|
|
139
151
|
isDeploying: flags.deploy,
|
|
152
|
+
logger: getLogger(task),
|
|
140
153
|
package: packageName,
|
|
141
154
|
parameters,
|
|
142
155
|
project: ctx.configOutput.config.project,
|
|
@@ -152,7 +165,7 @@ export default class Up extends Command {
|
|
|
152
165
|
ctx.added = output;
|
|
153
166
|
},
|
|
154
167
|
title: `Provisioning ${packageName}`,
|
|
155
|
-
})), { concurrent: true });
|
|
168
|
+
})), { concurrent: true, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
156
169
|
},
|
|
157
170
|
title: `Provisioning packages`,
|
|
158
171
|
},
|
|
@@ -207,7 +220,7 @@ export default class Up extends Command {
|
|
|
207
220
|
},
|
|
208
221
|
title: 'Saving state',
|
|
209
222
|
},
|
|
210
|
-
], { concurrent: false });
|
|
223
|
+
], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
211
224
|
},
|
|
212
225
|
title: 'Waking up the project',
|
|
213
226
|
},
|
|
@@ -2,8 +2,9 @@ import { Args, Command, Flags } from '@oclif/core';
|
|
|
2
2
|
import { Listr, ListrLogger, ListrLogLevels } from 'listr2';
|
|
3
3
|
import { getBackend } from '../../../backend/index.js';
|
|
4
4
|
import { getExecutor } from '../../../executor/index.js';
|
|
5
|
+
import { getLogger, isDebug, setDebug } from '../../../lib/log.js';
|
|
5
6
|
import { arrayOfStringToObject } from '../../../lib/object-utils.js';
|
|
6
|
-
import { delay
|
|
7
|
+
import { delay } from '../../../lib/shell.js';
|
|
7
8
|
import { load } from '../../../lib/yaml-utils.js';
|
|
8
9
|
export default class WorkspaceInstall extends Command {
|
|
9
10
|
static args = {
|
|
@@ -73,13 +74,17 @@ export default class WorkspaceInstall extends Command {
|
|
|
73
74
|
title: 'Resolving parameters',
|
|
74
75
|
},
|
|
75
76
|
{
|
|
76
|
-
|
|
77
|
+
rendererOptions: {
|
|
78
|
+
persistentOutput: isDebug(),
|
|
79
|
+
},
|
|
80
|
+
async task(ctx, task) {
|
|
77
81
|
const executor$ = getExecutor();
|
|
78
82
|
if (!executor$.success) {
|
|
79
83
|
throw new Error(executor$.reason);
|
|
80
84
|
}
|
|
81
85
|
const { executor } = executor$;
|
|
82
86
|
const provisionOutput = await executor.provision({
|
|
87
|
+
logger: getLogger(task),
|
|
83
88
|
package: args.package,
|
|
84
89
|
parameters: ctx.parameters,
|
|
85
90
|
workspace: flags.workspace,
|
|
@@ -112,7 +117,7 @@ export default class WorkspaceInstall extends Command {
|
|
|
112
117
|
},
|
|
113
118
|
title: `Installing ${args.package} into workspace ${flags.workspace}`,
|
|
114
119
|
},
|
|
115
|
-
], { concurrent: false });
|
|
120
|
+
], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
116
121
|
try {
|
|
117
122
|
await task.run();
|
|
118
123
|
myLogger.log(ListrLogLevels.COMPLETED, `Package ${args.package} installed successfully into workspace ${flags.workspace}`);
|
|
@@ -2,8 +2,9 @@ import { Args, Command, Flags } from '@oclif/core';
|
|
|
2
2
|
import { Listr, ListrLogger, ListrLogLevels } from 'listr2';
|
|
3
3
|
import { getBackend } from '../../../backend/index.js';
|
|
4
4
|
import { getExecutor } from '../../../executor/index.js';
|
|
5
|
+
import { getLogger, isDebug, setDebug } from '../../../lib/log.js';
|
|
5
6
|
import { arrayOfStringToObject } from '../../../lib/object-utils.js';
|
|
6
|
-
import { delay
|
|
7
|
+
import { delay } from '../../../lib/shell.js';
|
|
7
8
|
import { load } from '../../../lib/yaml-utils.js';
|
|
8
9
|
export default class WorkspaceUninstall extends Command {
|
|
9
10
|
static args = {
|
|
@@ -80,13 +81,17 @@ export default class WorkspaceUninstall extends Command {
|
|
|
80
81
|
title: 'Resolving parameters',
|
|
81
82
|
},
|
|
82
83
|
{
|
|
83
|
-
|
|
84
|
+
rendererOptions: {
|
|
85
|
+
persistentOutput: isDebug(),
|
|
86
|
+
},
|
|
87
|
+
async task(ctx, task) {
|
|
84
88
|
const executor$ = getExecutor();
|
|
85
89
|
if (!executor$.success) {
|
|
86
90
|
throw new Error(executor$.reason);
|
|
87
91
|
}
|
|
88
92
|
const { executor } = executor$;
|
|
89
93
|
const destroyOutput = await executor.destroy({
|
|
94
|
+
logger: getLogger(task),
|
|
90
95
|
package: args.package,
|
|
91
96
|
parameters: ctx.parameters,
|
|
92
97
|
workspace: flags.workspace,
|
|
@@ -118,7 +123,7 @@ export default class WorkspaceUninstall extends Command {
|
|
|
118
123
|
},
|
|
119
124
|
title: `Uninstalling package ${args.package} from workspace ${flags.workspace}`,
|
|
120
125
|
},
|
|
121
|
-
]);
|
|
126
|
+
], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
|
|
122
127
|
try {
|
|
123
128
|
await task.run();
|
|
124
129
|
myLogger.log(ListrLogLevels.COMPLETED, `Package ${args.package} uninstalled successfully from workspace ${flags.workspace}`);
|
package/dist/executor/local.js
CHANGED
|
@@ -12,6 +12,7 @@ export class LocalExecutor {
|
|
|
12
12
|
return destroyPackage({
|
|
13
13
|
...input,
|
|
14
14
|
env: getWorkspaceEnvOutput.env,
|
|
15
|
+
logger: input.logger,
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
async provision(input) {
|
|
@@ -25,6 +26,7 @@ export class LocalExecutor {
|
|
|
25
26
|
return provisionPackage({
|
|
26
27
|
...input,
|
|
27
28
|
env: getWorkspaceEnvOutput.env,
|
|
29
|
+
logger: input.logger,
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
async resolveEnvValues(input) {
|
package/dist/iac/cdk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CloudFormationClient, DescribeStacksCommand } from '@aws-sdk/client-cloudformation';
|
|
2
|
-
import {
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { runShell } from '../lib/shell.js';
|
|
5
5
|
import { load } from '../lib/yaml-utils.js';
|
|
@@ -7,7 +7,7 @@ export class Cdk {
|
|
|
7
7
|
async apply(input) {
|
|
8
8
|
try {
|
|
9
9
|
const { remainingEnv, serializedParameters, serializedWorkspaceEnv } = await this.serializedParametersAndContext(input);
|
|
10
|
-
runShell('npx', [
|
|
10
|
+
await runShell('npx', [
|
|
11
11
|
'aws-cdk', 'deploy', '--require-approval', 'never', ...serializedWorkspaceEnv, ...serializedParameters,
|
|
12
12
|
], {
|
|
13
13
|
directory: input.pkgPath,
|
|
@@ -15,6 +15,7 @@ export class Cdk {
|
|
|
15
15
|
...remainingEnv,
|
|
16
16
|
STACK_NAME: input.id
|
|
17
17
|
},
|
|
18
|
+
logger: input.logger,
|
|
18
19
|
});
|
|
19
20
|
const env = await this.getEnv(input.id);
|
|
20
21
|
return { env, success: true };
|
|
@@ -27,14 +28,15 @@ export class Cdk {
|
|
|
27
28
|
try {
|
|
28
29
|
const env = await this.getEnv(input.id);
|
|
29
30
|
const { remainingEnv, serializedParameters, serializedWorkspaceEnv } = await this.serializedParametersAndContext(input);
|
|
30
|
-
runShell('npx', [
|
|
31
|
+
await runShell('npx', [
|
|
31
32
|
'aws-cdk', 'destroy', '--force', ...serializedWorkspaceEnv, ...serializedParameters
|
|
32
33
|
], {
|
|
33
34
|
directory: input.pkgPath,
|
|
34
35
|
env: {
|
|
35
36
|
...remainingEnv,
|
|
36
37
|
STACK_NAME: input.id
|
|
37
|
-
}
|
|
38
|
+
},
|
|
39
|
+
logger: input.logger,
|
|
38
40
|
});
|
|
39
41
|
return { env, success: true };
|
|
40
42
|
}
|
|
@@ -52,22 +54,24 @@ export class Cdk {
|
|
|
52
54
|
}
|
|
53
55
|
async getParameterNames(input) {
|
|
54
56
|
const workDir = input.pkgPath;
|
|
55
|
-
runShell('npm', ['install'], { directory: workDir });
|
|
56
|
-
runShell('npx', [
|
|
57
|
+
await runShell('npm', ['install'], { directory: workDir });
|
|
58
|
+
await runShell('npx', [
|
|
57
59
|
'aws-cdk', 'synth',
|
|
58
60
|
], {
|
|
59
61
|
directory: workDir,
|
|
60
62
|
env: { ...input.env, ...input.parameters },
|
|
63
|
+
logger: input.logger,
|
|
61
64
|
});
|
|
62
|
-
const result = runShell('npx', [
|
|
65
|
+
const result = await runShell('npx', [
|
|
63
66
|
'aws-cdk', 'synth',
|
|
64
67
|
], {
|
|
65
68
|
directory: workDir,
|
|
66
69
|
env: { ...input.env, ...input.parameters },
|
|
70
|
+
logger: input.logger,
|
|
67
71
|
stdio: 'pipe',
|
|
68
72
|
});
|
|
69
73
|
const stackYamlPath = path.join(workDir, '.stack.yaml');
|
|
70
|
-
|
|
74
|
+
await writeFile(stackYamlPath, result.stdout, { encoding: 'utf8' });
|
|
71
75
|
const { data: synthedStack } = await load(stackYamlPath);
|
|
72
76
|
return Object.keys(synthedStack.Parameters);
|
|
73
77
|
}
|
package/dist/iac/common.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Logger } from '../lib/log.js';
|
|
1
2
|
export interface Iac {
|
|
2
3
|
apply(input: ApplyInput): Promise<ApplyOutput>;
|
|
3
4
|
destroy(input: DestroyInput): Promise<DestroyOutput>;
|
|
@@ -19,6 +20,7 @@ export type ApplyInput = {
|
|
|
19
20
|
terraformStateBucketRegion?: string;
|
|
20
21
|
terraformStateLockTableName: string;
|
|
21
22
|
};
|
|
23
|
+
logger?: Logger;
|
|
22
24
|
parameters?: {
|
|
23
25
|
[key: string]: string;
|
|
24
26
|
};
|
package/dist/iac/terraform.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Logger } from '../lib/log.js';
|
|
1
2
|
import { ApplyInput, ApplyOutput, DestroyInput, DestroyOutput, Iac } from './common.js';
|
|
2
3
|
export declare class Terraform implements Iac {
|
|
3
4
|
apply(input: ApplyInput): Promise<ApplyOutput>;
|
|
4
5
|
destroy(input: DestroyInput): Promise<DestroyOutput>;
|
|
5
|
-
downloadTerraform(): Promise<boolean>;
|
|
6
|
+
downloadTerraform(logger?: Logger): Promise<boolean>;
|
|
6
7
|
private getEnv;
|
|
7
8
|
private getTerraformBinary;
|
|
8
9
|
private getWithRedirect;
|
package/dist/iac/terraform.js
CHANGED
|
@@ -26,8 +26,8 @@ export class Terraform {
|
|
|
26
26
|
await fs.promises.writeFile(backendFile, backendConfig);
|
|
27
27
|
}
|
|
28
28
|
try {
|
|
29
|
-
const terraform = await this.getTerraformBinary();
|
|
30
|
-
runShell(terraform, ['init'], {
|
|
29
|
+
const terraform = await this.getTerraformBinary(input.logger);
|
|
30
|
+
await runShell(terraform, ['init'], {
|
|
31
31
|
directory: input.pkgPath,
|
|
32
32
|
env: {
|
|
33
33
|
...mapObject(input.env ?? {}, (key, value) => [
|
|
@@ -40,8 +40,9 @@ export class Terraform {
|
|
|
40
40
|
typeof value === 'object' ? JSON.stringify(value) : value,
|
|
41
41
|
]),
|
|
42
42
|
},
|
|
43
|
+
logger: input.logger,
|
|
43
44
|
});
|
|
44
|
-
runShell(terraform, ['apply', '-auto-approve'], {
|
|
45
|
+
await runShell(terraform, ['apply', '-auto-approve'], {
|
|
45
46
|
directory: input.pkgPath,
|
|
46
47
|
env: {
|
|
47
48
|
...mapObject(input.env ?? {}, (key, value) => [
|
|
@@ -54,6 +55,7 @@ export class Terraform {
|
|
|
54
55
|
typeof value === 'object' ? JSON.stringify(value) : value,
|
|
55
56
|
]),
|
|
56
57
|
},
|
|
58
|
+
logger: input.logger,
|
|
57
59
|
});
|
|
58
60
|
const env = await this.getEnv(input.pkgPath);
|
|
59
61
|
return {
|
|
@@ -69,9 +71,9 @@ export class Terraform {
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
async destroy(input) {
|
|
72
|
-
const terraform = await this.getTerraformBinary();
|
|
74
|
+
const terraform = await this.getTerraformBinary(input.logger);
|
|
73
75
|
try {
|
|
74
|
-
runShell(terraform, ['init'], {
|
|
76
|
+
await runShell(terraform, ['init'], {
|
|
75
77
|
directory: input.pkgPath,
|
|
76
78
|
env: {
|
|
77
79
|
...mapObject(input.env ?? {}, (key, value) => [
|
|
@@ -84,9 +86,10 @@ export class Terraform {
|
|
|
84
86
|
typeof value === 'object' ? JSON.stringify(value) : value,
|
|
85
87
|
]),
|
|
86
88
|
},
|
|
89
|
+
logger: input.logger,
|
|
87
90
|
});
|
|
88
91
|
const env = await this.getEnv(input.pkgPath);
|
|
89
|
-
runShell(terraform, ['destroy', '-auto-approve'], {
|
|
92
|
+
await runShell(terraform, ['destroy', '-auto-approve'], {
|
|
90
93
|
directory: input.pkgPath,
|
|
91
94
|
env: {
|
|
92
95
|
...mapObject(input.env ?? {}, (key, value) => [
|
|
@@ -99,6 +102,7 @@ export class Terraform {
|
|
|
99
102
|
typeof value === 'object' ? JSON.stringify(value) : value,
|
|
100
103
|
]),
|
|
101
104
|
},
|
|
105
|
+
logger: input.logger,
|
|
102
106
|
});
|
|
103
107
|
return {
|
|
104
108
|
env,
|
|
@@ -112,7 +116,11 @@ export class Terraform {
|
|
|
112
116
|
};
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
|
-
async downloadTerraform() {
|
|
119
|
+
async downloadTerraform(logger) {
|
|
120
|
+
if (process.env.HEREYA_SKIP_TERRAFORM_DOWNLOAD === 'true') {
|
|
121
|
+
logger?.info('Skipping terraform download');
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
116
124
|
const TERRAFORM_DOWNLOAD_URLS = new Map([
|
|
117
125
|
['darwin_arm64', 'https://github.com/opentofu/opentofu/releases/download/v1.9.0/tofu_1.9.0_darwin_arm64.zip'],
|
|
118
126
|
['darwin_x64', 'https://github.com/opentofu/opentofu/releases/download/v1.9.0/tofu_1.9.0_darwin_amd64.zip'],
|
|
@@ -140,7 +148,7 @@ export class Terraform {
|
|
|
140
148
|
await fs.promises.rm(tfPath);
|
|
141
149
|
}
|
|
142
150
|
}
|
|
143
|
-
|
|
151
|
+
logger?.info('Downloading terraform...');
|
|
144
152
|
const binKey = `${os.platform()}_${os.arch()}`;
|
|
145
153
|
const url = TERRAFORM_DOWNLOAD_URLS.get(binKey);
|
|
146
154
|
if (!url) {
|
|
@@ -168,13 +176,13 @@ export class Terraform {
|
|
|
168
176
|
});
|
|
169
177
|
return true;
|
|
170
178
|
}
|
|
171
|
-
async getEnv(pkgPath) {
|
|
172
|
-
const terraform = await this.getTerraformBinary();
|
|
173
|
-
const resourceOut = runShell(terraform, ['output', '--json'], {
|
|
179
|
+
async getEnv(pkgPath, logger) {
|
|
180
|
+
const terraform = await this.getTerraformBinary(logger);
|
|
181
|
+
const resourceOut = await runShell(terraform, ['output', '--json'], {
|
|
174
182
|
directory: pkgPath,
|
|
175
183
|
stdio: 'pipe',
|
|
176
184
|
});
|
|
177
|
-
let outStr = resourceOut.
|
|
185
|
+
let outStr = resourceOut.stdout.toString().trim();
|
|
178
186
|
const start = outStr.indexOf('{');
|
|
179
187
|
const end = outStr.lastIndexOf('}');
|
|
180
188
|
outStr = outStr.slice(start, end + 1);
|
|
@@ -186,8 +194,8 @@ export class Terraform {
|
|
|
186
194
|
}
|
|
187
195
|
return tfEnv;
|
|
188
196
|
}
|
|
189
|
-
async getTerraformBinary() {
|
|
190
|
-
await this.downloadTerraform();
|
|
197
|
+
async getTerraformBinary(logger) {
|
|
198
|
+
await this.downloadTerraform(logger);
|
|
191
199
|
return this.terraformBinPath();
|
|
192
200
|
}
|
|
193
201
|
async getWithRedirect(url, handler, reject) {
|
|
@@ -206,6 +214,9 @@ export class Terraform {
|
|
|
206
214
|
.on('error', (error) => reject(error));
|
|
207
215
|
}
|
|
208
216
|
terraformBinPath() {
|
|
217
|
+
if (process.env.HEREYA_TERRAFORM_BIN_PATH) {
|
|
218
|
+
return process.env.HEREYA_TERRAFORM_BIN_PATH;
|
|
219
|
+
}
|
|
209
220
|
return path.join(os.homedir(), '.hereya', 'iac', 'terraform', 'tofu_1', os.platform() === 'win32' ? 'tofu.exe' : 'tofu');
|
|
210
221
|
}
|
|
211
222
|
}
|
|
@@ -15,7 +15,7 @@ export class AwsInfrastructure {
|
|
|
15
15
|
const stsClient = new STSClient({});
|
|
16
16
|
const { Account: accountId } = await stsClient.send(new GetCallerIdentityCommand({}));
|
|
17
17
|
const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;
|
|
18
|
-
runShell('npx', ['cdk', 'bootstrap', `aws://${accountId}/${region}`]);
|
|
18
|
+
await runShell('npx', ['cdk', 'bootstrap', `aws://${accountId}/${region}`]);
|
|
19
19
|
const bootstrapPackage = 'hereya/bootstrap-aws-stack';
|
|
20
20
|
const output = await provisionPackage({ package: bootstrapPackage });
|
|
21
21
|
if (!output.success) {
|
|
@@ -63,6 +63,7 @@ export class AwsInfrastructure {
|
|
|
63
63
|
env: input.env ?? {},
|
|
64
64
|
id: input.id,
|
|
65
65
|
infraConfig,
|
|
66
|
+
logger: input.logger,
|
|
66
67
|
parameters: input.parameters,
|
|
67
68
|
pkgPath: downloadPath,
|
|
68
69
|
});
|
|
@@ -97,6 +98,7 @@ export class AwsInfrastructure {
|
|
|
97
98
|
env: input.env ?? {},
|
|
98
99
|
id: input.id,
|
|
99
100
|
infraConfig,
|
|
101
|
+
logger: input.logger,
|
|
100
102
|
parameters: input.parameters,
|
|
101
103
|
pkgPath: downloadPath,
|
|
102
104
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IacType } from '../iac/common.js';
|
|
2
|
+
import { Logger } from '../lib/log.js';
|
|
2
3
|
export declare enum InfrastructureType {
|
|
3
4
|
aws = "aws",
|
|
4
5
|
azure = "azure",
|
|
@@ -27,6 +28,7 @@ export type ProvisionInput = {
|
|
|
27
28
|
};
|
|
28
29
|
iacType: IacType;
|
|
29
30
|
id: string;
|
|
31
|
+
logger?: Logger;
|
|
30
32
|
parameters?: {
|
|
31
33
|
[key: string]: string;
|
|
32
34
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Logger } from '../lib/log.js';
|
|
2
3
|
import { PackageMetadata } from '../lib/package/index.js';
|
|
3
4
|
import { AwsInfrastructure } from './aws.js';
|
|
4
5
|
import { Infrastructure, InfrastructureType } from './common.js';
|
|
@@ -15,6 +16,7 @@ export type ProvisionPackageInput = {
|
|
|
15
16
|
[key: string]: string;
|
|
16
17
|
};
|
|
17
18
|
isDeploying?: boolean;
|
|
19
|
+
logger?: Logger;
|
|
18
20
|
package: string;
|
|
19
21
|
parameters?: {
|
|
20
22
|
[key: string]: string;
|
|
@@ -57,6 +57,7 @@ export async function destroyPackage(input) {
|
|
|
57
57
|
env: input.env,
|
|
58
58
|
iacType: metadata.iac,
|
|
59
59
|
id,
|
|
60
|
+
logger: input.logger,
|
|
60
61
|
parameters: input.parameters,
|
|
61
62
|
pkgName,
|
|
62
63
|
pkgUrl: packageUri,
|
|
@@ -68,6 +69,7 @@ export async function destroyPackage(input) {
|
|
|
68
69
|
env: input.env,
|
|
69
70
|
iacType: metadata.iac,
|
|
70
71
|
id,
|
|
72
|
+
logger: input.logger,
|
|
71
73
|
parameters: input.parameters,
|
|
72
74
|
pkgName,
|
|
73
75
|
pkgUrl: packageUri,
|
|
@@ -142,6 +144,7 @@ export async function provisionPackage(input) {
|
|
|
142
144
|
env: { ...input.env, ...depsEnv },
|
|
143
145
|
iacType: metadata.iac,
|
|
144
146
|
id,
|
|
147
|
+
logger: input.logger,
|
|
145
148
|
parameters: input.parameters,
|
|
146
149
|
pkgName,
|
|
147
150
|
pkgUrl: packageUri,
|
|
@@ -153,6 +156,7 @@ export async function provisionPackage(input) {
|
|
|
153
156
|
env: input.env,
|
|
154
157
|
iacType: metadata.iac,
|
|
155
158
|
id,
|
|
159
|
+
logger: input.logger,
|
|
156
160
|
parameters: input.parameters,
|
|
157
161
|
pkgName,
|
|
158
162
|
pkgUrl: packageUri,
|
|
@@ -27,6 +27,7 @@ export class LocalInfrastructure {
|
|
|
27
27
|
const output = await iac.destroy({
|
|
28
28
|
env: input.env ?? {},
|
|
29
29
|
id: input.id,
|
|
30
|
+
logger: input.logger,
|
|
30
31
|
parameters: input.parameters,
|
|
31
32
|
pkgPath: downloadPath,
|
|
32
33
|
});
|
|
@@ -49,6 +50,7 @@ export class LocalInfrastructure {
|
|
|
49
50
|
const output = await iac.apply({
|
|
50
51
|
env: input.env ?? {},
|
|
51
52
|
id: input.id,
|
|
53
|
+
logger: input.logger,
|
|
52
54
|
parameters: input.parameters,
|
|
53
55
|
pkgPath: downloadPath,
|
|
54
56
|
});
|
package/dist/lib/log.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ListrTaskWrapper } from 'listr2';
|
|
2
|
+
export declare function setDebug(value: boolean): void;
|
|
3
|
+
export declare function isDebug(): boolean;
|
|
4
|
+
export declare function getLogger(task: ListrTaskWrapper<any, any, any>): {
|
|
5
|
+
debug(message: string): void;
|
|
6
|
+
error(message: string): void;
|
|
7
|
+
info(message: string): void;
|
|
4
8
|
};
|
|
9
|
+
export interface Logger {
|
|
10
|
+
debug(message: string): void;
|
|
11
|
+
error(message: string): void;
|
|
12
|
+
info(message: string): void;
|
|
13
|
+
}
|
package/dist/lib/log.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
let debug = false;
|
|
2
|
+
export function setDebug(value) {
|
|
3
|
+
debug = value;
|
|
4
|
+
}
|
|
5
|
+
export function isDebug() {
|
|
6
|
+
return debug;
|
|
7
|
+
}
|
|
8
|
+
export function getLogger(task) {
|
|
9
|
+
return {
|
|
10
|
+
debug(message) {
|
|
11
|
+
if (isDebug()) {
|
|
12
|
+
task.output = message;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
error(message) {
|
|
16
|
+
task.output = message;
|
|
17
|
+
},
|
|
18
|
+
info(message) {
|
|
19
|
+
task.output = message;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
13
22
|
}
|