@agilecustoms/envctl 0.23.21 → 0.24.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/README.md +4 -2
- package/dist/commands/_keys.js +2 -3
- package/dist/commands/createEphemeral.js +2 -3
- package/dist/commands/delete.js +2 -3
- package/dist/commands/deploy.js +0 -1
- package/dist/commands/destroy.js +2 -3
- package/dist/commands/init.js +2 -3
- package/dist/commands/plan.js +0 -1
- package/dist/commands/status.js +2 -3
- package/dist/service/EnvCtl.js +15 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
## usage
|
|
7
7
|
|
|
8
8
|
```shell
|
|
9
|
-
|
|
9
|
+
terraform init -backend-config=key=laxa1986
|
|
10
|
+
# TODO: remove --env in next minor release
|
|
11
|
+
envctl deploy --env laxa1986 -var-file=versions.tfvars -var="log_level=debug"
|
|
10
12
|
```
|
|
11
13
|
|
|
12
14
|
## setup/update
|
|
@@ -50,7 +52,7 @@ Then as `/ci/deployer` --call--> `env-api` HTTP API (exposed with API Gateway wi
|
|
|
50
52
|
Now the problem is: any request needs to be signed with AWS signature v4. Originally I planned to use bash scripts, but it
|
|
51
53
|
quickly became bulky and hard to maintain. Then I thought about Node.js - it is available on dev machines and
|
|
52
54
|
in GitHub actions (namely in Ubuntu runners). How to distribute it? First I thought about using `ncc` to bundle in one
|
|
53
|
-
big .js file (as I do for `
|
|
55
|
+
big .js file (as I do for `publish-s3` and `gha-healthcheck`) but it will be hard to use on dev machine...
|
|
54
56
|
|
|
55
57
|
So I ended up publishing this client as an npm package in npmjs
|
|
56
58
|
- CI environments can install it via GH action `agilecustoms/envctl`
|
package/dist/commands/_keys.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export const _keys = {
|
|
2
2
|
CWD: 'Working directory (default: current directory)',
|
|
3
|
-
ENV: 'Environment name (can be git hash).
|
|
3
|
+
ENV: 'Environment name (can be git hash). = key used to store env state (s3 key in case of AWS)',
|
|
4
4
|
FORCE: 'Force deletion without confirmation',
|
|
5
5
|
KIND: 'Environment kind: complete project (default) or some slice such as tt-core + tt-web',
|
|
6
|
-
OWNER: 'Environment owner (GH username)'
|
|
7
|
-
PROJECT: 'Project code (like tt). Used when multiple projects deployed in same AWS account'
|
|
6
|
+
OWNER: 'Environment owner (GH username)'
|
|
8
7
|
};
|
|
@@ -6,13 +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
|
-
.option('--project <project>', _keys.PROJECT)
|
|
10
9
|
.requiredOption('--env <env>', _keys.ENV)
|
|
11
10
|
.option('--owner <owner>', _keys.OWNER)
|
|
12
11
|
.action(wrap(handler));
|
|
13
12
|
}
|
|
14
13
|
async function handler(options) {
|
|
15
|
-
const {
|
|
16
|
-
const token = await envCtl.createEphemeral(
|
|
14
|
+
const { env, owner } = options;
|
|
15
|
+
const token = await envCtl.createEphemeral(env, owner);
|
|
17
16
|
console.log(token);
|
|
18
17
|
}
|
package/dist/commands/delete.js
CHANGED
|
@@ -6,14 +6,13 @@ export function deleteIt(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('delete')
|
|
8
8
|
.description('Delete a development environment')
|
|
9
|
-
.option('--project <project>', _keys.PROJECT)
|
|
10
9
|
.option('--env <env>', _keys.ENV)
|
|
11
10
|
.option('--force', _keys.FORCE)
|
|
12
11
|
.option('--cwd <cwd>', _keys.CWD)
|
|
13
12
|
.action(wrap(handler));
|
|
14
13
|
}
|
|
15
14
|
async function handler(options) {
|
|
16
|
-
const {
|
|
15
|
+
const { env, force, cwd } = options;
|
|
17
16
|
const envName = cliHelper.ensureEnv(env);
|
|
18
|
-
await envCtl.delete(
|
|
17
|
+
await envCtl.delete(envName, Boolean(force), cwd);
|
|
19
18
|
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -6,7 +6,6 @@ export function deploy(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('deploy')
|
|
8
8
|
.description('Create new or update existing dev environment')
|
|
9
|
-
.option('--project <project>', _keys.PROJECT)
|
|
10
9
|
.option('--env <env>', _keys.ENV)
|
|
11
10
|
.option('--owner <owner>', _keys.OWNER)
|
|
12
11
|
.option('--kind <kind>', _keys.KIND)
|
package/dist/commands/destroy.js
CHANGED
|
@@ -8,7 +8,6 @@ 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('--project <project>', _keys.PROJECT)
|
|
12
11
|
.option('--env <env>', _keys.ENV)
|
|
13
12
|
.option('--force', _keys.FORCE)
|
|
14
13
|
.option('--cwd <cwd>', _keys.CWD)
|
|
@@ -17,7 +16,7 @@ export function destroy(program) {
|
|
|
17
16
|
.action(wrap(handler));
|
|
18
17
|
}
|
|
19
18
|
async function handler(tfArgs, options) {
|
|
20
|
-
const {
|
|
19
|
+
const { env, force, cwd } = options;
|
|
21
20
|
const envName = cliHelper.ensureEnv(env);
|
|
22
|
-
await envCtl.destroy(
|
|
21
|
+
await envCtl.destroy(envName, tfArgs, Boolean(force), cwd);
|
|
23
22
|
}
|
package/dist/commands/init.js
CHANGED
|
@@ -6,13 +6,12 @@ export function init(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('init')
|
|
8
8
|
.description('Terraform init wrapper')
|
|
9
|
-
.option('--project <project>', _keys.PROJECT)
|
|
10
9
|
.option('--env <env>', _keys.ENV)
|
|
11
10
|
.option('--cwd <cwd>', _keys.CWD)
|
|
12
11
|
.action(wrap(handler));
|
|
13
12
|
}
|
|
14
13
|
async function handler(options) {
|
|
15
|
-
const {
|
|
14
|
+
const { env, cwd } = options;
|
|
16
15
|
const envName = cliHelper.ensureEnv(env);
|
|
17
|
-
await envCtl.init(
|
|
16
|
+
await envCtl.init(envName, cwd);
|
|
18
17
|
}
|
package/dist/commands/plan.js
CHANGED
|
@@ -7,7 +7,6 @@ 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('--project <project>', _keys.PROJECT)
|
|
11
10
|
.option('--env <env>', _keys.ENV)
|
|
12
11
|
.option('--owner <owner>', _keys.OWNER)
|
|
13
12
|
.option('--cwd <cwd>', _keys.CWD)
|
package/dist/commands/status.js
CHANGED
|
@@ -6,13 +6,12 @@ export function status(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('status')
|
|
8
8
|
.description('Get env status')
|
|
9
|
-
.option('--project <project>', _keys.PROJECT)
|
|
10
9
|
.option('--env <env>', _keys.ENV)
|
|
11
10
|
.option('--cwd <cwd>', _keys.CWD)
|
|
12
11
|
.action(wrap(handler));
|
|
13
12
|
}
|
|
14
13
|
async function handler(options) {
|
|
15
|
-
const {
|
|
14
|
+
const { env, cwd } = options;
|
|
16
15
|
const envName = cliHelper.ensureEnv(env);
|
|
17
|
-
await envCtl.status(
|
|
16
|
+
await envCtl.status(envName, cwd);
|
|
18
17
|
}
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -9,11 +9,11 @@ export class EnvCtl {
|
|
|
9
9
|
this.envApi = envApi;
|
|
10
10
|
this.terraformAdapter = terraformAdapter;
|
|
11
11
|
}
|
|
12
|
-
key(
|
|
13
|
-
return
|
|
12
|
+
key(env) {
|
|
13
|
+
return env;
|
|
14
14
|
}
|
|
15
|
-
async status(
|
|
16
|
-
const key = this.key(
|
|
15
|
+
async status(envName, cwd) {
|
|
16
|
+
const key = this.key(envName);
|
|
17
17
|
console.log(`Retrieve env ${key}`);
|
|
18
18
|
const env = await this.envApi.get(key);
|
|
19
19
|
if (env === null) {
|
|
@@ -34,7 +34,7 @@ export class EnvCtl {
|
|
|
34
34
|
console.log(`Env name not provided, default to owner name ${owner}`);
|
|
35
35
|
envName = owner;
|
|
36
36
|
}
|
|
37
|
-
const key = this.key(
|
|
37
|
+
const key = this.key(envName);
|
|
38
38
|
console.log(`Check if env ${key} already exists`);
|
|
39
39
|
const env = await this.envApi.get(key);
|
|
40
40
|
if (env) {
|
|
@@ -63,8 +63,8 @@ export class EnvCtl {
|
|
|
63
63
|
}
|
|
64
64
|
throw new KnownException(`Env ${env.key} status is ${env.status}, can not run this command`);
|
|
65
65
|
}
|
|
66
|
-
async init(
|
|
67
|
-
const key = this.key(
|
|
66
|
+
async init(envName, cwd) {
|
|
67
|
+
const key = this.key(envName);
|
|
68
68
|
await this.terraformAdapter.init(key, cwd, true);
|
|
69
69
|
}
|
|
70
70
|
async plan(input, tfArgs, cwd) {
|
|
@@ -88,8 +88,8 @@ export class EnvCtl {
|
|
|
88
88
|
await this.terraformAdapter.init(key, cwd);
|
|
89
89
|
await this.terraformAdapter.plan(envTerraform, cwd);
|
|
90
90
|
}
|
|
91
|
-
async createEphemeral(
|
|
92
|
-
const key = this.key(
|
|
91
|
+
async createEphemeral(envName, owner) {
|
|
92
|
+
const key = this.key(envName);
|
|
93
93
|
const env = await this.envApi.get(key);
|
|
94
94
|
if (env !== null) {
|
|
95
95
|
throw new KnownException(`Env ${key} already exists`);
|
|
@@ -146,8 +146,8 @@ export class EnvCtl {
|
|
|
146
146
|
console.log('Activating env (to finish creation)');
|
|
147
147
|
await this.envApi.activate(env);
|
|
148
148
|
}
|
|
149
|
-
async delete(
|
|
150
|
-
const env = await this.get(
|
|
149
|
+
async delete(envName, force, cwd) {
|
|
150
|
+
const env = await this.get(envName);
|
|
151
151
|
if (!force) {
|
|
152
152
|
this.checkStatus(env);
|
|
153
153
|
if (env.status === EnvStatus.Init) {
|
|
@@ -174,8 +174,8 @@ export class EnvCtl {
|
|
|
174
174
|
const message = await this.envApi.delete(env);
|
|
175
175
|
console.log(message);
|
|
176
176
|
}
|
|
177
|
-
async destroy(
|
|
178
|
-
const env = await this.get(
|
|
177
|
+
async destroy(envName, tfArgs, force, cwd) {
|
|
178
|
+
const env = await this.get(envName);
|
|
179
179
|
this.checkStatus(env);
|
|
180
180
|
if (env.status === EnvStatus.Init) {
|
|
181
181
|
console.log(`Env ${env.key} has no resources, nothing to destroy, call 'delete' command instead`);
|
|
@@ -206,8 +206,8 @@ export class EnvCtl {
|
|
|
206
206
|
await this.envApi.delete(env);
|
|
207
207
|
console.log('Please wait for ~15 sec before you can create env with same name');
|
|
208
208
|
}
|
|
209
|
-
async get(
|
|
210
|
-
const key = this.key(
|
|
209
|
+
async get(envName) {
|
|
210
|
+
const key = this.key(envName);
|
|
211
211
|
console.log(`Retrieve env ${key}`);
|
|
212
212
|
const env = await this.envApi.get(key);
|
|
213
213
|
if (!env) {
|