@agilecustoms/envctl 0.12.0 → 0.13.1
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/commands/delete.js +7 -15
- package/dist/commands/deploy.js +10 -8
- package/dist/commands/index.js +1 -0
- package/dist/commands/keys.js +9 -0
- package/dist/commands/plan.js +7 -5
- package/dist/commands/status.js +18 -0
- package/dist/commands/utils.js +0 -29
- package/dist/commands/validation.js +44 -0
- package/dist/index.js +2 -1
- package/dist/service/EnvCtl.js +11 -1
- package/package.json +2 -1
package/dist/commands/delete.js
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { envCtl } from '../container.js';
|
|
3
|
+
import { KEYS } from './keys.js';
|
|
4
4
|
import { wrap } from './utils.js';
|
|
5
|
+
import { ensureEnv } from './validation.js';
|
|
5
6
|
export function deleteIt(program) {
|
|
6
7
|
program
|
|
7
8
|
.command('delete')
|
|
8
9
|
.description('Delete a development environment')
|
|
9
|
-
.option('--env <env>',
|
|
10
|
-
.option('--project <project>',
|
|
10
|
+
.option('--env <env>', KEYS.ENV)
|
|
11
|
+
.option('--project <project>', KEYS.PROJECT)
|
|
11
12
|
.action(wrap(handler));
|
|
12
13
|
}
|
|
13
14
|
async function handler(options) {
|
|
14
15
|
let { env, project } = options;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!owner) {
|
|
18
|
-
throw new KnownException('--env argument is not provided\n'
|
|
19
|
-
+ 'default to owner from local configuration, but it is not configured\n'
|
|
20
|
-
+ 'please call with --env argument or run \'envctl configure\' to configure owner');
|
|
21
|
-
}
|
|
22
|
-
console.log(`Env name not provided, default to owner name ${owner}`);
|
|
23
|
-
env = owner;
|
|
24
|
-
}
|
|
25
|
-
await envCtl.delete(env, project);
|
|
16
|
+
env = ensureEnv(env);
|
|
17
|
+
await envCtl.delete(project, env);
|
|
26
18
|
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -4,18 +4,20 @@ import { configService, envCtl } from '../container.js';
|
|
|
4
4
|
import { KnownException } from '../exceptions.js';
|
|
5
5
|
import { EnvType } from '../model/index.js';
|
|
6
6
|
import { EnvSize } from '../model/index.js';
|
|
7
|
-
import {
|
|
7
|
+
import { KEYS } from './keys.js';
|
|
8
|
+
import { wrap } from './utils.js';
|
|
9
|
+
import { ensureEnumValue, ensureKind } from './validation.js';
|
|
8
10
|
export function deploy(program) {
|
|
9
11
|
program
|
|
10
12
|
.command('deploy')
|
|
11
13
|
.description('Create new or update existing dev environment')
|
|
12
|
-
.option('--project <project>',
|
|
13
|
-
.option('--env <env>',
|
|
14
|
-
.option('--owner <owner>',
|
|
15
|
-
.option('--size <size>',
|
|
16
|
-
.option('--type <type>',
|
|
17
|
-
.option('--kind <kind>',
|
|
18
|
-
.option('--cwd <cwd>',
|
|
14
|
+
.option('--project <project>', KEYS.PROJECT)
|
|
15
|
+
.option('--env <env>', KEYS.ENV)
|
|
16
|
+
.option('--owner <owner>', KEYS.OWNER)
|
|
17
|
+
.option('--size <size>', KEYS.SIZE)
|
|
18
|
+
.option('--type <type>', KEYS.TYPE, EnvType.Dev)
|
|
19
|
+
.option('--kind <kind>', KEYS.KIND)
|
|
20
|
+
.option('--cwd <cwd>', KEYS.CWD)
|
|
19
21
|
.allowUnknownOption(true)
|
|
20
22
|
.argument('[args...]')
|
|
21
23
|
.action(wrap(handler));
|
package/dist/commands/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const KEYS = {
|
|
2
|
+
CWD: 'Working directory (default: current directory)',
|
|
3
|
+
ENV: 'Environment name (can be git hash). {project}-{env} give env key used to store env state (s3 key in case of AWS)',
|
|
4
|
+
KIND: 'Environment kind: complete project (default) or some slice such as tt-core + tt-web',
|
|
5
|
+
OWNER: 'Environment owner (GH username)',
|
|
6
|
+
PROJECT: 'Project code (like tt). Used when multiple projects deployed in same AWS account',
|
|
7
|
+
SIZE: 'Environment size: min, small, full',
|
|
8
|
+
TYPE: 'Environment type: dev, prod',
|
|
9
|
+
};
|
package/dist/commands/plan.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { envCtl } from '../container.js';
|
|
3
|
+
import { EnvType } from '../model/index.js';
|
|
3
4
|
import { parseEnvDto } from './deploy.js';
|
|
5
|
+
import { KEYS } from './keys.js';
|
|
4
6
|
import { wrap } from './utils.js';
|
|
5
7
|
export function plan(program) {
|
|
6
8
|
program
|
|
7
9
|
.command('plan')
|
|
8
10
|
.description('High level wrapper for terraform plan. Compliments deploy command: if you plan to deploy env with envctl deploy,'
|
|
9
11
|
+ ' then it is recommended to do plan with envctl plan to guarantee consistent behavior')
|
|
10
|
-
.option('--env <env>',
|
|
11
|
-
.option('--owner <owner>',
|
|
12
|
-
.option('--size <size>',
|
|
13
|
-
.option('--type <type>',
|
|
14
|
-
.option('--cwd <cwd>',
|
|
12
|
+
.option('--env <env>', KEYS.ENV)
|
|
13
|
+
.option('--owner <owner>', KEYS.OWNER)
|
|
14
|
+
.option('--size <size>', KEYS.SIZE)
|
|
15
|
+
.option('--type <type>', KEYS.TYPE, EnvType.Dev)
|
|
16
|
+
.option('--cwd <cwd>', KEYS.CWD)
|
|
15
17
|
.allowUnknownOption(true)
|
|
16
18
|
.argument('[args...]')
|
|
17
19
|
.action(wrap(handler));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { envCtl } from '../container.js';
|
|
3
|
+
import { KEYS } from './keys.js';
|
|
4
|
+
import { wrap } from './utils.js';
|
|
5
|
+
import { ensureEnv } from './validation.js';
|
|
6
|
+
export function status(program) {
|
|
7
|
+
program
|
|
8
|
+
.command('status')
|
|
9
|
+
.description('Get env status')
|
|
10
|
+
.option('--env <env>', KEYS.ENV)
|
|
11
|
+
.option('--project <project>', KEYS.PROJECT)
|
|
12
|
+
.action(wrap(handler));
|
|
13
|
+
}
|
|
14
|
+
async function handler(options) {
|
|
15
|
+
let { env, project } = options;
|
|
16
|
+
env = ensureEnv(env);
|
|
17
|
+
await envCtl.status(project, env);
|
|
18
|
+
}
|
package/dist/commands/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { ExitPromptError } from '@inquirer/core';
|
|
3
2
|
import inquirer from 'inquirer';
|
|
4
3
|
import { BusinessException, ExitException, KnownException } from '../exceptions.js';
|
|
@@ -33,31 +32,3 @@ export async function promptYesNo(message, defaultValue = false) {
|
|
|
33
32
|
}]);
|
|
34
33
|
return answer;
|
|
35
34
|
}
|
|
36
|
-
export function ensureKind(kind, cwd) {
|
|
37
|
-
if (kind) {
|
|
38
|
-
return kind;
|
|
39
|
-
}
|
|
40
|
-
kind = getDirName(cwd);
|
|
41
|
-
console.log(`Inferred kind from directory name: ${kind}`);
|
|
42
|
-
return kind;
|
|
43
|
-
}
|
|
44
|
-
function getDirName(cwd) {
|
|
45
|
-
cwd = resolveCwd(cwd);
|
|
46
|
-
return path.basename(cwd);
|
|
47
|
-
}
|
|
48
|
-
function resolveCwd(cwd) {
|
|
49
|
-
if (!cwd) {
|
|
50
|
-
return process.cwd();
|
|
51
|
-
}
|
|
52
|
-
if (path.isAbsolute(cwd)) {
|
|
53
|
-
return cwd;
|
|
54
|
-
}
|
|
55
|
-
return path.resolve(process.cwd(), cwd);
|
|
56
|
-
}
|
|
57
|
-
export function ensureEnumValue(enumObj, value, name) {
|
|
58
|
-
const values = Object.values(enumObj);
|
|
59
|
-
if (!values.includes(value)) {
|
|
60
|
-
throw new KnownException(`Invalid ${name}: "${value}". Must be one of: ${values.join(', ')}`);
|
|
61
|
-
}
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { configService } from '../container.js';
|
|
3
|
+
import { KnownException } from '../exceptions.js';
|
|
4
|
+
export function ensureKind(kind, cwd) {
|
|
5
|
+
if (kind) {
|
|
6
|
+
return kind;
|
|
7
|
+
}
|
|
8
|
+
kind = getDirName(cwd);
|
|
9
|
+
console.log(`Inferred kind from directory name: ${kind}`);
|
|
10
|
+
return kind;
|
|
11
|
+
}
|
|
12
|
+
function getDirName(cwd) {
|
|
13
|
+
cwd = resolveCwd(cwd);
|
|
14
|
+
return path.basename(cwd);
|
|
15
|
+
}
|
|
16
|
+
function resolveCwd(cwd) {
|
|
17
|
+
if (!cwd) {
|
|
18
|
+
return process.cwd();
|
|
19
|
+
}
|
|
20
|
+
if (path.isAbsolute(cwd)) {
|
|
21
|
+
return cwd;
|
|
22
|
+
}
|
|
23
|
+
return path.resolve(process.cwd(), cwd);
|
|
24
|
+
}
|
|
25
|
+
export function ensureEnumValue(enumObj, value, name) {
|
|
26
|
+
const values = Object.values(enumObj);
|
|
27
|
+
if (!values.includes(value)) {
|
|
28
|
+
throw new KnownException(`Invalid ${name}: "${value}". Must be one of: ${values.join(', ')}`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
export function ensureEnv(env) {
|
|
33
|
+
if (env) {
|
|
34
|
+
return env;
|
|
35
|
+
}
|
|
36
|
+
const owner = configService.getOwner();
|
|
37
|
+
if (!owner) {
|
|
38
|
+
throw new KnownException('--env argument is not provided\n'
|
|
39
|
+
+ 'default to owner from local configuration, but it is not configured\n'
|
|
40
|
+
+ 'please call with --env argument or run \'envctl configure\' to configure owner');
|
|
41
|
+
}
|
|
42
|
+
console.log(`Env name not provided, default to owner name ${owner}`);
|
|
43
|
+
return owner;
|
|
44
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import updateNotifier from 'update-notifier';
|
|
5
|
-
import { configure, deleteIt, deploy, plan } from './commands/index.js';
|
|
5
|
+
import { configure, deleteIt, deploy, plan, status } from './commands/index.js';
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
const pkg = require('../package.json');
|
|
8
8
|
updateNotifier({ pkg, updateCheckInterval: 0 }).notify();
|
|
@@ -15,4 +15,5 @@ configure(program);
|
|
|
15
15
|
deploy(program);
|
|
16
16
|
deleteIt(program);
|
|
17
17
|
plan(program);
|
|
18
|
+
status(program);
|
|
18
19
|
program.parse(process.argv);
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -11,6 +11,16 @@ export class EnvCtl {
|
|
|
11
11
|
key(project, env) {
|
|
12
12
|
return project ? `${project}-${env}` : env;
|
|
13
13
|
}
|
|
14
|
+
async status(project, envName) {
|
|
15
|
+
const key = this.key(project, envName);
|
|
16
|
+
console.log(`Retrieve env ${key}`);
|
|
17
|
+
const env = await this.envApi.get(key);
|
|
18
|
+
if (env === null) {
|
|
19
|
+
console.log(`Env ${key} does not exist`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log(`Env ${key} status: ${env.status}`);
|
|
23
|
+
}
|
|
14
24
|
async plan(envDto, tfArgs, cwd) {
|
|
15
25
|
const key = this.key(envDto.project, envDto.env);
|
|
16
26
|
console.log(`Check if env ${key} already exists`);
|
|
@@ -83,7 +93,7 @@ export class EnvCtl {
|
|
|
83
93
|
console.log('Unlock env after db evolution');
|
|
84
94
|
await this.envApi.activate(key);
|
|
85
95
|
}
|
|
86
|
-
async delete(
|
|
96
|
+
async delete(project, envName) {
|
|
87
97
|
const key = this.key(project, envName);
|
|
88
98
|
console.log(`Retrieve env`);
|
|
89
99
|
const env = await this.envApi.get(key);
|
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.13.1",
|
|
5
5
|
"author": "Alex Chekulaev",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"run": "node dist/index.js",
|
|
28
28
|
"run-version": "tsc --sourceMap true && npm run run -- --version",
|
|
29
29
|
"run-configure": "tsc --sourceMap true && npm run run -- configure",
|
|
30
|
+
"run-status": "tsc --sourceMap true && npm run run -- status",
|
|
30
31
|
"run-plan": "tsc --sourceMap true && npm run run -- plan --size min --cwd ../tt-core",
|
|
31
32
|
"run-deploy": "tsc --sourceMap true && npm run run -- deploy --size min --cwd ../tt-core",
|
|
32
33
|
"run-delete": "tsc --sourceMap true && npm run run -- delete"
|