@brunwig/mup-aws-beanstalk 0.8.3 → 0.8.5

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.
@@ -3,58 +3,41 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setup = setup;
6
+ exports.clean = clean;
7
+ exports.debug = debug;
7
8
  exports.deploy = deploy;
9
+ exports.events = events;
8
10
  exports.logs = logs;
9
- exports.logsNginx = logsNginx;
10
11
  exports.logsEb = logsEb;
11
- exports.start = start;
12
- exports.stop = stop;
13
- exports.restart = restart;
14
- exports.clean = clean;
12
+ exports.logsNginx = logsNginx;
15
13
  exports.reconfig = reconfig;
16
- exports.events = events;
17
- exports.status = status;
18
- exports.ssl = ssl;
14
+ exports.restart = restart;
15
+ exports.setup = setup;
19
16
  exports.shell = shell;
20
- exports.debug = debug;
21
-
17
+ exports.ssl = ssl;
18
+ exports.start = start;
19
+ exports.status = status;
20
+ exports.stop = stop;
22
21
  var _chalk = _interopRequireDefault(require("chalk"));
23
-
24
22
  var _ssh = require("ssh2");
25
-
26
23
  var _aws = require("./aws");
27
-
28
24
  var _certificates = _interopRequireDefault(require("./certificates"));
29
-
30
25
  var _policies = require("./policies");
31
-
32
26
  var _upload = _interopRequireWildcard(require("./upload"));
33
-
34
27
  var _prepareBundle = require("./prepare-bundle");
35
-
36
28
  var _utils = require("./utils");
37
-
38
29
  var _versions = require("./versions");
39
-
40
30
  var _envSettings = require("./env-settings");
41
-
42
31
  var _ebConfig = require("./eb-config");
43
-
44
32
  var _envReady = require("./env-ready");
