@agilecustoms/envctl 0.24.0 → 0.25.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/dist/client/CliHelper.js +6 -6
- package/dist/client/TerraformAdapter.js +1 -1
- package/dist/commands/_keys.js +1 -1
- package/dist/commands/createEphemeral.js +3 -3
- package/dist/commands/delete.js +4 -4
- package/dist/commands/deploy.js +2 -3
- package/dist/commands/destroy.js +4 -4
- package/dist/commands/init.js +4 -4
- package/dist/commands/plan.js +2 -3
- package/dist/commands/status.js +4 -4
- package/dist/service/EnvCtl.js +23 -31
- package/package.json +3 -2
package/dist/client/CliHelper.js
CHANGED
|
@@ -16,17 +16,17 @@ export class CliHelper {
|
|
|
16
16
|
}]);
|
|
17
17
|
return answer;
|
|
18
18
|
}
|
|
19
|
-
ensureEnv(
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
19
|
+
ensureEnv(key) {
|
|
20
|
+
if (key) {
|
|
21
|
+
return key;
|
|
22
22
|
}
|
|
23
23
|
const owner = this.configService.getOwner();
|
|
24
24
|
if (!owner) {
|
|
25
|
-
throw new KnownException('--
|
|
25
|
+
throw new KnownException('--key argument is not provided\n'
|
|
26
26
|
+ 'default to owner from local configuration, but it is not configured\n'
|
|
27
|
-
+ 'please call with --
|
|
27
|
+
+ 'please call with --key argument or run \'envctl configure\' to configure owner');
|
|
28
28
|
}
|
|
29
|
-
console.log(`
|
|
29
|
+
console.log(`Key is not provided, default to owner name ${owner}`);
|
|
30
30
|
return owner;
|
|
31
31
|
}
|
|
32
32
|
ensureOwner(owner) {
|
|
@@ -69,7 +69,7 @@ export class TerraformAdapter {
|
|
|
69
69
|
tfArgs(env, cwd) {
|
|
70
70
|
const varDefs = this.getVarDefs(cwd);
|
|
71
71
|
const argVars = this.getArgVars(env.args);
|
|
72
|
-
const specialFields = { ...env, env: env.
|
|
72
|
+
const specialFields = { ...env, env: env.key };
|
|
73
73
|
const extraArgs = [];
|
|
74
74
|
for (const name of ['env', 'owner', 'ephemeral']) {
|
|
75
75
|
if (varDefs[name] && !argVars[name]) {
|
package/dist/commands/_keys.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const _keys = {
|
|
2
2
|
CWD: 'Working directory (default: current directory)',
|
|
3
|
-
ENV: 'Environment name (can be git hash). = key used to store env state (s3 key in case of AWS)',
|
|
4
3
|
FORCE: 'Force deletion without confirmation',
|
|
4
|
+
KEY: 'Environment name/identifier - taken from remote stake key, must be unique for a given customer',
|
|
5
5
|
KIND: 'Environment kind: complete project (default) or some slice such as tt-core + tt-web',
|
|
6
6
|
OWNER: 'Environment owner (GH username)'
|
|
7
7
|
};
|
|
@@ -6,12 +6,12 @@ export function createEphemeral(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('create-ephemeral')
|
|
8
8
|
.description('Create bare env w/o resources. Used in CI as first step just to pre-generate token for extension')
|
|
9
|
-
.requiredOption('--
|
|
9
|
+
.requiredOption('--key <key>', _keys.KEY)
|
|
10
10
|
.option('--owner <owner>', _keys.OWNER)
|
|
11
11
|
.action(wrap(handler));
|
|
12
12
|
}
|
|
13
13
|
async function handler(options) {
|
|
14
|
-
const {
|
|
15
|
-
const token = await envCtl.createEphemeral(
|
|
14
|
+
const { key, owner } = options;
|
|
15
|
+
const token = await envCtl.createEphemeral(key, owner);
|
|
16
16
|
console.log(token);
|
|
17
17
|
}
|
package/dist/commands/delete.js
CHANGED
|
@@ -6,13 +6,13 @@ export function deleteIt(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('delete')
|
|
8
8
|
.description('Delete a development environment')
|
|
9
|
-
.option('--
|
|
9
|
+
.option('--key <key>', _keys.KEY)
|
|
10
10
|
.option('--force', _keys.FORCE)
|
|
11
11
|
.option('--cwd <cwd>', _keys.CWD)
|
|
12
12
|
.action(wrap(handler));
|
|
13
13
|
}
|
|
14
14
|
async function handler(options) {
|
|
15
|
-
const {
|
|
16
|
-
const
|
|
17
|
-
await envCtl.delete(
|
|
15
|
+
const { key, force, cwd } = options;
|
|
16
|
+
const theKey = cliHelper.ensureEnv(key);
|
|
17
|
+
await envCtl.delete(theKey, Boolean(force), cwd);
|
|
18
18
|
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -6,7 +6,7 @@ export function deploy(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('deploy')
|
|
8
8
|
.description('Create new or update existing dev environment')
|
|
9
|
-
.option('--
|
|
9
|
+
.option('--key <key>', _keys.KEY)
|
|
10
10
|
.option('--owner <owner>', _keys.OWNER)
|
|
11
11
|
.option('--kind <kind>', _keys.KIND)
|
|
12
12
|
.option('--cwd <cwd>', _keys.CWD)
|
|
@@ -16,7 +16,6 @@ export function deploy(program) {
|
|
|
16
16
|
}
|
|
17
17
|
async function handler(tfArgs, options) {
|
|
18
18
|
await awsCredsHelper.ensureCredentials();
|
|
19
|
-
const { cwd,
|
|
20
|
-
envDto.envName = env;
|
|
19
|
+
const { cwd, ...envDto } = options;
|
|
21
20
|
await envCtl.deploy(envDto, tfArgs, cwd);
|
|
22
21
|
}
|
package/dist/commands/destroy.js
CHANGED
|
@@ -8,7 +8,7 @@ export function destroy(program) {
|
|
|
8
8
|
.description('Destroy environment resources. This is thin wrapper for terraform destroy.'
|
|
9
9
|
+ ' Unlike "delete" command (which just schedule deletion) this command deletes resources synchronously.'
|
|
10
10
|
+ ' Main use case - test deletion process, basically that you have enough permissions to delete resources')
|
|
11
|
-
.option('--
|
|
11
|
+
.option('--key <key>', _keys.KEY)
|
|
12
12
|
.option('--force', _keys.FORCE)
|
|
13
13
|
.option('--cwd <cwd>', _keys.CWD)
|
|
14
14
|
.allowUnknownOption(true)
|
|
@@ -16,7 +16,7 @@ export function destroy(program) {
|
|
|
16
16
|
.action(wrap(handler));
|
|
17
17
|
}
|
|
18
18
|
async function handler(tfArgs, options) {
|
|
19
|
-
const {
|
|
20
|
-
const
|
|
21
|
-
await envCtl.destroy(
|
|
19
|
+
const { key, force, cwd } = options;
|
|
20
|
+
const theKey = cliHelper.ensureEnv(key);
|
|
21
|
+
await envCtl.destroy(theKey, tfArgs, Boolean(force), cwd);
|
|
22
22
|
}
|
package/dist/commands/init.js
CHANGED
|
@@ -6,12 +6,12 @@ export function init(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('init')
|
|
8
8
|
.description('Terraform init wrapper')
|
|
9
|
-
.option('--
|
|
9
|
+
.option('--key <key>', _keys.KEY)
|
|
10
10
|
.option('--cwd <cwd>', _keys.CWD)
|
|
11
11
|
.action(wrap(handler));
|
|
12
12
|
}
|
|
13
13
|
async function handler(options) {
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
await envCtl.init(
|
|
14
|
+
const { key, cwd } = options;
|
|
15
|
+
const theKey = cliHelper.ensureEnv(key);
|
|
16
|
+
await envCtl.init(theKey, cwd);
|
|
17
17
|
}
|
package/dist/commands/plan.js
CHANGED
|
@@ -7,7 +7,7 @@ export function plan(program) {
|
|
|
7
7
|
.command('plan')
|
|
8
8
|
.description('High level wrapper for terraform plan. Compliments deploy command: if you plan to deploy env with envctl deploy,'
|
|
9
9
|
+ ' then it is recommended to do plan with envctl plan to guarantee consistent behavior')
|
|
10
|
-
.option('--
|
|
10
|
+
.option('--key <key>', _keys.KEY)
|
|
11
11
|
.option('--owner <owner>', _keys.OWNER)
|
|
12
12
|
.option('--cwd <cwd>', _keys.CWD)
|
|
13
13
|
.allowUnknownOption(true)
|
|
@@ -16,7 +16,6 @@ export function plan(program) {
|
|
|
16
16
|
}
|
|
17
17
|
async function handler(tfArgs, options) {
|
|
18
18
|
await awsCredsHelper.ensureCredentials();
|
|
19
|
-
const { cwd,
|
|
20
|
-
envDto.envName = env;
|
|
19
|
+
const { cwd, ...envDto } = options;
|
|
21
20
|
await envCtl.plan(envDto, tfArgs, cwd);
|
|
22
21
|
}
|
package/dist/commands/status.js
CHANGED
|
@@ -6,12 +6,12 @@ export function status(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('status')
|
|
8
8
|
.description('Get env status')
|
|
9
|
-
.option('--
|
|
9
|
+
.option('--key <key>', _keys.KEY)
|
|
10
10
|
.option('--cwd <cwd>', _keys.CWD)
|
|
11
11
|
.action(wrap(handler));
|
|
12
12
|
}
|
|
13
13
|
async function handler(options) {
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
await envCtl.status(
|
|
14
|
+
const { key, cwd } = options;
|
|
15
|
+
const theKey = cliHelper.ensureEnv(key);
|
|
16
|
+
await envCtl.status(theKey, cwd);
|
|
17
17
|
}
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -9,11 +9,7 @@ export class EnvCtl {
|
|
|
9
9
|
this.envApi = envApi;
|
|
10
10
|
this.terraformAdapter = terraformAdapter;
|
|
11
11
|
}
|
|
12
|
-
key
|
|
13
|
-
return env;
|
|
14
|
-
}
|
|
15
|
-
async status(envName, cwd) {
|
|
16
|
-
const key = this.key(envName);
|
|
12
|
+
async status(key, cwd) {
|
|
17
13
|
console.log(`Retrieve env ${key}`);
|
|
18
14
|
const env = await this.envApi.get(key);
|
|
19
15
|
if (env === null) {
|
|
@@ -27,14 +23,13 @@ export class EnvCtl {
|
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
25
|
async tryGetEnv(input) {
|
|
30
|
-
let
|
|
26
|
+
let key = input.key;
|
|
31
27
|
let owner = input.owner;
|
|
32
|
-
if (!
|
|
28
|
+
if (!key) {
|
|
33
29
|
owner = this.cliHelper.ensureOwner(owner);
|
|
34
30
|
console.log(`Env name not provided, default to owner name ${owner}`);
|
|
35
|
-
|
|
31
|
+
key = owner;
|
|
36
32
|
}
|
|
37
|
-
const key = this.key(envName);
|
|
38
33
|
console.log(`Check if env ${key} already exists`);
|
|
39
34
|
const env = await this.envApi.get(key);
|
|
40
35
|
if (env) {
|
|
@@ -43,7 +38,7 @@ export class EnvCtl {
|
|
|
43
38
|
else {
|
|
44
39
|
console.log(`Env ${key} does not exist`);
|
|
45
40
|
}
|
|
46
|
-
return {
|
|
41
|
+
return { anOwner: owner, key, env };
|
|
47
42
|
}
|
|
48
43
|
checkInput(env, input, cwd) {
|
|
49
44
|
if (input.owner && env.owner !== input.owner) {
|
|
@@ -63,15 +58,14 @@ export class EnvCtl {
|
|
|
63
58
|
}
|
|
64
59
|
throw new KnownException(`Env ${env.key} status is ${env.status}, can not run this command`);
|
|
65
60
|
}
|
|
66
|
-
async init(
|
|
67
|
-
const key = this.key(envName);
|
|
61
|
+
async init(key, cwd) {
|
|
68
62
|
await this.terraformAdapter.init(key, cwd, true);
|
|
69
63
|
}
|
|
70
64
|
async plan(input, tfArgs, cwd) {
|
|
71
|
-
const {
|
|
65
|
+
const { anOwner, key, env } = await this.tryGetEnv(input);
|
|
72
66
|
if (env == null) {
|
|
73
67
|
const owner = this.cliHelper.ensureOwner(anOwner);
|
|
74
|
-
await this.runPlan(key,
|
|
68
|
+
await this.runPlan(key, owner, tfArgs, undefined, cwd);
|
|
75
69
|
return;
|
|
76
70
|
}
|
|
77
71
|
this.checkInput(env, input, cwd);
|
|
@@ -81,15 +75,14 @@ export class EnvCtl {
|
|
|
81
75
|
if (env.status !== EnvStatus.Active) {
|
|
82
76
|
throw new KnownException(`Env ${env.key} status is ${env.status}, can not run plan`);
|
|
83
77
|
}
|
|
84
|
-
await this.runPlan(key,
|
|
78
|
+
await this.runPlan(key, owner, tfArgs, env.vars, cwd);
|
|
85
79
|
}
|
|
86
|
-
async runPlan(key,
|
|
87
|
-
const envTerraform = {
|
|
80
|
+
async runPlan(key, owner, args, vars, cwd) {
|
|
81
|
+
const envTerraform = { key, ephemeral: false, owner, args, vars };
|
|
88
82
|
await this.terraformAdapter.init(key, cwd);
|
|
89
83
|
await this.terraformAdapter.plan(envTerraform, cwd);
|
|
90
84
|
}
|
|
91
|
-
async createEphemeral(
|
|
92
|
-
const key = this.key(envName);
|
|
85
|
+
async createEphemeral(key, owner) {
|
|
93
86
|
const env = await this.envApi.get(key);
|
|
94
87
|
if (env !== null) {
|
|
95
88
|
throw new KnownException(`Env ${key} already exists`);
|
|
@@ -98,14 +91,14 @@ export class EnvCtl {
|
|
|
98
91
|
return await this.envApi.createEphemeral(createEnv);
|
|
99
92
|
}
|
|
100
93
|
async deploy(input, tfArgs, cwd) {
|
|
101
|
-
const {
|
|
94
|
+
const { anOwner, key, env } = await this.tryGetEnv(input);
|
|
102
95
|
if (env === null) {
|
|
103
96
|
const owner = this.cliHelper.ensureOwner(anOwner);
|
|
104
97
|
const kind = this.cliHelper.ensureKind(input.kind, cwd);
|
|
105
98
|
console.log('Creating env tracking record in DynamoDB');
|
|
106
99
|
const createEnv = { key, owner, kind };
|
|
107
100
|
const newEnv = await this.envApi.create(createEnv);
|
|
108
|
-
return await this.runDeploy(newEnv,
|
|
101
|
+
return await this.runDeploy(newEnv, key, tfArgs, cwd);
|
|
109
102
|
}
|
|
110
103
|
this.checkInput(env, input, cwd);
|
|
111
104
|
this.checkStatus(env);
|
|
@@ -124,13 +117,13 @@ export class EnvCtl {
|
|
|
124
117
|
console.log('Env status is ACTIVE\nWill lock for update and run terraform apply (to update resources)');
|
|
125
118
|
await this.envApi.lockForUpdate(env);
|
|
126
119
|
}
|
|
127
|
-
await this.runDeploy(env,
|
|
120
|
+
await this.runDeploy(env, key, tfArgs, cwd);
|
|
128
121
|
}
|
|
129
|
-
async runDeploy(env,
|
|
122
|
+
async runDeploy(env, key, tfArgs, cwd) {
|
|
130
123
|
await this.terraformAdapter.init(env.key, cwd);
|
|
131
124
|
console.log('Deploying resources');
|
|
132
125
|
const { ephemeral, vars } = env;
|
|
133
|
-
const envTerraform = {
|
|
126
|
+
const envTerraform = { key, ephemeral, owner: env.owner || 'system', args: tfArgs, vars };
|
|
134
127
|
const onDemandVars = {};
|
|
135
128
|
try {
|
|
136
129
|
await this.terraformAdapter.apply(envTerraform, onDemandVars, cwd);
|
|
@@ -146,8 +139,8 @@ export class EnvCtl {
|
|
|
146
139
|
console.log('Activating env (to finish creation)');
|
|
147
140
|
await this.envApi.activate(env);
|
|
148
141
|
}
|
|
149
|
-
async delete(
|
|
150
|
-
const env = await this.get(
|
|
142
|
+
async delete(key, force, cwd) {
|
|
143
|
+
const env = await this.get(key);
|
|
151
144
|
if (!force) {
|
|
152
145
|
this.checkStatus(env);
|
|
153
146
|
if (env.status === EnvStatus.Init) {
|
|
@@ -174,8 +167,8 @@ export class EnvCtl {
|
|
|
174
167
|
const message = await this.envApi.delete(env);
|
|
175
168
|
console.log(message);
|
|
176
169
|
}
|
|
177
|
-
async destroy(
|
|
178
|
-
const env = await this.get(
|
|
170
|
+
async destroy(key, tfArgs, force, cwd) {
|
|
171
|
+
const env = await this.get(key);
|
|
179
172
|
this.checkStatus(env);
|
|
180
173
|
if (env.status === EnvStatus.Init) {
|
|
181
174
|
console.log(`Env ${env.key} has no resources, nothing to destroy, call 'delete' command instead`);
|
|
@@ -196,7 +189,7 @@ export class EnvCtl {
|
|
|
196
189
|
await this.envApi.lockForUpdate(env);
|
|
197
190
|
}
|
|
198
191
|
const { ephemeral, owner, vars } = env;
|
|
199
|
-
const envTerraform = {
|
|
192
|
+
const envTerraform = { key, ephemeral, owner: owner || 'system', args: tfArgs, vars };
|
|
200
193
|
console.log('Destroying env resources');
|
|
201
194
|
await this.terraformAdapter.init(env.key, cwd);
|
|
202
195
|
await this.terraformAdapter.destroy(envTerraform, force, cwd);
|
|
@@ -206,8 +199,7 @@ export class EnvCtl {
|
|
|
206
199
|
await this.envApi.delete(env);
|
|
207
200
|
console.log('Please wait for ~15 sec before you can create env with same name');
|
|
208
201
|
}
|
|
209
|
-
async get(
|
|
210
|
-
const key = this.key(envName);
|
|
202
|
+
async get(key) {
|
|
211
203
|
console.log(`Retrieve env ${key}`);
|
|
212
204
|
const env = await this.envApi.get(key);
|
|
213
205
|
if (!env) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agilecustoms/envctl",
|
|
3
3
|
"description": "node.js CLI client for manage environments",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.25.0",
|
|
5
5
|
"author": "Alex Chekulaev",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
"run-version": " tsc --sourceMap true && npm run run -- --version",
|
|
30
30
|
"run-configure": "tsc --sourceMap true && npm run run -- configure",
|
|
31
31
|
"~": "",
|
|
32
|
+
"run-init": "cd ../tt-core && terraform init -backend-config=key=laxa1986 -upgrade",
|
|
33
|
+
"*": "",
|
|
32
34
|
"run-status": " tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
|
|
33
|
-
"run-init": " tsc --sourceMap true && npm run run -- init --cwd ../tt-core",
|
|
34
35
|
"run-plan": " tsc --sourceMap true && npm run run -- plan --cwd ../tt-core",
|
|
35
36
|
"run-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-core -var=\"env_size=min\"",
|
|
36
37
|
"run-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
|