@agilecustoms/envctl 1.17.0 → 1.18.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/client/Cli.js
CHANGED
package/dist/commands/_keys.js
CHANGED
package/dist/commands/plan.js
CHANGED
|
@@ -5,7 +5,7 @@ import { wrap } from './_utils.js';
|
|
|
5
5
|
export function plan(program, configService, envService) {
|
|
6
6
|
program
|
|
7
7
|
.command('plan')
|
|
8
|
-
.description('High level wrapper for terraform plan. Compliments
|
|
8
|
+
.description('High level wrapper for terraform plan. Compliments apply command: if you plan to deploy env with envctl apply,'
|
|
9
9
|
+ ' then it is recommended to do plan with envctl plan to guarantee consistent behavior')
|
|
10
10
|
.option('--profile <profile>', _keys.PROFILE)
|
|
11
11
|
.allowUnknownOption(true)
|
|
@@ -2,18 +2,18 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as os from 'node:os';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { KnownException } from '../exceptions.js';
|
|
5
|
-
const CONFIG_DIR = path.join(os.homedir(), '.envctl');
|
|
6
5
|
export const DEFAULT_HOST = 'cli.maintenance.agilecustoms.com';
|
|
7
|
-
var EnvKey;
|
|
6
|
+
export var EnvKey;
|
|
8
7
|
(function (EnvKey) {
|
|
9
8
|
EnvKey["API_KEY"] = "ENVCTL_API_KEY";
|
|
9
|
+
EnvKey["HOME"] = "ENVCTL_HOME";
|
|
10
10
|
EnvKey["PROFILE"] = "ENVCTL_PROFILE";
|
|
11
11
|
})(EnvKey || (EnvKey = {}));
|
|
12
12
|
function env(key) {
|
|
13
13
|
return process.env[key];
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
return
|
|
15
|
+
function configDir() {
|
|
16
|
+
return env(EnvKey.HOME) || path.join(os.homedir(), '.envctl');
|
|
17
17
|
}
|
|
18
18
|
export class ConfigService {
|
|
19
19
|
config;
|
|
@@ -24,7 +24,7 @@ export class ConfigService {
|
|
|
24
24
|
throw new Error('load config second time?');
|
|
25
25
|
const customProfile = profile || env(EnvKey.PROFILE);
|
|
26
26
|
profile = customProfile || 'default';
|
|
27
|
-
const configPath = path.join(
|
|
27
|
+
const configPath = path.join(configDir(), `${profile}.json`);
|
|
28
28
|
if (fs.existsSync(configPath)) {
|
|
29
29
|
const data = fs.readFileSync(configPath, 'utf-8');
|
|
30
30
|
this.config = JSON.parse(data);
|
|
@@ -37,15 +37,15 @@ export class ConfigService {
|
|
|
37
37
|
saveConfig(profile, config) {
|
|
38
38
|
const mergedConfig = { ...this.loadConfig(profile, false), ...config };
|
|
39
39
|
const data = JSON.stringify(mergedConfig, null, 2);
|
|
40
|
-
fs.mkdirSync(
|
|
41
|
-
const configPath = path.join(
|
|
40
|
+
fs.mkdirSync(configDir(), { recursive: true });
|
|
41
|
+
const configPath = path.join(configDir(), `${profile}.json`);
|
|
42
42
|
fs.writeFileSync(configPath, data);
|
|
43
43
|
}
|
|
44
|
-
init(profile) {
|
|
44
|
+
init(profile = undefined) {
|
|
45
45
|
this.loadConfig(profile);
|
|
46
46
|
const apiKey = this.getApiKey();
|
|
47
47
|
if (!apiKey) {
|
|
48
|
-
if (
|
|
48
|
+
if (!!process.env['CI']) {
|
|
49
49
|
throw new KnownException('API key is missing, set env variable ' + EnvKey.API_KEY);
|
|
50
50
|
}
|
|
51
51
|
throw new KnownException('API key is missing, call \'envctl configure\' or set env variable ' + EnvKey.API_KEY);
|
|
@@ -27,10 +27,10 @@ export class EnvService extends BaseService {
|
|
|
27
27
|
if (env.status !== EnvStatus.Deleting && env.status !== EnvStatus.DeleteError) {
|
|
28
28
|
logger.info(`Expires at ${toLocalTime(env.ttl)}`);
|
|
29
29
|
}
|
|
30
|
-
if (env.
|
|
31
|
-
const
|
|
32
|
-
if (env.
|
|
33
|
-
logger.warn(`Env ${key}
|
|
30
|
+
if (env.dir) {
|
|
31
|
+
const dir = this.cli.getDir();
|
|
32
|
+
if (env.dir !== dir) {
|
|
33
|
+
logger.warn(`Env ${key} was deployed from ${env.dir}`);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -45,13 +45,13 @@ export class EnvService extends BaseService {
|
|
|
45
45
|
}
|
|
46
46
|
return env;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
checkDir(env) {
|
|
49
49
|
if (env.ephemeral)
|
|
50
50
|
return;
|
|
51
|
-
if (env.
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
throw new KnownException(`Env ${env.key}
|
|
51
|
+
if (env.dir) {
|
|
52
|
+
const dir = this.cli.getDir();
|
|
53
|
+
if (dir !== env.dir) {
|
|
54
|
+
throw new KnownException(`Env ${env.key} was deployed from ${env.dir} - make sure you run this command from the same directory`);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -59,7 +59,7 @@ export class EnvService extends BaseService {
|
|
|
59
59
|
const key = this.terraformAdapter.getTerraformBackend().getKey();
|
|
60
60
|
const env = await this.tryGetEnv(key);
|
|
61
61
|
if (env) {
|
|
62
|
-
this.
|
|
62
|
+
this.checkDir(env);
|
|
63
63
|
this.handleDeleteStatuses(env);
|
|
64
64
|
}
|
|
65
65
|
const newEnv = env === null;
|
|
@@ -116,9 +116,8 @@ export class EnvService extends BaseService {
|
|
|
116
116
|
const key = this.terraformAdapter.getTerraformBackend().getKey();
|
|
117
117
|
let env = await this.tryGetEnv(key);
|
|
118
118
|
if (env === null) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const createEnv = { key, kind };
|
|
119
|
+
const dir = this.cli.getDir();
|
|
120
|
+
const createEnv = { key, dir };
|
|
122
121
|
await this.lockTerraform(createEnv, true);
|
|
123
122
|
tfArgs = await this.ensurePlan({ key, ephemeral: false }, tfArgs);
|
|
124
123
|
logger.info('Creating env metadata');
|
|
@@ -126,7 +125,7 @@ export class EnvService extends BaseService {
|
|
|
126
125
|
await this.runApply(env, tfArgs);
|
|
127
126
|
return;
|
|
128
127
|
}
|
|
129
|
-
this.
|
|
128
|
+
this.checkDir(env);
|
|
130
129
|
this.handleDeleteStatuses(env);
|
|
131
130
|
const status = env.status;
|
|
132
131
|
if (status === EnvStatus.Deploying || status === EnvStatus.Updating) {
|