45
-
46
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
47
-
48
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
49
-
50
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
-
52
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
53
-
54
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
55
-
56
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
57
-
33
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
34
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
35
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
36
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
37
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
38
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
39
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
40
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
58
41
  async function setup(api) {
59
42
  const config = api.getConfig();
60
43
  const appConfig = config.app;
@@ -73,27 +56,27 @@ async function setup(api) {
73
56
  automationDocument
74
57
  } = (0, _utils.names)(config);
75
58
  (0, _utils.logStep)('=> @Brunwig/mup-aws-beanstalk');
76
- (0, _utils.logStep)('=> Setting up'); // Create bucket if needed
59
+ (0, _utils.logStep)('=> Setting up');
77
60
 
61
+ // Create bucket if needed
78
62
  const {
79
63
  Buckets
80
64
  } = await _aws.s3.listBuckets().promise();
81
65
  const beanstalkBucketCreated = await (0, _utils.ensureBucketExists)(Buckets, bucketName, appConfig.region);
82
-
83
66
  if (beanstalkBucketCreated) {
84
67
  console.log(' Created Bucket');
85
68
  }
69
+ (0, _utils.logStep)('=> Ensuring IAM Roles and Instance Profiles are setup');
86
70
 
87
- (0, _utils.logStep)('=> Ensuring IAM Roles and Instance Profiles are setup'); // Create role and instance profile
88
-
71
+ // Create role and instance profile
89
72
  await (0, _utils.ensureRoleExists)(instanceProfile, _policies.rolePolicy);
90
73
  await (0, _utils.ensureInstanceProfileExists)(config, instanceProfile);
91
74
  await (0, _utils.ensurePoliciesAttached)(config, instanceProfile, ['arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier', 'arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker', 'arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier', ...(appConfig.gracefulShutdown ? ['arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM'] : [])]);
92
- await (0, _utils.ensureRoleAdded)(config, instanceProfile, instanceProfile); // Create role used by enhanced health
75
+ await (0, _utils.ensureRoleAdded)(config, instanceProfile, instanceProfile);
93
76
 
77
+ // Create role used by enhanced health
94
78
  await (0, _utils.ensureRoleExists)(serviceRoleName, _policies.serviceRole);
95
79
  await (0, _utils.ensurePoliciesAttached)(config, serviceRoleName, ['arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth', 'arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkService']);
96
-
97
80
  if (appConfig.gracefulShutdown) {
98
81
  const accountId = await (0, _utils.getAccountId)();
99
82
  const policy = (0, _policies.eventTargetRolePolicy)(accountId, environmentName, appConfig.region || 'us-east-1');
@@ -101,13 +84,12 @@ async function setup(api) {
101
84
  await (0, _utils.ensureRoleExists)(eventTargetRoleName, _policies.eventTargetRole, true);
102
85
  await (0, _utils.ensureInlinePolicyAttached)(eventTargetRoleName, eventTargetPolicyName, policy);
103
86
  await (0, _utils.ensureInlinePolicyAttached)(eventTargetRoleName, eventTargetPassRoleName, passPolicy);
104
- } // Create beanstalk application if needed
105
-
87
+ }
106
88
 
89
+ // Create beanstalk application if needed
107
90
  const {
108
91
  Applications
109
92
  } = await _aws.beanstalk.describeApplications().promise();
110
-
111
93
  if (!Applications.find(app => app.ApplicationName === appName)) {
112
94
  const params = {
113
95
  ApplicationName: appName,
@@ -116,7 +98,6 @@ async function setup(api) {
116
98
  await _aws.beanstalk.createApplication(params).promise();
117
99
  console.log(' Created Beanstalk application');
118
100
  }
119
-
120
101
  if (appConfig.gracefulShutdown) {
121
102
  (0, _utils.logStep)('=> Ensuring Graceful Shutdown is setup');
122
103
  const existingBucket = (0, _utils.findBucketWithPrefix)(Buckets, trailBucketPrefix);
@@ -126,18 +107,15 @@ async function setup(api) {
126
107
  const policy = (0, _policies.trailBucketPolicy)(accountId, trailBucketName);
127
108
  const trailBucketCreated = await (0, _utils.ensureBucketExists)(Buckets, trailBucketName, appConfig.region);
128
109
  await (0, _utils.ensureBucketPolicyAttached)(trailBucketName, policy);
129
-
130
110
  if (trailBucketCreated) {
131
111
  console.log(' Created bucket for Cloud Trail');
132
112
  }
133
-
134
113
  const params = {
135
114
  trailNameList: [trailName]
136
115
  };
137
116
  const {
138
117
  trailList
139
118
  } = await _aws.cloudTrail.describeTrails(params).promise();
140
-
141
119
  if (trailList.length === 0) {
142
120
  const createParams = {
143
121
  Name: trailName,
@@ -146,28 +124,21 @@ async function setup(api) {
146
124
  await _aws.cloudTrail.createTrail(createParams).promise();
147
125
  console.log(' Created CloudTrail trail');
148
126
  }
149
-
150
127
  const createdDocument = await (0, _utils.ensureSsmDocument)(automationDocument, (0, _policies.gracefulShutdownAutomationDocument)());
151
-
152
128
  if (createdDocument) {
153
129
  console.log(' Created SSM Automation Document');
154
130
  }
155
-
156
131
  const createdRule = await (0, _utils.ensureCloudWatchRule)(deregisterRuleName, 'Used by Meteor Up for graceful shutdown', _policies.DeregisterEvent);
157
-
158
132
  if (createdRule) {
159
133
  console.log(' Created Cloud Watch rule');
160
134
  }
161
-
162
135
  const target = (0, _policies.deregisterEventTarget)(environmentName, eventTargetRoleName, accountId, region);
163
136
  const createdTarget = await (0, _utils.ensureRuleTargetExists)(deregisterRuleName, target, accountId);
164
-
165
137
  if (createdTarget) {
166
138
  console.log(' Created target for Cloud Watch rule');
167
139
  }
168
140
  }
169
141
  }
170
-
171
142
  async function deploy(api) {
172
143
  await api.runCommand('beanstalk.setup');
173
144
  const config = api.getConfig();
@@ -178,18 +149,17 @@ async function deploy(api) {
178
149
  environment
179
150
  } = (0, _utils.names)(config);
180
151
  const version = await (0, _versions.largestVersion)(api);
181
- const nextVersion = version + 1; // Mutates the config, so the meteor.build command will have the correct build location
152
+ const nextVersion = version + 1;
182
153
 
154
+ // Mutates the config, so the meteor.build command will have the correct build location
183
155
  config.app.buildOptions.buildLocation = config.app.buildOptions.buildLocation || (0, _utils.tmpBuildPath)(config.app.path, api);
184
156
  const bundlePath = api.resolvePath(config.app.buildOptions.buildLocation, 'bundle.zip');
185
157
  const willBuild = (0, _utils.shouldRebuild)(bundlePath, api.getOptions()['cached-build']);
186
-
187
158
  if (willBuild) {
188
159
  await api.runCommand('meteor.build');
189
160
  (0, _prepareBundle.injectFiles)(api, app, nextVersion, config.app);
190
161
  await (0, _prepareBundle.archiveApp)(config.app.buildOptions.buildLocation, api);
191
162
  }
192
-
193
163
  (0, _utils.logStep)('=> Uploading bundle');
194
164
  const key = `${bundlePrefix}${nextVersion}`;
195
165
  await (0, _upload.default)(config.app, bucket, `${bundlePrefix}${nextVersion}`, bundlePath);
@@ -210,7 +180,6 @@ async function deploy(api) {
210
180
  toRemove,
211
181
  toUpdate
212
182
  } = await (0, _ebConfig.prepareUpdateEnvironment)(api);
213
-
214
183
  if (api.verbose) {
215
184
  console.log('EB Config changes:');
216
185
  console.dir({
@@ -218,7 +187,6 @@ async function deploy(api) {
218
187
  toUpdate
219
188
  });
220
189
  }
221
-
222
190
  await _aws.beanstalk.updateEnvironment({
223
191
  EnvironmentName: environment,
224
192
  VersionLabel: nextVersion.toString(),
@@ -233,15 +201,15 @@ async function deploy(api) {
233
201
  EnvironmentNames: [environment]
234
202
  }).promise();
235
203
  await api.runCommand('beanstalk.clean');
236
- await api.runCommand('beanstalk.ssl'); // Check if deploy succeeded
204
+ await api.runCommand('beanstalk.ssl');
237
205
 
206
+ // Check if deploy succeeded
238
207
  const {
239
208
  Environments: finalEnvironments
240
209
  } = await _aws.beanstalk.describeEnvironments({
241
210
  ApplicationName: app,
242
211
  EnvironmentNames: [environment]
243
212
  }).promise();
244
-
245
213
  if (nextVersion.toString() === finalEnvironments[0].VersionLabel) {
246
214
  console.log(_chalk.default.green(`App is running at ${Environments[0].CNAME}`));
247
215
  } else {
@@ -249,7 +217,6 @@ async function deploy(api) {
249
217
  process.exitCode = 1;
250
218
  }
251
219
  }
252
-
253
220
  async function logs(api) {
254
221
  const logsContent = await (0, _utils.getLogs)(api, ['web.stdout.log', 'nodejs/nodejs.log']);
255
222
  logsContent.forEach(({
@@ -259,7 +226,6 @@ async function logs(api) {
259
226
  console.log(`${instance} `, data[0] || data[1]);
260
227
  });
261
228
  }
262
-
263
229
  async function logsNginx(api) {
264
230
  const logsContent = await (0, _utils.getLogs)(api, ['nginx/error.log', 'nginx/access.log']);
265
231
  logsContent.forEach(({
@@ -270,7 +236,6 @@ async function logsNginx(api) {
270
236
  console.log(`${instance} `, data[1]);
271
237
  });
272
238
  }
273
-
274
239
  async function logsEb(api) {
275
240
  const logsContent = await (0, _utils.getLogs)(api, ['eb-engine.log', 'eb-activity.log']);
276
241
  logsContent.forEach(({
@@ -280,7 +245,6 @@ async function logsEb(api) {
280
245
  console.log(`${instance} `, data[0] || data[1]);
281
246
  });
282
247
  }
283
-
284
248
  async function start(api) {
285
249
  const config = api.getConfig();
286
250
  const {
@@ -305,7 +269,6 @@ async function start(api) {
305
269
  }).promise();
306
270
  await (0, _envReady.waitForHealth)(config);
307
271
  }
308
-
309
272
  async function stop(api) {
310
273
  const config = api.getConfig();
311
274
  const {
@@ -326,7 +289,6 @@ async function stop(api) {
326
289
  }).promise();
327
290
  await (0, _envReady.waitForHealth)(config, 'Grey');
328
291
  }
329
-
330
292
  async function restart(api) {
331
293
  const config = api.getConfig();
332
294
  const {
@@ -338,7 +300,6 @@ async function restart(api) {
338
300
  }).promise();
339
301
  await (0, _envReady.waitForEnvReady)(config, false);
340
302
  }
341
-
342
303
  async function clean(api) {
343
304
  const config = api.getConfig();
344
305
  const {
@@ -352,7 +313,6 @@ async function clean(api) {
352
313
  const envVersions = await (0, _versions.oldEnvVersions)(api);
353
314
  (0, _utils.logStep)('=> Removing old versions');
354
315
  const promises = [];
355
-
356
316
  for (let i = 0; i < versions.length; i++) {
357
317
  promises.push(_aws.beanstalk.deleteApplicationVersion({
358
318
  ApplicationName: app,
@@ -360,18 +320,17 @@ async function clean(api) {
360
320
  DeleteSourceBundle: true
361
321
  }).promise());
362
322
  }
363
-
364
323
  for (let i = 0; i < envVersions.length; i++) {
365
324
  promises.push(_aws.s3.deleteObject({
366
325
  Bucket: bucket,
367
326
  Key: `env/${envVersions[i]}.txt`
368
327
  }).promise());
369
- } // TODO: remove bundles
328
+ }
370
329
 
330
+ // TODO: remove bundles
371
331
 
372
332
  await Promise.all(promises);
373
333
  }
374
-
375
334
  async function reconfig(api) {
376
335
  const config = api.getConfig();
377
336
  const {
@@ -380,24 +339,23 @@ async function reconfig(api) {
380
339
  bucket
381
340
  } = (0, _utils.names)(config);
382
341
  const deploying = !!api.commandHistory.find(entry => entry.name === 'beanstalk.deploy');
383
- (0, _utils.logStep)('=> Configuring Beanstalk environment'); // check if env exists
342
+ (0, _utils.logStep)('=> @Brunwig/mup-aws-beanstalk');
343
+ (0, _utils.logStep)('=> Configuring Beanstalk environment');
384
344
 
345
+ // check if env exists
385
346
  const {
386
347
  Environments
387
348
  } = await _aws.beanstalk.describeEnvironments({
388
349
  ApplicationName: app,
389
350
  EnvironmentNames: [environment]
390
351
  }).promise();
391
-
392
352
  if (!Environments.find(env => env.Status !== 'Terminated')) {
393
353
  const desiredEbConfig = (0, _ebConfig.createDesiredConfig)(api.getConfig(), api.getSettings(), config.app.longEnvVars ? 1 : false);
394
-
395
354
  if (config.app.longEnvVars) {
396
355
  const envContent = (0, _envSettings.createEnvFile)(config.app.env, api.getSettings());
397
356
  await (0, _upload.uploadEnvFile)(bucket, 1, envContent);
398
357
  }
399
-
400
- const platformArn = await (0, _utils.selectPlatformArn)(api.getConfig().awsPlatformBranchName);
358
+ const platformArn = await (0, _utils.selectPlatformArn)(api.getConfig().app.awsPlatformBranchName);
401
359
  const [version] = await (0, _versions.ebVersions)(api);
402
360
  await _aws.beanstalk.createEnvironment({
403
361
  ApplicationName: app,
@@ -416,7 +374,6 @@ async function reconfig(api) {
416
374
  toRemove,
417
375
  toUpdate
418
376
  } = await (0, _ebConfig.prepareUpdateEnvironment)(api);
419
-
420
377
  if (api.verbose) {
421
378
  console.log('EB Config changes:');
422
379
  console.dir({
@@ -424,7 +381,6 @@ async function reconfig(api) {
424
381
  toUpdate
425
382
  });
426
383
  }
427
-
428
384
  if (toRemove.length > 0 || toUpdate.length > 0) {
429
385
  await (0, _envReady.waitForEnvReady)(config, true);
430
386
  await _aws.beanstalk.updateEnvironment({
@@ -436,14 +392,12 @@ async function reconfig(api) {
436
392
  await (0, _envReady.waitForEnvReady)(config, true);
437
393
  }
438
394
  }
439
-
440
395
  const {
441
396
  ConfigurationSettings
442
397
  } = await _aws.beanstalk.describeConfigurationSettings({
443
398
  EnvironmentName: environment,
444
399
  ApplicationName: app
445
400
  }).promise();
446
-
447
401
  if ((0, _ebConfig.scalingConfigChanged)(ConfigurationSettings[0].OptionSettings, config)) {
448
402
  (0, _utils.logStep)('=> Configuring scaling');
449
403
  await _aws.beanstalk.updateEnvironment({
@@ -453,7 +407,6 @@ async function reconfig(api) {
453
407
  await (0, _envReady.waitForEnvReady)(config, true);
454
408
  }
455
409
  }
456
-
457
410
  async function events(api) {
458
411
  const {
459
412
  environment
@@ -465,13 +418,11 @@ async function events(api) {
465
418
  }).promise();
466
419
  console.log(envEvents.map(ev => `${ev.EventDate}: ${ev.Message}`).join('\n'));
467
420
  }
468
-
469
421
  async function status(api) {
470
422
  const {
471
423
  environment
472
424
  } = (0, _utils.names)(api.getConfig());
473
425
  let result;
474
-
475
426
  try {
476
427
  result = await _aws.beanstalk.describeEnvironmentHealth({
477
428
  AttributeNames: ['All'],
@@ -482,10 +433,8 @@ async function status(api) {
482
433
  console.log(' AWS Beanstalk environment does not exist');
483
434
  return;
484
435
  }
485
-
486
436
  throw e;
487
437
  }
488
-
489
438
  const {
490
439
  InstanceHealthList
491
440
  } = await _aws.beanstalk.describeInstancesHealth({
@@ -500,16 +449,13 @@ async function status(api) {
500
449
  } = result.ApplicationMetrics;
501
450
  console.log(`Environment Status: ${result.Status}`);
502
451
  console.log(`Health Status: ${(0, _utils.coloredStatusText)(result.Color, result.HealthStatus)}`);
503
-
504
452
  if (result.Causes.length > 0) {
505
453
  console.log('Causes: ');
506
454
  result.Causes.forEach(cause => console.log(` ${cause}`));
507
455
  }
508
-
509
456
  console.log('');
510
457
  console.log(`=== Metrics For Last ${Duration || 'Unknown'} Minutes ===`);
511
458
  console.log(` Requests: ${RequestCount}`);
512
-
513
459
  if (StatusCodes) {
514
460
  console.log(' Status Codes');
515
461
  console.log(` 2xx: ${StatusCodes.Status2xx}`);
@@ -517,7 +463,6 @@ async function status(api) {
517
463
  console.log(` 4xx: ${StatusCodes.Status4xx}`);
518
464
  console.log(` 5xx: ${StatusCodes.Status5xx}`);
519
465
  }
520
-
521
466
  if (Latency) {
522
467
  console.log(' Latency');
523
468
  console.log(` 99.9%: ${Latency.P999}`);
@@ -529,41 +474,34 @@ async function status(api) {
529
474
  console.log(` 50% : ${Latency.P50}`);
530
475
  console.log(` 10% : ${Latency.P10}`);
531
476
  }
532
-
533
477
  console.log('');
534
478
  console.log('=== Instances ===');
535
479
  InstanceHealthList.forEach(instance => {
536
480
  console.log(` ${instance.InstanceId}: ${(0, _utils.coloredStatusText)(instance.Color, instance.HealthStatus)}`);
537
481
  });
538
-
539
482
  if (InstanceHealthList.length === 0) {
540
483
  console.log(' 0 Instances');
541
484
  }
542
485
  }
543
-
544
486
  async function ssl(api) {
545
487
  const config = api.getConfig();
546
488
  await (0, _envReady.waitForEnvReady)(config, true);
547
-
548
489
  if (!config.app || !config.app.sslDomains) {
549
490
  (0, _utils.logStep)('=> Updating Beanstalk SSL Config');
550
491
  await (0, _certificates.default)(config);
551
492
  return;
552
493
  }
553
-
554
494
  (0, _utils.logStep)('=> Checking Certificate Status');
555
495
  const domains = config.app.sslDomains;
556
496
  const {
557
497
  CertificateSummaryList
558
498
  } = await _aws.acm.listCertificates().promise();
559
499
  let found = null;
560
-
561
500
  for (let i = 0; i < CertificateSummaryList.length; i++) {
562
501
  const {
563
502
  DomainName,
564
503
  CertificateArn
565
504
  } = CertificateSummaryList[i];
566
-
567
505
  if (DomainName === domains[0]) {
568
506
  const {
569
507
  Certificate
@@ -571,15 +509,12 @@ async function ssl(api) {
571
509
  // eslint-disable-line no-await-in-loop
572
510
  CertificateArn
573
511
  }).promise();
574
-
575
512
  if (domains.join(',') === Certificate.SubjectAlternativeNames.join(',')) {
576
513
  found = CertificateSummaryList[i];
577
514
  }
578
515
  }
579
516
  }
580
-
581
517
  let certificateArn;
582
-
583
518
  if (!found) {
584
519
  (0, _utils.logStep)('=> Requesting Certificate');
585
520
  const result = await _aws.acm.requestCertificate({
@@ -588,16 +523,14 @@ async function ssl(api) {
588
523
  }).promise();
589
524
  certificateArn = result.CertificateArn;
590
525
  }
591
-
592
526
  if (found) {
593
527
  certificateArn = found.CertificateArn;
594
528
  }
595
-
596
529
  let emailsProvided = false;
597
530
  let checks = 0;
598
531
  let certificate;
599
- /* eslint-disable no-await-in-loop */
600
532
 
533
+ /* eslint-disable no-await-in-loop */
601
534
  while (!emailsProvided && checks < 5) {
602
535
  const {
603
536
  Certificate
@@ -605,7 +538,6 @@ async function ssl(api) {
605
538
  CertificateArn: certificateArn
606
539
  }).promise();
607
540
  const validationOptions = Certificate.DomainValidationOptions[0];
608
-
609
541
  if (typeof validationOptions.ValidationEmails === 'undefined') {
610
542
  emailsProvided = true;
611
543
  certificate = Certificate;
@@ -619,7 +551,6 @@ async function ssl(api) {
619
551
  });
620
552
  }
621
553
  }
622
-
623
554
  if (certificate.Status === 'PENDING_VALIDATION') {
624
555
  console.log('Certificate is pending validation.');
625
556
  certificate.DomainValidationOptions.forEach(({
@@ -632,16 +563,13 @@ async function ssl(api) {
632
563
  console.log(_chalk.default.green(`${ValidationDomain || DomainName} has been verified`));
633
564
  return;
634
565
  }
635
-
636
566
  console.log(_chalk.default.yellow(`${ValidationDomain || DomainName} is pending validation`));
637
-
638
567
  if (ValidationEmails) {
639
568
  console.log('Emails with instructions have been sent to:');
640
569
  ValidationEmails.forEach(email => {
641
570
  console.log(` ${email}`);
642
571
  });
643
572
  }
644
-
645
573
  console.log('Run "mup beanstalk ssl" after you have verified the domains, or to check the verification status');
646
574
  });
647
575
  } else if (certificate.Status === 'ISSUED') {
@@ -650,20 +578,17 @@ async function ssl(api) {
650
578
  await (0, _certificates.default)(config, certificateArn);
651
579
  }
652
580
  }
653
-
654
581
  async function shell(api) {
655
582
  const {
656
583
  selected,
657
584
  description
658
585
  } = await (0, _utils.pickInstance)(api.getConfig(), api.getArgs()[2]);
659
-
660
586
  if (!selected) {
661
587
  console.log(description);
662
588
  console.log('Run "mup beanstalk shell <instance id>"');
663
589
  process.exitCode = 1;
664
590
  return;
665
591
  }
666
-
667
592
  const {
668
593
  sshOptions,
669
594
  removeSSHAccess
@@ -676,7 +601,6 @@ async function shell(api) {
676
601
  if (err) {
677
602
  throw err;
678
603
  }
679
-
680
604
  stream.on('close', async () => {
681
605
  conn.end();
682
606
  await removeSSHAccess();
@@ -693,21 +617,18 @@ async function shell(api) {
693
617
  });
694
618
  }).connect(sshOptions);
695
619
  }
696
-
697
620
  async function debug(api) {
698
621
  const config = api.getConfig();
699
622
  const {
700
623
  selected,
701
624
  description
702
625
  } = await (0, _utils.pickInstance)(config, api.getArgs()[2]);
703
-
704
626
  if (!selected) {
705
627
  console.log(description);
706
628
  console.log('Run "mup beanstalk debug <instance id>"');
707
629
  process.exitCode = 1;
708
630
  return;
709
631
  }
710
-
711
632
  const {
712
633
  sshOptions,
713
634
  removeSSHAccess
@@ -715,15 +636,12 @@ async function debug(api) {
715
636
  const conn = new _ssh.Client();
716
637
  conn.on('ready', async () => {
717
638
  const result = await (0, _utils.executeSSHCommand)(conn, 'sudo pkill -USR1 -u webapp -n node || sudo pkill -USR1 -u nodejs -n node');
718
-
719
639
  if (api.verbose) {
720
640
  console.log(result.output);
721
641
  }
722
-
723
642
  const server = _objectSpread(_objectSpread({}, sshOptions), {}, {
724
643
  pem: api.resolvePath(config.app.sshKey.privateKey)
725
644
  });
726
-
727
645
  let loggedConnection = false;
728
646
  api.forwardPort({
729
647
  server,
@@ -731,11 +649,9 @@ async function debug(api) {
731
649
  localPort: 9229,
732
650
  remoteAddress: '127.0.0.1',
733
651
  remotePort: 9229,
734
-
735
652
  onError(error) {
736
653
  console.error(error);
737
654
  },
738
-
739
655
  onReady() {
740
656
  console.log('Connected to server');
741
657
  console.log('');
@@ -754,7 +670,6 @@ async function debug(api) {
754
670
  console.log('The debugger will be enabled until the next time the app is restarted,');
755
671
  console.log('though only accessible while this command is running');
756
672
  },
757
-
758
673
  onConnection() {
759
674
  if (!loggedConnection) {
760
675
  // It isn't guaranteed the debugger is connected, but not many
@@ -764,7 +679,6 @@ async function debug(api) {
764
679
  loggedConnection = true;
765
680
  }
766
681
  }
767
-
768
682
  });
769
683
  }).connect(sshOptions);
770
684
  process.on('SIGINT', async () => {