@agilecustoms/envctl 0.27.1 → 0.27.3
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.
|
@@ -6,11 +6,11 @@ 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
|
-
.
|
|
9
|
+
.requiredOption('--key <key>', _keys.KEY)
|
|
10
10
|
.action(wrap(handler));
|
|
11
11
|
}
|
|
12
12
|
async function handler(options) {
|
|
13
|
-
const {
|
|
14
|
-
const token = await envCtl.createEphemeral(
|
|
13
|
+
const { key } = options;
|
|
14
|
+
const token = await envCtl.createEphemeral(key);
|
|
15
15
|
console.log(token);
|
|
16
16
|
}
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -45,9 +45,10 @@ export class EnvCtl {
|
|
|
45
45
|
}
|
|
46
46
|
return env;
|
|
47
47
|
}
|
|
48
|
-
checkInput(env,
|
|
48
|
+
checkInput(env, cwd) {
|
|
49
49
|
if (env.ephemeral)
|
|
50
50
|
return;
|
|
51
|
+
const owner = this.configService.getOwner();
|
|
51
52
|
if (env.owner !== owner) {
|
|
52
53
|
throw new KnownException(`Can not change env owner ${env.owner} -> ${owner}`);
|
|
53
54
|
}
|
|
@@ -71,25 +72,20 @@ export class EnvCtl {
|
|
|
71
72
|
const key = this.terraformAdapter.getKey(cwd);
|
|
72
73
|
const owner = this.configService.getOwner();
|
|
73
74
|
const env = await this.tryGetEnv(key);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw new KnownException(`Env ${env.key} status is ${env.status}, can not run plan`);
|
|
75
|
+
let vars = undefined;
|
|
76
|
+
if (env) {
|
|
77
|
+
this.checkInput(env, cwd);
|
|
78
|
+
this.checkStatus(env);
|
|
79
|
+
await this.promptUnlock(env);
|
|
80
|
+
if (env.status !== EnvStatus.Active) {
|
|
81
|
+
throw new KnownException(`Env ${env.key} status is ${env.status}, can not run plan`);
|
|
82
|
+
}
|
|
83
|
+
vars = env.vars;
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
async runPlan(key, owner, args, vars, cwd) {
|
|
88
|
-
const envTerraform = { key, ephemeral: false, owner, args, vars };
|
|
85
|
+
const envTerraform = { key, ephemeral: false, owner, args: tfArgs, vars };
|
|
89
86
|
await this.terraformAdapter.plan(envTerraform, cwd);
|
|
90
87
|
}
|
|
91
|
-
async createEphemeral(
|
|
92
|
-
const key = this.terraformAdapter.getKey(cwd);
|
|
88
|
+
async createEphemeral(key) {
|
|
93
89
|
const env = await this.envApi.get(key);
|
|
94
90
|
if (env !== null) {
|
|
95
91
|
throw new KnownException(`Env ${key} already exists`);
|
|
@@ -99,31 +95,32 @@ export class EnvCtl {
|
|
|
99
95
|
}
|
|
100
96
|
async deploy(tfArgs, cwd) {
|
|
101
97
|
const key = this.terraformAdapter.getKey(cwd);
|
|
102
|
-
|
|
103
|
-
const env = await this.tryGetEnv(key);
|
|
98
|
+
let env = await this.tryGetEnv(key);
|
|
104
99
|
if (env === null) {
|
|
105
100
|
const kind = this.cliHelper.getKind(cwd);
|
|
106
101
|
console.log('Creating env metadata');
|
|
102
|
+
const owner = this.configService.getOwner();
|
|
107
103
|
const createEnv = { key, owner, kind };
|
|
108
|
-
|
|
109
|
-
return await this.runDeploy(newEnv, key, tfArgs, cwd);
|
|
104
|
+
env = await this.envApi.create(createEnv);
|
|
110
105
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
else {
|
|
107
|
+
this.checkInput(env, cwd);
|
|
108
|
+
this.checkStatus(env);
|
|
109
|
+
if (env.status === EnvStatus.Init) {
|
|
110
|
+
await this.envApi.lockForUpdate(env);
|
|
111
|
+
}
|
|
112
|
+
else if (env.status == EnvStatus.Updating) {
|
|
113
|
+
const answerYes = await this.cliHelper.promptYesNo(`Env status is ${env.status},
|
|
118
114
|
likely to be an error from a previous run\nDo you want to proceed with deployment?`);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
if (!answerYes) {
|
|
116
|
+
console.log('Aborting deployment');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (env.status === EnvStatus.Active) {
|
|
121
|
+
console.log('Env status is ACTIVE\nWill lock for update and run terraform apply (to update resources)');
|
|
122
|
+
await this.envApi.lockForUpdate(env);
|
|
122
123
|
}
|
|
123
|
-
}
|
|
124
|
-
if (env.status === EnvStatus.Active) {
|
|
125
|
-
console.log('Env status is ACTIVE\nWill lock for update and run terraform apply (to update resources)');
|
|
126
|
-
await this.envApi.lockForUpdate(env);
|
|
127
124
|
}
|
|
128
125
|
await this.runDeploy(env, key, tfArgs, cwd);
|
|
129
126
|
}
|
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.27.
|
|
4
|
+
"version": "0.27.3",
|
|
5
5
|
"author": "Alex Chekulaev",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"run-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
|
|
37
37
|
"run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
|
|
38
38
|
"-": "",
|
|
39
|
+
"run-ephemeral-create": " tsc --sourceMap true && npm run run -- create-ephemeral --key test",
|
|
39
40
|
"run-ephemeral-init": "cd ../tt-gitops && terraform init -upgrade -backend-config=key=test -reconfigure",
|
|
40
|
-
"run-ephemeral-create": " tsc --sourceMap true && npm run run -- create-ephemeral --cwd ../tt-gitops",
|
|
41
41
|
"run-ephemeral-status": " tsc --sourceMap true && npm run run -- status --key test",
|
|
42
42
|
"run-ephemeral-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-gitops -var-file=versions.tfvars",
|
|
43
43
|
"run-ephemeral-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-gitops --force",
|