grada-run 0.49.4 → 0.49.6
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/package.json +2 -1
- package/src/commands/add.js +1 -1
- package/src/commands/alerts.js +1 -1
- package/src/commands/apply.js +84 -5
- package/src/commands/db/backup.js +3 -3
- package/src/commands/db/connect.js +2 -2
- package/src/commands/db/enable-vector.js +1 -1
- package/src/commands/db/import.js +2 -2
- package/src/commands/db/migrate.js +7 -6
- package/src/commands/destroy.js +116 -10
- package/src/commands/diagnose.js +18 -5
- package/src/commands/domain.js +51 -4
- package/src/commands/exec.js +1 -1
- package/src/commands/gc.js +2 -2
- package/src/commands/init.js +7 -7
- package/src/commands/logs.js +20 -7
- package/src/commands/rollback.js +21 -6
- package/src/commands/secrets.js +19 -19
- package/src/commands/status.js +3 -3
- package/src/commands/wake.js +2 -2
- package/src/utils/addons.js +1 -1
- package/src/utils/backup.js +1 -1
- package/src/utils/ecs-runner.js +3 -3
- package/src/utils/generator.js +3 -3
- package/src/utils/prompts.js +1 -1
- package/src/utils/resolvers.js +8 -10
- package/src/utils/terraform-errors.js +47 -0
- package/src/utils/terraform.js +1 -1
- package/templates/README.md +2 -2
- package/templates/github/deploy-lambda.yml +2 -2
- package/templates/github/deploy-static.yml +1 -1
- package/templates/github/deploy.yml +2 -2
- package/templates/github/drift.yml +1 -1
- package/templates/github/plan.yml +2 -2
- package/templates/github/preview-lambda.yml +4 -4
- package/templates/github/preview.yml +4 -4
- package/templates/github/teardown.yml +3 -3
- package/templates/terraform/addons/bedrock.tf +1 -1
- package/templates/terraform/backend.tf +1 -1
- package/templates/terraform/cloudfront-lambda.tf +2 -2
- package/templates/terraform/cloudfront.tf +3 -3
- package/templates/terraform/database-aurora-postgresql.tf +1 -1
- package/templates/terraform/main.tf +3 -3
- package/templates/terraform/oidc.tf +29 -14
- package/templates/terraform/secrets.tf +1 -1
package/src/commands/domain.js
CHANGED
|
@@ -2,12 +2,14 @@ import fsSync from 'fs';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import color from 'picocolors';
|
|
5
|
-
import { intro, outro, confirm, cancel, isCancel } from '@clack/prompts';
|
|
5
|
+
import { intro, outro, confirm, cancel, isCancel, select } from '@clack/prompts';
|
|
6
6
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
7
7
|
import { resolveProjectName, resolveHeadless, resolveCwd } from '../utils/resolvers.js';
|
|
8
8
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
9
9
|
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
10
10
|
import { getTerraformOutputs } from '../utils/terraform.js';
|
|
11
|
+
import { Route53Client, ListHostedZonesCommand } from '@aws-sdk/client-route-53';
|
|
12
|
+
import { resolveClient } from '../utils/aws.js';
|
|
11
13
|
import {
|
|
12
14
|
findResourceBlock,
|
|
13
15
|
findNestedBlock,
|
|
@@ -435,7 +437,7 @@ async function runDomainMain(input = {}) {
|
|
|
435
437
|
return failCommand({
|
|
436
438
|
noExit,
|
|
437
439
|
message: `\n✖ Invalid Route 53 zone ID "${options.zoneId}".`,
|
|
438
|
-
hint: ' Zone IDs look like Z1234567890ABC (find yours with: aws route53 list-hosted-zones).\n',
|
|
440
|
+
hint: ' Zone IDs look like Z1234567890ABC (re-run without --zone-id to pick from your hosted zones, or find yours with: aws route53 list-hosted-zones).\n',
|
|
439
441
|
event: 'domain_run',
|
|
440
442
|
telemetry: { subcommand, error_code: 'INVALID_ZONE_ID' },
|
|
441
443
|
reason: 'invalid-zone-id',
|
|
@@ -483,6 +485,42 @@ async function runDomainMain(input = {}) {
|
|
|
483
485
|
}, { scope: 'terraform' });
|
|
484
486
|
}
|
|
485
487
|
|
|
488
|
+
// Hosted-zone discovery for `add` without --zone-id: lists zones
|
|
489
|
+
// matching the domain (apex or parent) and lets the user pick one.
|
|
490
|
+
// Returns the picked zone id, or null for external DNS, no match,
|
|
491
|
+
// cancel, or any lookup failure (all fall back to external mode).
|
|
492
|
+
async function discoverHostedZoneId({ route53Client, region, domain }) {
|
|
493
|
+
let zones;
|
|
494
|
+
try {
|
|
495
|
+
const client = resolveClient(route53Client, Route53Client, { region });
|
|
496
|
+
const resp = await client.send(new ListHostedZonesCommand({ MaxItems: 100 }));
|
|
497
|
+
zones = resp?.HostedZones || [];
|
|
498
|
+
} catch {
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
const bare = (name) => String(name || '').replace(/\.$/, '').toLowerCase();
|
|
502
|
+
const matches = zones
|
|
503
|
+
.filter((zone) => {
|
|
504
|
+
const name = bare(zone.Name);
|
|
505
|
+
const target = domain.toLowerCase();
|
|
506
|
+
return name !== '' && (target === name || target.endsWith(`.${name}`));
|
|
507
|
+
})
|
|
508
|
+
.sort((a, b) => String(b.Name).length - String(a.Name).length);
|
|
509
|
+
if (matches.length === 0) return null;
|
|
510
|
+
const picked = await select({
|
|
511
|
+
message: `Pick the Route 53 hosted zone for ${domain}:`,
|
|
512
|
+
options: [
|
|
513
|
+
...matches.map((zone) => {
|
|
514
|
+
const id = normalizeZoneId(zone.Id) || zone.Id;
|
|
515
|
+
return { value: id, label: `${zone.Name} (${id}${zone.Config?.PrivateZone ? ', private' : ''})` };
|
|
516
|
+
}),
|
|
517
|
+
{ value: null, label: 'External DNS instead' },
|
|
518
|
+
],
|
|
519
|
+
});
|
|
520
|
+
if (isCancel(picked) || !picked) return null;
|
|
521
|
+
return picked;
|
|
522
|
+
}
|
|
523
|
+
|
|
486
524
|
async function runDomainAdd({ options, projectName, domain, zoneId, domainTfPath, cloudfrontTfPath }) {
|
|
487
525
|
const noExit = isProgrammaticCall(options);
|
|
488
526
|
const force = options.force === true;
|
|
@@ -509,6 +547,15 @@ async function runDomainAdd({ options, projectName, domain, zoneId, domainTfPath
|
|
|
509
547
|
}
|
|
510
548
|
}
|
|
511
549
|
|
|
550
|
+
if (!zoneId && !resolveHeadless(options)) {
|
|
551
|
+
const discovered = await discoverHostedZoneId({
|
|
552
|
+
route53Client: options.route53Client,
|
|
553
|
+
region: options.region ?? process.env.AWS_REGION ?? 'us-east-2',
|
|
554
|
+
domain,
|
|
555
|
+
});
|
|
556
|
+
if (discovered) zoneId = discovered;
|
|
557
|
+
}
|
|
558
|
+
|
|
512
559
|
const mode = zoneId ? 'route53' : (activate ? 'external-active' : 'external-pending');
|
|
513
560
|
let content;
|
|
514
561
|
if (mode === 'route53') {
|
|
@@ -529,7 +576,7 @@ async function runDomainAdd({ options, projectName, domain, zoneId, domainTfPath
|
|
|
529
576
|
cloudfrontPatched = patched.changed;
|
|
530
577
|
} else if (previousDomain && previousDomain !== domain) {
|
|
531
578
|
// External-pending wires nothing new, but a --force replace must
|
|
532
|
-
// still release the previous ACTIVE aliases
|
|
579
|
+
// still release the previous ACTIVE aliases.
|
|
533
580
|
const read = await readCloudFrontDistribution(cloudfrontTfPath, 'add', noExit);
|
|
534
581
|
if (!read.ok) return read.failure;
|
|
535
582
|
const updated = unpatchCloudFrontDomain(read.content, previousDomain);
|
|
@@ -799,7 +846,7 @@ async function runDomainRemove({ options, projectName, domainTfPath, cloudfrontT
|
|
|
799
846
|
console.log(color.yellow(`⚠ ${remainingAliases.length} alias(es) remain (${remainingAliases.join(', ')}): the ACM viewer_certificate is kept, but its validation resource is deleted with domain.tf — rewire the certificate by hand before applying.`));
|
|
800
847
|
} else if (!unpatched) {
|
|
801
848
|
// The aliases were never touched: claiming a restore would send
|
|
802
|
-
// the next apply into a stale-alias failure
|
|
849
|
+
// the next apply into a stale-alias failure.
|
|
803
850
|
console.log(color.green(`\n✅ Custom domain ${domain || ''} removed.`.replace(' ', ' ')));
|
|
804
851
|
const why = !domain
|
|
805
852
|
? 'terraform/domain.tf was unparseable, so CloudFront aliases were left untouched'
|
package/src/commands/exec.js
CHANGED
|
@@ -109,7 +109,7 @@ async function runExecMain(input = {}) {
|
|
|
109
109
|
cwd = resolveCwd(options);
|
|
110
110
|
region = resolveRegion(options, cwd);
|
|
111
111
|
projectName = resolveProjectName(options, cwd);
|
|
112
|
-
// Workspace-namespaced resources
|
|
112
|
+
// Workspace-namespaced resources: --workspace (or the
|
|
113
113
|
// local .terraform/environment) targets a preview stack like
|
|
114
114
|
// rollback and db do — exec into a preview must not land in
|
|
115
115
|
// production. Explicit flags/env keep winning.
|
package/src/commands/gc.js
CHANGED
|
@@ -287,7 +287,7 @@ async function discoverOldManualSnapshots({ rdsClient, dbIdentifier, dbClusterId
|
|
|
287
287
|
.map((id) => id.trim().toLowerCase());
|
|
288
288
|
const patterns = dbIds
|
|
289
289
|
.map((id) => new RegExp(`^${escapeRegExp(id)}-manual-\\d{8}-\\d{6}$`));
|
|
290
|
-
//
|
|
290
|
+
// The gate's pre-deploy snapshots are per-commit, so without
|
|
291
291
|
// a discovery rule they accumulate into the region snapshot quota.
|
|
292
292
|
const predeployPatterns = dbIds
|
|
293
293
|
.map((id) => new RegExp(`^${escapeRegExp(id)}-pre-deploy-[0-9a-f]{7,40}$`));
|
|
@@ -589,7 +589,7 @@ export async function deleteDiscoveredResources(clients, discovered) {
|
|
|
589
589
|
try {
|
|
590
590
|
summary[target.summary] = await target.remove(clients, discovered[target.field] || []);
|
|
591
591
|
} catch (error) {
|
|
592
|
-
// One target's API failure must not strand the rest
|
|
592
|
+
// One target's API failure must not strand the rest:
|
|
593
593
|
// record it, zero its count, and keep deleting.
|
|
594
594
|
errors.push({ target: target.summary, error });
|
|
595
595
|
summary[target.summary] = 0;
|
package/src/commands/init.js
CHANGED
|
@@ -144,7 +144,7 @@ export function resolveDefaultBranch(targetDir, deployBranch, execSyncImpl = exe
|
|
|
144
144
|
// Renders both CI roles' trust claims as HCL fragments from the resolved
|
|
145
145
|
// repo trust: the deploy role binds to the effective deploy branch (the
|
|
146
146
|
// same value rendered into the deploy trigger, so the two stay in sync),
|
|
147
|
-
// the preview role binds to pull request events.
|
|
147
|
+
// the preview role binds to pull request events. Scheduled drift
|
|
148
148
|
// runs on the default branch, so when it differs from the deploy branch
|
|
149
149
|
// the deploy role trusts both refs. The open trust and hand-customized
|
|
150
150
|
// claims render verbatim — never silently widened.
|
|
@@ -193,7 +193,7 @@ export function buildRoleArn(accountId, roleName) {
|
|
|
193
193
|
// dual-format pair resolves back to its classic entry so re-init stays
|
|
194
194
|
// stable; anything richer is described for warnings and guarded against
|
|
195
195
|
// silent widening.
|
|
196
|
-
// Recognizes our own canonical dual-branch trust
|
|
196
|
+
// Recognizes our own canonical dual-branch trust: two classic
|
|
197
197
|
// branch refs for one slug plus each entry's immutable companion, in
|
|
198
198
|
// render order. Returns { deploySub, branches } or null.
|
|
199
199
|
function parseCanonicalDualTrust(entries) {
|
|
@@ -492,7 +492,7 @@ async function mainStackMain(input = {}) {
|
|
|
492
492
|
target = targetAnswer;
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
// Capability-vs-target policy for --with
|
|
495
|
+
// Capability-vs-target policy for --with: refuse fast when
|
|
496
496
|
// the requested capability cannot render on this target (static has
|
|
497
497
|
// no task role or VPC), before any prompt/AWS call/write. Interactive
|
|
498
498
|
// multiselect offers only compatible targets' caps; this covers --with.
|
|
@@ -962,7 +962,7 @@ async function mainStackMain(input = {}) {
|
|
|
962
962
|
|
|
963
963
|
// 7. Synthesize Templates
|
|
964
964
|
s.message('Synthesizing Terraform templates...');
|
|
965
|
-
//
|
|
965
|
+
// Live origin/HEAD wins when it names a real branch; when
|
|
966
966
|
// detection falls back, a re-init keeps the tree's own default branch
|
|
967
967
|
// so dual trust never narrows silently.
|
|
968
968
|
const treeDefaultBranch = oidcResolution.treeBranches?.[1] ?? null;
|
|
@@ -1025,7 +1025,7 @@ async function mainStackMain(input = {}) {
|
|
|
1025
1025
|
if (migrationGateEnabled && migrationCmd) {
|
|
1026
1026
|
const deployYmlPath = path.join(dirConfig.targetDir, '.github', 'workflows', 'deploy.yml');
|
|
1027
1027
|
const workflowContent = readFileSafe(deployYmlPath);
|
|
1028
|
-
//
|
|
1028
|
+
// Scope the gate's snapshot id to the database (aurora
|
|
1029
1029
|
// takes the cluster prefix) so guardrails and gc can name it.
|
|
1030
1030
|
const gateDbRefs = resolveDbEngineRefs(config.dbEngine);
|
|
1031
1031
|
const gateDbIdentifier = `${dirConfig.actualProjectName}${resourceSuffix}-db${gateDbRefs.isCluster ? '-cluster' : ''}`;
|
|
@@ -1053,7 +1053,7 @@ async function mainStackMain(input = {}) {
|
|
|
1053
1053
|
|
|
1054
1054
|
if (driftEnabled) {
|
|
1055
1055
|
// drift.yml rides the manifest + backup like deploy.yml now
|
|
1056
|
-
//
|
|
1056
|
+
// Re-init backs the old file up and regenerates fresh
|
|
1057
1057
|
// (current role ARN) instead of silently keeping a stale copy.
|
|
1058
1058
|
// Hand edits trip refuse-dirty before this point; --force regenerates.
|
|
1059
1059
|
const drifted = scaffoldDriftWorkflow(dirConfig.targetDir, {
|
|
@@ -1235,7 +1235,7 @@ async function mainStackMain(input = {}) {
|
|
|
1235
1235
|
console.log(color.dim(' 💡 Vector-search dependencies detected: managed pgvector support is coming soon.'));
|
|
1236
1236
|
}
|
|
1237
1237
|
// Static targets refuse `add cron` (no compute) — don't send
|
|
1238
|
-
// static users down a dead end
|
|
1238
|
+
// static users down a dead end.
|
|
1239
1239
|
if (upcoming.cron && target !== 'static') {
|
|
1240
1240
|
console.log(color.dim(' 💡 Scheduled-task dependencies detected: scaffold a schedule with "grada add cron".'));
|
|
1241
1241
|
}
|
package/src/commands/logs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CloudWatchLogsClient, FilterLogEventsCommand, DescribeLogStreamsCommand } from '@aws-sdk/client-cloudwatch-logs';
|
|
1
|
+
import { CloudWatchLogsClient, FilterLogEventsCommand, DescribeLogStreamsCommand, DescribeLogGroupsCommand } from '@aws-sdk/client-cloudwatch-logs';
|
|
2
2
|
import color from 'picocolors';
|
|
3
3
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
4
4
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
@@ -117,7 +117,7 @@ function eventKey(event) {
|
|
|
117
117
|
|
|
118
118
|
// Fetches the most recent matching events from a log group.
|
|
119
119
|
// FilterLogEvents pages oldest-first, so slicing the first page shows the
|
|
120
|
-
// OLDEST N on groups larger than one page
|
|
120
|
+
// OLDEST N on groups larger than one page. This probes with a
|
|
121
121
|
// small page (cheap when the group fits), and only multi-page groups pay
|
|
122
122
|
// for a wide-page scan to the live edge; a rolling window keeps memory
|
|
123
123
|
// O(tail). Returns `{ events, nextToken }` — the trailing window plus the
|
|
@@ -167,9 +167,22 @@ export function buildLogStreamName(containerName, taskId, prefix = 'ecs') {
|
|
|
167
167
|
return `${prefix}/${containerName}/${taskId}`;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
function printMissingLogGroupGuidance(logGroup, service, region) {
|
|
170
|
+
async function printMissingLogGroupGuidance(logGroup, service, region, logsClient) {
|
|
171
171
|
const prefix = `/${String(logGroup).split('/').filter(Boolean).slice(0, 2).join('/')}/`;
|
|
172
172
|
console.log(color.yellow(`\n⚠ No log group found for "${service}" (expected ${logGroup}).`));
|
|
173
|
+
try {
|
|
174
|
+
const resp = await logsClient.send(new DescribeLogGroupsCommand({ logGroupNamePrefix: prefix, limit: 10 }));
|
|
175
|
+
const names = (resp?.logGroups || []).map((group) => group.logGroupName).filter(Boolean).slice(0, 10);
|
|
176
|
+
if (names.length > 0) {
|
|
177
|
+
console.log(color.dim('Matching groups:'));
|
|
178
|
+
for (const name of names) console.log(color.dim(` ${name}`));
|
|
179
|
+
} else {
|
|
180
|
+
console.log(color.dim(`No log groups match "${prefix}".`));
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
} catch {
|
|
184
|
+
// Listing failed: fall back to the CLI pointer below.
|
|
185
|
+
}
|
|
173
186
|
console.log(color.dim(`List matching groups with: aws logs describe-log-groups --log-group-name-prefix "${prefix}" --region ${region}`));
|
|
174
187
|
}
|
|
175
188
|
|
|
@@ -195,7 +208,7 @@ async function runLogsMain(input = {}) {
|
|
|
195
208
|
try {
|
|
196
209
|
cwd = resolveCwd(options);
|
|
197
210
|
region = resolveRegion(options, cwd);
|
|
198
|
-
// Workspace-namespaced resources
|
|
211
|
+
// Workspace-namespaced resources: --workspace (or the
|
|
199
212
|
// local .terraform/environment) targets a preview stack like
|
|
200
213
|
// rollback and db do. Explicit flags/env keep winning.
|
|
201
214
|
const namespacedOptions = withWorkspaceNamespace(options, cwd);
|
|
@@ -212,7 +225,7 @@ async function runLogsMain(input = {}) {
|
|
|
212
225
|
const isLambda = isComputeTarget(cwd, 'lambda');
|
|
213
226
|
const explicitService = hasExplicitService(options) && !isLambda;
|
|
214
227
|
|
|
215
|
-
// Explicit garbage fails loud
|
|
228
|
+
// Explicit garbage fails loud: silently substituting defaults
|
|
216
229
|
// for a mistyped --tail/--since shows logs the user never asked for.
|
|
217
230
|
// Absent flags still default via the normalizers below.
|
|
218
231
|
const rawTail = options.tail ?? options.tailLines ?? options.lines;
|
|
@@ -268,7 +281,7 @@ async function runLogsMain(input = {}) {
|
|
|
268
281
|
} catch (verifyError) {
|
|
269
282
|
if (isAuthError(verifyError)) throw verifyError;
|
|
270
283
|
if (isNotFoundError(verifyError)) {
|
|
271
|
-
printMissingLogGroupGuidance(logGroup, service, region);
|
|
284
|
+
await printMissingLogGroupGuidance(logGroup, service, region, logsClient);
|
|
272
285
|
return { logs: [], logGroup, region, service };
|
|
273
286
|
}
|
|
274
287
|
// Any other verification failure is non-fatal: the fetch below is authoritative.
|
|
@@ -344,7 +357,7 @@ async function runLogsMain(input = {}) {
|
|
|
344
357
|
return { logs: [], logGroup, region, service };
|
|
345
358
|
}
|
|
346
359
|
if (isNotFoundError(error)) {
|
|
347
|
-
printMissingLogGroupGuidance(logGroup, service, region);
|
|
360
|
+
await printMissingLogGroupGuidance(logGroup, service, region, logsClient);
|
|
348
361
|
return { logs: [], logGroup, region, service };
|
|
349
362
|
}
|
|
350
363
|
|
package/src/commands/rollback.js
CHANGED
|
@@ -63,6 +63,21 @@ export async function discoverEligibleRevisions(ecsClient, family, currentRevNum
|
|
|
63
63
|
return discoverWithAdapter(createEcsRevisionAdapter(ecsClient), family, currentRevNum);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// Failure-path hint naming the revisions the user can actually pick,
|
|
67
|
+
// listed in-flow through the same seam Case B selects from. Falls back
|
|
68
|
+
// to the CLI pointer when discovery itself fails.
|
|
69
|
+
async function eligibleRevisionsHint(ecsClient, family, currentRevNum, region) {
|
|
70
|
+
const fallback = 'List recent revisions with: aws ecs list-task-definitions --family-prefix ' + family + ` --region ${region}\n`;
|
|
71
|
+
try {
|
|
72
|
+
const eligible = await discoverEligibleRevisions(ecsClient, family, currentRevNum);
|
|
73
|
+
if (eligible.length === 0) return fallback;
|
|
74
|
+
const revs = eligible.slice(0, 5).map((arn) => String(arn).split(':').pop());
|
|
75
|
+
return `Eligible revisions (newest first): ${revs.join(', ')}\n`;
|
|
76
|
+
} catch {
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
66
81
|
// Programmatic entry wrapper: stamps cli_command for telemetry on every
|
|
67
82
|
// invocation path, including direct imports that bypass bin/cli.js and MCP.
|
|
68
83
|
export async function runRollback(input = {}) {
|
|
@@ -178,7 +193,7 @@ async function runRollbackMain(input = {}) {
|
|
|
178
193
|
let targetTaskDefArn;
|
|
179
194
|
let targetRevisionNum;
|
|
180
195
|
// Case A only: the requested web revision's image, for worker
|
|
181
|
-
// pairing
|
|
196
|
+
// pairing. Null in Case B and when undescribable.
|
|
182
197
|
let requestedWebImage = null;
|
|
183
198
|
|
|
184
199
|
if (options.revision !== undefined && options.revision !== null && String(options.revision).trim() !== '') {
|
|
@@ -195,7 +210,7 @@ async function runRollbackMain(input = {}) {
|
|
|
195
210
|
s.stop(color.red('Revision not found.'));
|
|
196
211
|
return failCommand({
|
|
197
212
|
message: `\n✖ Task definition "${targetInput}" was not found in family "${family}".`,
|
|
198
|
-
hint:
|
|
213
|
+
hint: await eligibleRevisionsHint(ecsClient, family, currentRevNum, region),
|
|
199
214
|
event: 'rollback_run',
|
|
200
215
|
telemetry: { projectName, error_code: 'REVISION_NOT_FOUND' },
|
|
201
216
|
reason: 'revision-not-found',
|
|
@@ -212,7 +227,7 @@ async function runRollbackMain(input = {}) {
|
|
|
212
227
|
s.stop(color.red('Foreign task definition family.'));
|
|
213
228
|
return failCommand({
|
|
214
229
|
message: `\n✖ Task definition "${targetInput}" belongs to family "${descResp.taskDefinition.family ?? 'unknown'}", not "${family}". Rollback stays within the service's own family.`,
|
|
215
|
-
hint:
|
|
230
|
+
hint: await eligibleRevisionsHint(ecsClient, family, currentRevNum, region),
|
|
216
231
|
event: 'rollback_run',
|
|
217
232
|
telemetry: { projectName, error_code: 'REVISION_FAMILY_MISMATCH' },
|
|
218
233
|
reason: 'revision-family-mismatch',
|
|
@@ -236,7 +251,7 @@ async function runRollbackMain(input = {}) {
|
|
|
236
251
|
exitCode: 1,
|
|
237
252
|
});
|
|
238
253
|
}
|
|
239
|
-
//
|
|
254
|
+
// A NEWER explicit revision would silently
|
|
240
255
|
// roll FORWARD — rollback only moves to older revisions.
|
|
241
256
|
if (Number.isInteger(Number(targetRevisionNum)) && Number.isInteger(currentRevNum)
|
|
242
257
|
&& Number(targetRevisionNum) > currentRevNum) {
|
|
@@ -322,7 +337,7 @@ async function runRollbackMain(input = {}) {
|
|
|
322
337
|
}
|
|
323
338
|
}
|
|
324
339
|
|
|
325
|
-
// 1b. Worker rollback
|
|
340
|
+
// 1b. Worker rollback: deploys advance web AND worker,
|
|
326
341
|
// so a rollback must move both — otherwise the worker keeps the bad
|
|
327
342
|
// image. Explicit --service keeps single-service semantics (the
|
|
328
343
|
// escape hatch); workerless trees (no worker.tf) skip. Resolved
|
|
@@ -352,7 +367,7 @@ async function runRollbackMain(input = {}) {
|
|
|
352
367
|
exitCode: 1,
|
|
353
368
|
});
|
|
354
369
|
}
|
|
355
|
-
//
|
|
370
|
+
// In Case A the worker target pairs with the
|
|
356
371
|
// REQUESTED web image (deploys pin both to the same SHA) —
|
|
357
372
|
// newest-previous regardless would skew the pairing. When
|
|
358
373
|
// no eligible worker revision carries the web image, fall
|
package/src/commands/secrets.js
CHANGED
|
@@ -64,7 +64,7 @@ function resolveSecretsFile(envFilePath) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function resolveSecretsProject(projectName) {
|
|
67
|
-
//
|
|
67
|
+
// The terraform project name (what provisioned the vault)
|
|
68
68
|
// outranks the directory basename — a renamed directory otherwise
|
|
69
69
|
// silently aims at a missing vault.
|
|
70
70
|
if (typeof projectName === 'string' && projectName.trim()) return projectName.trim();
|
|
@@ -87,7 +87,7 @@ export async function resolveSecretsRegion(options = {}) {
|
|
|
87
87
|
try {
|
|
88
88
|
const backendTfPath = path.join(process.cwd(), 'terraform', 'backend.tf');
|
|
89
89
|
const backendTfContent = await fs.readFile(backendTfPath, 'utf-8');
|
|
90
|
-
//
|
|
90
|
+
// Scan line-wise skipping comments — the old whole-file
|
|
91
91
|
// regex resolved commented-out regions (or legacy lines) as live.
|
|
92
92
|
for (const rawLine of backendTfContent.split('\n')) {
|
|
93
93
|
const line = rawLine.trim();
|
|
@@ -181,7 +181,7 @@ export async function getManagedEnvNames(cwd = process.cwd(), target = 'ecs') {
|
|
|
181
181
|
}
|
|
182
182
|
// NODE_ENV is injected only when the worker renders (the generator
|
|
183
183
|
// scopes it to worker trees): on workerless trees it is a legitimate
|
|
184
|
-
// custom key and must not auto-skip
|
|
184
|
+
// custom key and must not auto-skip. Unreadable dirs keep
|
|
185
185
|
// the base set above (fail-closed; the TF precondition backstops
|
|
186
186
|
// real collisions there).
|
|
187
187
|
if (!tfFiles.includes('worker.tf')) names.delete('NODE_ENV');
|
|
@@ -252,9 +252,9 @@ function vaultPayloadShape(parsed) {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
// Validates a GetSecretValue response into the managed JSON object.
|
|
255
|
-
// Refuses binary payloads (
|
|
255
|
+
// Refuses binary payloads (They read as "empty" and a push
|
|
256
256
|
// would full-replace them away without the removal confirm) and
|
|
257
|
-
// non-object/non-string payloads (
|
|
257
|
+
// non-object/non-string payloads (Phantom `0,1` removals,
|
|
258
258
|
// garbage pull keys, TypeError crashes). A response carrying neither
|
|
259
259
|
// field means an empty/new vault — live AWS never returns that shape
|
|
260
260
|
// for a valued secret.
|
|
@@ -289,7 +289,7 @@ function vaultPayloadObject(resp, secretId) {
|
|
|
289
289
|
const ATTEMPTED_KEY_RE = /^\s*([^=:#\s][^=:]*?)\s*[=:]/;
|
|
290
290
|
|
|
291
291
|
// Finds .env input lines dotenv silently dropped plus duplicate keys
|
|
292
|
-
|
|
292
|
+
//. Multiline double-quoted values span lines — continuation
|
|
293
293
|
// lines are value text, not dropped lines. Pure and unit-tested via
|
|
294
294
|
// push output.
|
|
295
295
|
function analyzeEnvLines(envContent, parsedSecrets) {
|
|
@@ -363,12 +363,12 @@ async function handleSecretsCatch({
|
|
|
363
363
|
} else if (handleAuthErrorBranch(error, s, opts)) {
|
|
364
364
|
return;
|
|
365
365
|
}
|
|
366
|
-
//
|
|
366
|
+
// Failures after the vault write (keys file, ECS restart)
|
|
367
367
|
// must report the vault as updated with the recovery step — a bare
|
|
368
368
|
// "Failed to push" lies about what succeeded.
|
|
369
369
|
const postVaultHints = {
|
|
370
370
|
'secret_keys.json write': ' Re-run the push to regenerate terraform/secret_keys.json — the vault already holds the new values.\n',
|
|
371
|
-
'ECS restart': '
|
|
371
|
+
'ECS restart': ' Re-run the push to retry the restart (or trigger it by hand: aws ecs update-service --force-new-deployment) — the vault already holds the new values.\n',
|
|
372
372
|
};
|
|
373
373
|
const failureMessage = postVaultStep === null
|
|
374
374
|
? `❌ Failed to ${verb} secrets: ${error.message}`
|
|
@@ -415,7 +415,7 @@ export async function pushSecrets(envFilePath, projectName, options = {}) {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
async function pushSecretsMain(envFilePath, projectName, options = {}) {
|
|
418
|
-
//
|
|
418
|
+
// Push is read-modify-full-replace — serialize local
|
|
419
419
|
// concurrent pushes like every other mutating family (the re-read
|
|
420
420
|
// before UpdateSecret below covers cross-machine second writers).
|
|
421
421
|
return withProjectLock(process.cwd(), () => pushSecretsInner(envFilePath, projectName, options));
|
|
@@ -456,14 +456,14 @@ async function pushSecretsInner(envFilePath, projectName, options = {}) {
|
|
|
456
456
|
resolvedFilePath = '.env';
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
//
|
|
459
|
+
// Shared helper — the terraform project name outranks the
|
|
460
460
|
// directory basename (a renamed directory must not aim at a phantom).
|
|
461
461
|
const resolvedProjectName = resolveSecretsProject(explicitProjectName);
|
|
462
462
|
|
|
463
463
|
const s = spinner();
|
|
464
464
|
s.start(truncateSpinnerText(`Reading ${envFilePath} and pushing to AWS Secrets Manager...`));
|
|
465
465
|
|
|
466
|
-
//
|
|
466
|
+
// Write progress for the catch below — names the post-vault
|
|
467
467
|
// follow-up step when one fails, so the report says the vault is
|
|
468
468
|
// updated instead of misreporting a failed push.
|
|
469
469
|
let postVaultStep = null;
|
|
@@ -518,7 +518,7 @@ async function pushSecretsInner(envFilePath, projectName, options = {}) {
|
|
|
518
518
|
|
|
519
519
|
const parsedSecrets = dotenv.parse(envContent);
|
|
520
520
|
|
|
521
|
-
//
|
|
521
|
+
// Dotenv silently drops lines it cannot parse (and
|
|
522
522
|
// last-wins duplicates) — name them so the success count below
|
|
523
523
|
// reconciles with the file. Runs before the empty early-return
|
|
524
524
|
// so an all-dropped file explains itself.
|
|
@@ -540,7 +540,7 @@ async function pushSecretsInner(envFilePath, projectName, options = {}) {
|
|
|
540
540
|
return;
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
-
// Pre-write guards
|
|
543
|
+
// Pre-write guards: colliding keys are auto-skipped
|
|
544
544
|
// on ECS — pushing them can only brick the deploy, so excluding
|
|
545
545
|
// them with a loud notice beats refusing and demanding a hand
|
|
546
546
|
// edit. Local-dev wiring values warn. Everything surfaces before
|
|
@@ -612,18 +612,18 @@ async function pushSecretsInner(envFilePath, projectName, options = {}) {
|
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
-
//
|
|
615
|
+
// Push is full-replace, so vault keys absent from .env are
|
|
616
616
|
// deleted by the update below. Name every victim before writing;
|
|
617
617
|
// interactive runs confirm first, headless proceeds loudly.
|
|
618
618
|
// Skipped keys are present in .env, so they never land here — their
|
|
619
619
|
// exclusion from the vault write is covered by the skip notice
|
|
620
620
|
// above, not by this confirm.
|
|
621
621
|
const removed = (existingKeys ?? []).filter((key) => !Object.hasOwn(parsedSecrets, key));
|
|
622
|
-
//
|
|
622
|
+
// Skipped keys are present in .env (so they never land in
|
|
623
623
|
// `removed`) but excluded from the vault write — a stale vault
|
|
624
624
|
// value for a skipped key is wiped by the full-replace update.
|
|
625
625
|
// Name every such victim loudly. The skip notice above is the
|
|
626
|
-
// acknowledgment, so unlike
|
|
626
|
+
// acknowledgment, so unlike true removals these never confirm.
|
|
627
627
|
const staleSkipped = skipped.filter((key) => (existingKeys ?? []).includes(key));
|
|
628
628
|
if (staleSkipped.length > 0) {
|
|
629
629
|
console.log(color.yellow(`⚠️ ${staleSkipped.length} skipped ${staleSkipped.length === 1 ? 'key' : 'keys'} still ${staleSkipped.length === 1 ? 'has' : 'have'} a stale vault value that this push deletes (no longer pushed):`));
|
|
@@ -656,7 +656,7 @@ async function pushSecretsInner(envFilePath, projectName, options = {}) {
|
|
|
656
656
|
s.start(truncateSpinnerText(`Reading ${envFilePath} and pushing to AWS Secrets Manager...`));
|
|
657
657
|
}
|
|
658
658
|
|
|
659
|
-
//
|
|
659
|
+
// The confirm above can wait unboundedly — re-read the
|
|
660
660
|
// vault immediately before the full-replace write and abort when
|
|
661
661
|
// a second writer moved the payload since the first read.
|
|
662
662
|
let rereadSecretString = null;
|
|
@@ -690,7 +690,7 @@ async function pushSecretsInner(envFilePath, projectName, options = {}) {
|
|
|
690
690
|
const keys = Object.keys(pushableSecrets);
|
|
691
691
|
const keysFilePath = path.join(process.cwd(), 'terraform', 'secret_keys.json');
|
|
692
692
|
|
|
693
|
-
//
|
|
693
|
+
// Skip the write when the file is already byte-identical
|
|
694
694
|
// so unchanged pushes don't dirty `git status`.
|
|
695
695
|
const nextKeysContent = JSON.stringify(keys, null, 2);
|
|
696
696
|
let keysUnchanged = false;
|
|
@@ -1041,7 +1041,7 @@ async function auditSecretsMain(envFilePath, projectName, options = {}) {
|
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
1043
|
|
|
1044
|
-
//
|
|
1044
|
+
// Flag both limbs — keys colliding with Grada-managed
|
|
1045
1045
|
// environment names (fatal on ECS, shadowing on Lambda) and
|
|
1046
1046
|
// wiring-like values that look like local-dev placeholders.
|
|
1047
1047
|
const auditTarget = readTerraformComputeTarget(process.cwd());
|
package/src/commands/status.js
CHANGED
|
@@ -453,7 +453,7 @@ async function runStatusMain(input = {}) {
|
|
|
453
453
|
return runStaticStatus({ ...options, cwd, region, projectName });
|
|
454
454
|
}
|
|
455
455
|
const resourceSuffix = readResourceSuffix(cwd);
|
|
456
|
-
// Workspace-namespaced resources
|
|
456
|
+
// Workspace-namespaced resources: --workspace (or the local
|
|
457
457
|
// .terraform/environment) targets a preview stack like rollback and db
|
|
458
458
|
// do. Explicit flags/env keep winning; telemetry keeps the raw name.
|
|
459
459
|
const namespacedProject = resolveNamespacedProject(projectName, options, cwd);
|
|
@@ -502,9 +502,9 @@ async function runStatusMain(input = {}) {
|
|
|
502
502
|
return;
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
// Namespaced stem
|
|
505
|
+
// Namespaced stem: the raw project prefix merged prod
|
|
506
506
|
// + preview alarms into one verdict and could auto-diagnose the
|
|
507
|
-
// wrong cluster. Paired with workspace-aware alarm names
|
|
507
|
+
// wrong cluster. Paired with workspace-aware alarm names.
|
|
508
508
|
const alarmsResp = await cloudWatchClient.send(new DescribeAlarmsCommand({ AlarmNamePrefix: `${namespacedProject}${resourceSuffix}`, MaxRecords: 100 }));
|
|
509
509
|
const rawAlarms = [...(alarmsResp.MetricAlarms || []), ...(alarmsResp.CompositeAlarms || [])];
|
|
510
510
|
|
package/src/commands/wake.js
CHANGED
|
@@ -221,7 +221,7 @@ async function runWakeMain(input = {}) {
|
|
|
221
221
|
// both must reach the main flow, never the already-awake
|
|
222
222
|
// skip. Every other status (available, starting, …) is
|
|
223
223
|
// started or self-resolving, so there is nothing for wake
|
|
224
|
-
// to do
|
|
224
|
+
// to do.
|
|
225
225
|
const dbAwake = !foundDb || (foundDb.status !== 'stopped' && foundDb.status !== 'stopping');
|
|
226
226
|
if (servicesAwake && dbAwake) {
|
|
227
227
|
return reportSleepWakeSkip({
|
|
@@ -258,7 +258,7 @@ async function runWakeMain(input = {}) {
|
|
|
258
258
|
// A transitional database (stopping/starting/…) can neither
|
|
259
259
|
// start nor serve: settle first (mirroring destroy), then
|
|
260
260
|
// start when it lands on `stopped`. Never restore ECS +
|
|
261
|
-
// report success over an unsettled database
|
|
261
|
+
// report success over an unsettled database.
|
|
262
262
|
if (dbTarget && dbTarget.status !== 'stopped' && dbTarget.status !== 'available') {
|
|
263
263
|
const transitional = dbTarget.status;
|
|
264
264
|
const isCluster = dbTarget.kind === 'cluster';
|
package/src/utils/addons.js
CHANGED
|
@@ -83,7 +83,7 @@ export const ADDON_REGISTRY = {
|
|
|
83
83
|
export const ADDON_TARGET_POLICY = {
|
|
84
84
|
// Static trees have no task role or VPC: every one of these renders
|
|
85
85
|
// a dangling aws_iam_role.task_role / aws_vpc reference on static
|
|
86
|
-
//
|
|
86
|
+
// Refuse fast instead of emitting unplannable TF.
|
|
87
87
|
'storage:s3': { ecs: 'allow', lambda: 'allow', static: 'refuse' },
|
|
88
88
|
'db:dynamodb': { ecs: 'allow', lambda: 'allow', static: 'refuse' },
|
|
89
89
|
'db:redis': { ecs: 'allow', lambda: 'allow', static: 'refuse' },
|
package/src/utils/backup.js
CHANGED
|
@@ -32,7 +32,7 @@ function collectManifestFiles(targetDir) {
|
|
|
32
32
|
// Preview/teardown/drift carry project names + role ARNs and invite
|
|
33
33
|
// hand edits like deploy.yml — manifest them so re-init refuses
|
|
34
34
|
// dirty trees and backs them up instead of silently overwriting or
|
|
35
|
-
// leaving them stale
|
|
35
|
+
// leaving them stale.
|
|
36
36
|
for (const rel of ['Dockerfile', 'preview.yml', 'teardown.yml', 'drift.yml', 'plan.yml'].map((name) => (
|
|
37
37
|
name === 'Dockerfile' ? name : path.join('.github', 'workflows', name)
|
|
38
38
|
))) {
|
package/src/utils/ecs-runner.js
CHANGED
|
@@ -311,7 +311,7 @@ export async function runEphemeralEcsTask({
|
|
|
311
311
|
// Sniffs the URL scheme from discrete credentials. Explicit values win;
|
|
312
312
|
// when DB_ENGINE/DB_PORT are secrets-sourced (valueFrom, values unknown
|
|
313
313
|
// to the CLI) the reference text is sniffed for engine/port hints
|
|
314
|
-
// instead
|
|
314
|
+
// instead. Indeterminate stays postgresql (back-compat).
|
|
315
315
|
function sniffRunnerScheme(entries, values) {
|
|
316
316
|
const engine = values.get('DB_ENGINE');
|
|
317
317
|
if (typeof engine === 'string' && engine !== '') {
|
|
@@ -326,7 +326,7 @@ function sniffRunnerScheme(entries, values) {
|
|
|
326
326
|
return 'postgresql';
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
// Runtime userinfo encoder for the synthesized URL
|
|
329
|
+
// Runtime userinfo encoder for the synthesized URL: node sees
|
|
330
330
|
// only shell references, never the values, so the encoding ladder ships
|
|
331
331
|
// inside the script — node (encodeURIComponent) → sed (the URL-breaking
|
|
332
332
|
// subset: %, ?, #, @, :, /) → warned raw. Quoting alone cannot save a
|
|
@@ -510,7 +510,7 @@ export async function reportRunnerOutcome({
|
|
|
510
510
|
if (exitCode === 0) {
|
|
511
511
|
// Owner pairs its own start/stop: the runner usually stops
|
|
512
512
|
// first (idempotent no-op then), but success must never
|
|
513
|
-
// depend on a callee for the spinner lifecycle
|
|
513
|
+
// depend on a callee for the spinner lifecycle.
|
|
514
514
|
try { s.stop(color.green(`${label} succeeded.`)); } catch { /* already stopped */ }
|
|
515
515
|
console.log(color.green(`\n✅ ${label} succeeded.`));
|
|
516
516
|
await trackSuccess(event, { ...telemetry });
|
package/src/utils/generator.js
CHANGED
|
@@ -17,7 +17,7 @@ const __dirname = path.dirname(__filename);
|
|
|
17
17
|
// name stays a writable candidate so pre-rebrand docs keep updating.
|
|
18
18
|
export const MANAGED_DOC_FALLBACK = 'GRADA.md';
|
|
19
19
|
export const LEGACY_MANAGED_DOC_FALLBACK = 'DEPLOY-STACK.md';
|
|
20
|
-
// Greppable, boot-failing Rails master-key seed
|
|
20
|
+
// Greppable, boot-failing Rails master-key seed: Rails cannot
|
|
21
21
|
// boot on it, so a tree that never pushes the real key fails closed.
|
|
22
22
|
export const RAILS_MASTER_KEY_PLACEHOLDER = 'REPLACE_ME_PUSH_REAL_RAILS_MASTER_KEY';
|
|
23
23
|
|
|
@@ -505,7 +505,7 @@ export async function generateTemplates(targetDir, config) {
|
|
|
505
505
|
// Build the initial HCL map for AWS Secrets Manager
|
|
506
506
|
let initialSecretMap = `{\n EXAMPLE_API_KEY = "replace_me_in_aws_console"`;
|
|
507
507
|
|
|
508
|
-
// 4.1. Seed a placeholder for the Rails master key
|
|
508
|
+
// 4.1. Seed a placeholder for the Rails master key: the
|
|
509
509
|
// live key must never render into committed .tf (or linger in
|
|
510
510
|
// state), and no constant dummy may boot prod. The placeholder is
|
|
511
511
|
// greppable and boot-failing; the loud instruction tells the
|
|
@@ -587,7 +587,7 @@ resource "aws_lb_listener_rule" "vercel_redirect_${index}" {
|
|
|
587
587
|
|
|
588
588
|
// Inject variables. Replacement FUNCTION (not string): `$&`/`$'`/
|
|
589
589
|
// `$$` in values (Procfile commands, compose env vars) must land
|
|
590
|
-
// byte-identical, not interpolate match text
|
|
590
|
+
// byte-identical, not interpolate match text.
|
|
591
591
|
for (const [key, value] of Object.entries(config)) {
|
|
592
592
|
const literal = String(value ?? '');
|
|
593
593
|
content = content.replace(new RegExp(`{{${key}}}`, 'g'), () => literal);
|
package/src/utils/prompts.js
CHANGED
|
@@ -90,7 +90,7 @@ export async function getProjectConfig(isHeadless, headlessOptions, targetDir, d
|
|
|
90
90
|
const skipsContainerSizing = hints && typeof hints === 'object'
|
|
91
91
|
&& (hints.target === 'lambda' || hints.target === 'static');
|
|
92
92
|
if (isHeadless) {
|
|
93
|
-
//
|
|
93
|
+
// An undetectable framework with a package.json present is
|
|
94
94
|
// a plain-Node project, not a static site — defaulting to 'static'
|
|
95
95
|
// renders an nginx Dockerfile that can neither build scriptless
|
|
96
96
|
// projects nor run node payloads. No package.json keeps 'static'.
|