@agilecustoms/envctl 0.8.0 → 0.9.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/commands/delete.js
CHANGED
|
@@ -5,10 +5,11 @@ export function deleteIt(program) {
|
|
|
5
5
|
program
|
|
6
6
|
.command('delete')
|
|
7
7
|
.description('Delete a development environment')
|
|
8
|
-
.requiredOption('--project <project>', 'Project name: can be project code (like tt when deploy whole project), or {code}-{microservice} if you want to deploy a single microservice')
|
|
9
8
|
.requiredOption('--env <env>', 'Environment name (can be git hash). {project}-{env} give env key used to store env state (s3 key in case of AWS)')
|
|
9
|
+
.option('--project <project>', 'Project code (like tt). Used when multiple projects deployed in same AWS account')
|
|
10
10
|
.action(wrap(handler));
|
|
11
11
|
}
|
|
12
12
|
async function handler(options) {
|
|
13
|
-
|
|
13
|
+
let { env, project } = options;
|
|
14
|
+
await envCtl.delete(env, project);
|
|
14
15
|
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { envCtl } from '../container.js';
|
|
3
|
-
import { wrap } from './utils.js';
|
|
3
|
+
import { ensureKind, wrap } from './utils.js';
|
|
4
4
|
export function deploy(program) {
|
|
5
5
|
program
|
|
6
6
|
.command('deploy')
|
|
7
7
|
.description('Create new or update existing dev environment')
|
|
8
|
-
.
|
|
9
|
-
.
|
|
8
|
+
.option('--project <project>', 'Project code (like tt). Used when multiple projects deployed in same AWS account')
|
|
9
|
+
.option('--env <env>', 'Environment name (can be git hash). {project}-{env} give env key used to store env state (s3 key in case of AWS)')
|
|
10
10
|
.requiredOption('--owner <owner>', 'Environment owner (GH username)')
|
|
11
11
|
.requiredOption('--size <size>', 'Environment size: min, small, full')
|
|
12
12
|
.option('--type <type>', 'Environment type: dev, prod', 'dev')
|
|
@@ -17,7 +17,12 @@ export function deploy(program) {
|
|
|
17
17
|
.action(wrap(handler));
|
|
18
18
|
}
|
|
19
19
|
async function handler(tfArgs, options) {
|
|
20
|
-
|
|
20
|
+
let { project, env, owner, size, type, kind, cwd } = options;
|
|
21
|
+
if (!env) {
|
|
22
|
+
console.log(`Env name not provided, default to owner name ${owner}`);
|
|
23
|
+
env = owner;
|
|
24
|
+
}
|
|
25
|
+
kind = ensureKind(kind, cwd);
|
|
21
26
|
const envAttributes = { project, env, owner, size, type, kind };
|
|
22
27
|
await envCtl.deploy(envAttributes, tfArgs, options.cwd);
|
|
23
28
|
}
|
package/dist/commands/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'path';
|
|
1
2
|
import { stdin as input, stdout as output } from 'process';
|
|
2
3
|
import { createInterface } from 'readline/promises';
|
|
3
4
|
import { BusinessException, ExitException, KnownException } from '../exceptions.js';
|
|
@@ -31,3 +32,24 @@ export async function promptYesNo(question) {
|
|
|
31
32
|
const answer = await prompt(question);
|
|
32
33
|
return answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes';
|
|
33
34
|
}
|
|
35
|
+
export function ensureKind(kind, cwd) {
|
|
36
|
+
if (kind) {
|
|
37
|
+
return kind;
|
|
38
|
+
}
|
|
39
|
+
kind = getDirName(cwd);
|
|
40
|
+
console.log(`Inferred kind from directory name: ${kind}`);
|
|
41
|
+
return kind;
|
|
42
|
+
}
|
|
43
|
+
function getDirName(cwd) {
|
|
44
|
+
cwd = resolveCwd(cwd);
|
|
45
|
+
return path.basename(cwd);
|
|
46
|
+
}
|
|
47
|
+
function resolveCwd(cwd) {
|
|
48
|
+
if (!cwd) {
|
|
49
|
+
return process.cwd();
|
|
50
|
+
}
|
|
51
|
+
if (path.isAbsolute(cwd)) {
|
|
52
|
+
return cwd;
|
|
53
|
+
}
|
|
54
|
+
return path.resolve(process.cwd(), cwd);
|
|
55
|
+
}
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -8,7 +8,7 @@ export class EnvCtl {
|
|
|
8
8
|
this.terraformAdapter = terraformAdapter;
|
|
9
9
|
}
|
|
10
10
|
async deploy(envDto, tfArgs, cwd) {
|
|
11
|
-
const key = `${envDto.project}-${envDto.env}
|
|
11
|
+
const key = envDto.project ? `${envDto.project}-${envDto.env}` : envDto.env;
|
|
12
12
|
console.log(`Check if env ${key} already exists`);
|
|
13
13
|
const env = await this.envApi.get(key);
|
|
14
14
|
if (env === null) {
|
|
@@ -53,6 +53,10 @@ export class EnvCtl {
|
|
|
53
53
|
await this.envApi.lockForUpdate(key);
|
|
54
54
|
await this.runDeploy(key, envDto, tfArgs, cwd);
|
|
55
55
|
}
|
|
56
|
+
else if (env.status === 'DELETING') {
|
|
57
|
+
const time = env.size === 'min' ? 2 : 5;
|
|
58
|
+
throw new KnownException(`Env status is DELETING, please wait (~${time} min)`);
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
async runDeploy(key, envAttrs, tfArgs, cwd) {
|
|
58
62
|
console.log('Deploying resources');
|
|
@@ -64,8 +68,8 @@ export class EnvCtl {
|
|
|
64
68
|
console.log('Unlock env after db evolution');
|
|
65
69
|
await this.envApi.activate(key);
|
|
66
70
|
}
|
|
67
|
-
async delete(
|
|
68
|
-
const key = `${project}-${envName}
|
|
71
|
+
async delete(envName, project) {
|
|
72
|
+
const key = project ? `${project}-${envName}` : envName;
|
|
69
73
|
console.log(`Retrieve env`);
|
|
70
74
|
const env = await this.envApi.get(key);
|
|
71
75
|
if (env === null) {
|
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.9.0",
|
|
5
5
|
"author": "Alex Chekulaev",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"build": "tsc",
|
|
27
27
|
"run": "node dist/index.js",
|
|
28
28
|
"run-version": "tsc --sourceMap true && npm run run -- --version",
|
|
29
|
-
"run-deploy": "tsc --sourceMap true &&
|
|
30
|
-
"run-delete": "tsc --sourceMap true &&
|
|
29
|
+
"run-deploy": "tsc --sourceMap true && npm run run -- deploy --owner laxa1986 --size min --cwd ../tt-core",
|
|
30
|
+
"run-delete": "tsc --sourceMap true && npm run run -- delete --env laxa1986"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@aws-sdk/client-sts": "^3.716.0",
|