@agilecustoms/envctl 0.16.1 → 0.18.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.
@@ -4,11 +4,13 @@ import { KnownException } from '../exceptions.js';
4
4
  export class AwsCredsHelper {
5
5
  creds;
6
6
  async ensureCredentials() {
7
- await this.getCredentials();
7
+ await this.getCredentials(true);
8
8
  }
9
- async getCredentials() {
9
+ async getCredentials(printLogs = false) {
10
10
  if (!this.creds) {
11
- console.log('Fetching AWS credentials...');
11
+ if (printLogs) {
12
+ console.log('Fetching AWS credentials...');
13
+ }
12
14
  this.creds = await this._getCredentials();
13
15
  }
14
16
  return this.creds;
@@ -0,0 +1,20 @@
1
+ import { Command } from 'commander';
2
+ import { envCtl } from '../container.js';
3
+ import { _keys } from './_keys.js';
4
+ import { wrap } from './_utils.js';
5
+ export function apiCreateEphemeral(program) {
6
+ program
7
+ .command('api-create-ephemeral')
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
+ .requiredOption('--env <env>', _keys.ENV)
11
+ .requiredOption('--owner <owner>', _keys.OWNER)
12
+ .requiredOption('--size <size>', _keys.SIZE)
13
+ .requiredOption('--type <type>', _keys.TYPE)
14
+ .action(wrap(handler));
15
+ }
16
+ async function handler(options) {
17
+ const { project, env, owner, size, type } = options;
18
+ const token = await envCtl.createEphemeral(project, env, owner, size, type);
19
+ console.log(token);
20
+ }
@@ -1,6 +1,8 @@
1
+ export { apiCreateEphemeral } from './apiCreateEphemeral.js';
1
2
  export { configure } from './configure.js';
2
3
  export { deleteIt } from './delete.js';
3
4
  export { deploy } from './deploy.js';
4
5
  export { destroy } from './destroy.js';
6
+ export { init } from './init.js';
5
7
  export { plan } from './plan.js';
6
8
  export { status } from './status.js';
@@ -0,0 +1,18 @@
1
+ import { Command } from 'commander';
2
+ import { cliHelper, envCtl } from '../container.js';
3
+ import { _keys } from './_keys.js';
4
+ import { wrap } from './_utils.js';
5
+ export function init(program) {
6
+ program
7
+ .command('init')
8
+ .description('Terraform init wrapper')
9
+ .option('--project <project>', _keys.PROJECT)
10
+ .option('--env <env>', _keys.ENV)
11
+ .option('--cwd <cwd>', _keys.CWD)
12
+ .action(wrap(handler));
13
+ }
14
+ async function handler(options) {
15
+ const { project, env, cwd } = options;
16
+ const envName = cliHelper.ensureEnv(env);
17
+ await envCtl.init(project, envName, cwd);
18
+ }
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, destroy, plan, status } from './commands/index.js';
5
+ import { apiCreateEphemeral, configure, deleteIt, deploy, destroy, init, 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();
@@ -11,10 +11,12 @@ program
11
11
  .name('envctl')
12
12
  .description('CLI to manage environments')
13
13
  .version(pkg.version);
14
+ apiCreateEphemeral(program);
14
15
  configure(program);
15
16
  deleteIt(program);
16
17
  deploy(program);
17
18
  destroy(program);
19
+ init(program);
18
20
  plan(program);
19
21
  status(program);
20
22
  program.parse(process.argv);
@@ -1,4 +1,5 @@
1
1
  import { KnownException, TerraformInitRequired } from '../exceptions.js';
2
+ import { EnvType, EnvSize } from '../model/index.js';
2
3
  import { EnvSizeAvgTime, EnvStatus } from '../model/index.js';
3
4
  export class EnvCtl {
4
5
  cliHelper;
@@ -78,6 +79,10 @@ export class EnvCtl {
78
79
  }
79
80
  throw new KnownException(`Env status is ${env.status}, can not run this command`);
80
81
  }
82
+ async init(project, envName, cwd) {
83
+ const key = this.key(project, envName);
84
+ await this.terraformAdapter.init(key, cwd);
85
+ }
81
86
  async plan(input, tfArgs, cwd) {
82
87
  const { envName, owner, key, env } = await this.tryGetEnv(input);
83
88
  if (env == null) {
@@ -94,6 +99,16 @@ export class EnvCtl {
94
99
  }
95
100
  await this.terraformAdapter.plan(envInput, tfArgs, cwd);
96
101
  }
102
+ async createEphemeral(project, envName, owner, size, type) {
103
+ const key = this.key(project, envName);
104
+ const env = await this.envApi.get(key);
105
+ if (env !== null) {
106
+ throw new KnownException(`Env ${key} already exists`);
107
+ }
108
+ const createEnv = { key, ephemeral: true, owner, size, type };
109
+ const newEnv = await this.envApi.create(createEnv);
110
+ return newEnv.token;
111
+ }
97
112
  async deploy(input, tfArgs, cwd) {
98
113
  const { envName, owner, key, env } = await this.tryGetEnv(input);
99
114
  if (env === null) {
@@ -138,10 +153,6 @@ export class EnvCtl {
138
153
  }
139
154
  console.log('Activating env (to finish creation)');
140
155
  await this.envApi.activate(env);
141
- console.log('Lock env to run db evolution');
142
- await this.envApi.lockForUpdate(env);
143
- console.log('Unlock env after db evolution');
144
- await this.envApi.activate(env);
145
156
  }
146
157
  async delete(project, envName, cwd) {
147
158
  const env = await this.get(project, envName);
@@ -158,7 +169,7 @@ export class EnvCtl {
158
169
  }
159
170
  await this.promptUnlock(env);
160
171
  if (env.status !== EnvStatus.Active) {
161
- throw new KnownException(`Env ${env.key} status is ${env.status}, can not delete`);
172
+ return;
162
173
  }
163
174
  console.log('Deleting env');
164
175
  const statusMessage = await this.envApi.delete(env);
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.16.1",
4
+ "version": "0.18.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {
@@ -28,10 +28,12 @@
28
28
  "run-version": "tsc --sourceMap true && npm run run -- --version",
29
29
  "run-configure": "tsc --sourceMap true && npm run run -- configure",
30
30
  "run-status": "tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
31
+ "run-init": "tsc --sourceMap true && npm run run -- init --cwd ../tt-core",
31
32
  "run-plan": "tsc --sourceMap true && npm run run -- plan --size min --cwd ../tt-core",
32
33
  "run-deploy": "tsc --sourceMap true && npm run run -- deploy --size min --cwd ../tt-core",
33
34
  "run-delete": "tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
34
- "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core"
35
+ "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
36
+ "run-api-create-ephemeral": "tsc --sourceMap true && npm run run -- api-create-ephemeral --env laxa1986 --owner laxa1986 --size min --type dev"
35
37
  },
36
38
  "dependencies": {
37
39
  "@aws-sdk/client-sts": "^3.716.0",