grada-run 0.44.0 → 0.45.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/bin/cli.js +1 -1
- package/package.json +1 -1
- package/src/commands/db/backup.js +40 -16
- package/src/commands/db/migrate.js +33 -18
- package/src/commands/db.js +12 -5
- package/src/commands/domain.js +14 -10
- package/src/commands/init.js +1 -1
package/bin/cli.js
CHANGED
|
@@ -131,7 +131,7 @@ function runCommand(promise) {
|
|
|
131
131
|
// Help wins over every subcommand: no flow — destructive or otherwise —
|
|
132
132
|
// may execute from a help invocation. `db` keeps its own usage path
|
|
133
133
|
// inside runDb (db usage for `db --help` and every `db <leaf> --help`,
|
|
134
|
-
// exit 0; bare `db`
|
|
134
|
+
// exit 0; bare `db` prints usage the same untracked way).
|
|
135
135
|
const wantsHelp = positionalArgs[0] === 'help' || rawArgs.includes('--help') || rawArgs.includes('-h');
|
|
136
136
|
// Version wins over every subcommand like help does — but unlike help it
|
|
137
137
|
// needs no `db` exemption: the version is global, identical everywhere.
|
package/package.json
CHANGED
|
@@ -15,6 +15,12 @@ export const DEFAULT_BACKUP_POLL_INTERVAL_MS = 5000;
|
|
|
15
15
|
|
|
16
16
|
const SNAPSHOT_NOT_FOUND_NAMES = new Set(['DBSnapshotNotFound', 'DBSnapshotNotFoundFault']);
|
|
17
17
|
const CLUSTER_SNAPSHOT_NOT_FOUND_NAMES = new Set(['DBClusterSnapshotNotFound', 'DBClusterSnapshotNotFoundFault']);
|
|
18
|
+
const SNAPSHOT_ALREADY_EXISTS_NAMES = new Set([
|
|
19
|
+
'DBSnapshotAlreadyExists',
|
|
20
|
+
'DBSnapshotAlreadyExistsFault',
|
|
21
|
+
'DBClusterSnapshotAlreadyExists',
|
|
22
|
+
'DBClusterSnapshotAlreadyExistsFault',
|
|
23
|
+
]);
|
|
18
24
|
// Snapshot states that never become available: polling past them only
|
|
19
25
|
// wastes the timeout and misreports.
|
|
20
26
|
const TERMINAL_SNAPSHOT_STATUSES = new Set(['failed', 'deleted', 'deleting']);
|
|
@@ -142,25 +148,43 @@ async function runDbBackupMain(input = {}) {
|
|
|
142
148
|
{ Key: 'ManagedBy', Value: 'grada' },
|
|
143
149
|
{ Key: 'Project', Value: projectName },
|
|
144
150
|
];
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
// An existing id is success, not failure: CI retries and re-runs of
|
|
152
|
+
// the same migration must not fail just because the snapshot step
|
|
153
|
+
// already ran. The wait below then resolves its actual state
|
|
154
|
+
// (available, still creating, or failed) the same as a fresh create.
|
|
155
|
+
let reusedExisting = false;
|
|
156
|
+
try {
|
|
157
|
+
if (isCluster) {
|
|
158
|
+
await rdsClient.send(new CreateDBClusterSnapshotCommand({
|
|
159
|
+
DBClusterIdentifier: target.id,
|
|
160
|
+
DBClusterSnapshotIdentifier: snapshotId,
|
|
161
|
+
Tags: snapshotTags,
|
|
162
|
+
}));
|
|
163
|
+
} else {
|
|
164
|
+
await rdsClient.send(new CreateDBSnapshotCommand({
|
|
165
|
+
DBInstanceIdentifier: target.id,
|
|
166
|
+
DBSnapshotIdentifier: snapshotId,
|
|
167
|
+
Tags: snapshotTags,
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error && SNAPSHOT_ALREADY_EXISTS_NAMES.has(error.name)) {
|
|
172
|
+
reusedExisting = true;
|
|
173
|
+
} else {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
157
176
|
}
|
|
158
177
|
|
|
159
178
|
if (noWait) {
|
|
160
|
-
|
|
161
|
-
|
|
179
|
+
if (reusedExisting) {
|
|
180
|
+
s.stop(color.green('Snapshot already exists.'));
|
|
181
|
+
console.log(`\n Snapshot ${color.cyan(snapshotId)} already exists — reusing it.`);
|
|
182
|
+
} else {
|
|
183
|
+
s.stop(color.green('Snapshot creation started.'));
|
|
184
|
+
console.log(`\n Snapshot ${color.cyan(snapshotId)} is being created (status: creating).`);
|
|
185
|
+
}
|
|
162
186
|
console.log(color.dim(` Restore it later with: npx grada-run db restore ${snapshotId}\n`));
|
|
163
|
-
await trackSuccess('db_backup_run', { projectName, waited: false, db_kind: target.kind });
|
|
187
|
+
await trackSuccess('db_backup_run', { projectName, waited: false, db_kind: target.kind, reused_existing: reusedExisting });
|
|
164
188
|
outro(color.green('Done.'));
|
|
165
189
|
return { ok: true, snapshotId, status: 'creating' };
|
|
166
190
|
}
|
|
@@ -243,7 +267,7 @@ async function runDbBackupMain(input = {}) {
|
|
|
243
267
|
s.stop(color.green('Snapshot available.'));
|
|
244
268
|
console.log(`\n Snapshot ${color.cyan(snapshotId)} is ready.`);
|
|
245
269
|
console.log(color.dim(` Restore it with: npx grada-run db restore ${snapshotId}\n`));
|
|
246
|
-
await trackSuccess('db_backup_run', { projectName, waited: true, db_kind: target.kind });
|
|
270
|
+
await trackSuccess('db_backup_run', { projectName, waited: true, db_kind: target.kind, reused_existing: reusedExisting });
|
|
247
271
|
outro(color.green('Done.'));
|
|
248
272
|
return { ok: true, snapshotId, status: 'available' };
|
|
249
273
|
} catch (error) {
|
|
@@ -86,7 +86,7 @@ export function quoteShellArg(value) {
|
|
|
86
86
|
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
function renderGateBlock({ includeSetupNode,
|
|
89
|
+
function renderGateBlock({ includeSetupNode, steps }) {
|
|
90
90
|
const lines = [` ${GATE_START_MARKER}`];
|
|
91
91
|
if (includeSetupNode) {
|
|
92
92
|
lines.push(
|
|
@@ -97,16 +97,18 @@ function renderGateBlock({ includeSetupNode, stepName, runLine }) {
|
|
|
97
97
|
''
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
for (const { stepName, runLine } of steps) {
|
|
101
|
+
lines.push(
|
|
102
|
+
` - name: ${stepName}`,
|
|
103
|
+
// Gates run AWS calls: honor the credential-skip outcome like
|
|
104
|
+
// every other post-assume step (BUG-138). Neutral on deploy
|
|
105
|
+
// (a failed assume fails the run before any gate runs).
|
|
106
|
+
` if: steps.aws-creds.outcome == 'success'`,
|
|
107
|
+
' run: |',
|
|
108
|
+
` ${runLine}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
lines.push(` ${GATE_END_MARKER}`);
|
|
110
112
|
return `${lines.join('\n')}\n`;
|
|
111
113
|
}
|
|
112
114
|
|
|
@@ -132,10 +134,10 @@ export function buildRunnerInvocation(cliVersion) {
|
|
|
132
134
|
|
|
133
135
|
// Shared injection core: strips any previous gate, renders the block, and
|
|
134
136
|
// splices it before the anchor step. Returns null without the anchor.
|
|
135
|
-
function injectGateBlock(content, {
|
|
137
|
+
function injectGateBlock(content, { steps, anchor }) {
|
|
136
138
|
const base = stripPreviousGateBlock(String(content ?? ''));
|
|
137
139
|
const includeSetupNode = !base.includes('actions/setup-node');
|
|
138
|
-
const block = renderGateBlock({ includeSetupNode,
|
|
140
|
+
const block = renderGateBlock({ includeSetupNode, steps });
|
|
139
141
|
const anchorIdx = base.indexOf(anchor);
|
|
140
142
|
if (anchorIdx === -1) return null;
|
|
141
143
|
const insertAt = base.lastIndexOf('\n', anchorIdx) + 1;
|
|
@@ -147,9 +149,18 @@ function injectGateBlock(content, { runLine, stepName, anchor }) {
|
|
|
147
149
|
// anchor step is present. Pure and unit-tested.
|
|
148
150
|
export function injectMigrationGate(workflowContent, { cmd, cliVersion } = {}) {
|
|
149
151
|
const taskDefRef = '${{ steps.register-task-def.outputs.task-arn }}';
|
|
152
|
+
const runner = buildRunnerInvocation(cliVersion);
|
|
150
153
|
return injectGateBlock(workflowContent, {
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
steps: [
|
|
155
|
+
{
|
|
156
|
+
stepName: 'Take pre-migration database snapshot',
|
|
157
|
+
runLine: `${runner} db backup --id "pre-deploy-\${{ github.sha }}" --headless`,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
stepName: 'Pre-Deploy Database Migration',
|
|
161
|
+
runLine: `${runner} db migrate --cmd ${quoteShellArg(cmd)} --task-def "${taskDefRef}" --headless`,
|
|
162
|
+
},
|
|
163
|
+
],
|
|
153
164
|
anchor: '- name: Force ECS deployment',
|
|
154
165
|
});
|
|
155
166
|
}
|
|
@@ -160,8 +171,12 @@ export function injectMigrationGate(workflowContent, { cmd, cliVersion } = {}) {
|
|
|
160
171
|
// service itself via --workspace. Returns null without the anchor.
|
|
161
172
|
export function injectPreviewMigrationGate(workflowContent, { cmd, cliVersion } = {}) {
|
|
162
173
|
return injectGateBlock(workflowContent, {
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
steps: [
|
|
175
|
+
{
|
|
176
|
+
stepName: 'Preview Database Migration',
|
|
177
|
+
runLine: `${buildRunnerInvocation(cliVersion)} db migrate --cmd ${quoteShellArg(cmd)} --workspace "\${{ env.WORKSPACE }}" --headless`,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
165
180
|
anchor: '- name: Comment PR',
|
|
166
181
|
});
|
|
167
182
|
}
|
|
@@ -398,7 +413,7 @@ async function runDbMigrateMain(input = {}) {
|
|
|
398
413
|
}
|
|
399
414
|
await atomicWriteFile(workflowFile, updated, 'utf8');
|
|
400
415
|
console.log(color.green('\n✅ Pre-deploy migration gate installed in .github/workflows/deploy.yml.'));
|
|
401
|
-
console.log(color.dim('
|
|
416
|
+
console.log(color.dim(' Each deploy now snapshots the database, then runs migrations against the new image revision before the ECS service updates.\n'));
|
|
402
417
|
if (readTerraformComputeTarget(cwd) === 'ecs') {
|
|
403
418
|
const previewFile = path.join(cwd, '.github', 'workflows', 'preview.yml');
|
|
404
419
|
let previewContent = null;
|
package/src/commands/db.js
CHANGED
|
@@ -114,13 +114,20 @@ async function runDbMain(argv = [], extraOptions = {}) {
|
|
|
114
114
|
return runDbImport({ ...parseDbImportArgs(argv), ...extra });
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
if (subcommand === undefined) {
|
|
118
|
+
// Bare invocation is help-seeking, not an error: usage + exit
|
|
119
|
+
// 0, untracked like --help (keeps probe noise out of error
|
|
120
|
+
// telemetry).
|
|
121
|
+
console.log(color.yellow('\n⚠ Missing db subcommand.'));
|
|
122
|
+
console.log('');
|
|
123
|
+
printDbUsage();
|
|
124
|
+
console.log('');
|
|
125
|
+
return { ok: true };
|
|
126
|
+
}
|
|
127
|
+
|
|
117
128
|
return failCommand({
|
|
118
129
|
print: () => {
|
|
119
|
-
|
|
120
|
-
console.log(color.yellow('\n⚠ Missing db subcommand.'));
|
|
121
|
-
} else {
|
|
122
|
-
console.log(color.red(`\n✖ Unknown db subcommand "${subcommand}".`));
|
|
123
|
-
}
|
|
130
|
+
console.log(color.red(`\n✖ Unknown db subcommand "${subcommand}".`));
|
|
124
131
|
console.log('');
|
|
125
132
|
printDbUsage();
|
|
126
133
|
console.log('');
|
package/src/commands/domain.js
CHANGED
|
@@ -386,24 +386,28 @@ async function runDomainMain(input = {}) {
|
|
|
386
386
|
intro(color.bgCyan(color.black(' grada domain 🌐 ')));
|
|
387
387
|
|
|
388
388
|
if (!DOMAIN_SUBCOMMANDS.includes(subcommand)) {
|
|
389
|
-
//
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
:
|
|
389
|
+
// Blank input trims to '' rather than undefined — same missing
|
|
390
|
+
// case the old 'none' telemetry bucket covered.
|
|
391
|
+
if (subcommand === undefined || subcommand === '') {
|
|
392
|
+
// Bare invocation is help-seeking, not an error: usage + exit
|
|
393
|
+
// 0, untracked like --help (keeps probe noise out of error
|
|
394
|
+
// telemetry).
|
|
395
|
+
console.log(color.yellow('\n⚠ Missing domain subcommand.'));
|
|
396
|
+
console.log('');
|
|
397
|
+
printDomainUsage();
|
|
398
|
+
console.log('');
|
|
399
|
+
return { ok: true };
|
|
400
|
+
}
|
|
393
401
|
return failCommand({
|
|
394
402
|
noExit,
|
|
395
403
|
print: () => {
|
|
396
|
-
|
|
397
|
-
console.log(color.yellow('\n⚠ Missing domain subcommand.'));
|
|
398
|
-
} else {
|
|
399
|
-
console.log(color.red(`\n✖ Unknown domain subcommand "${options.subcommand}".`));
|
|
400
|
-
}
|
|
404
|
+
console.log(color.red(`\n✖ Unknown domain subcommand "${options.subcommand}".`));
|
|
401
405
|
console.log('');
|
|
402
406
|
printDomainUsage();
|
|
403
407
|
console.log('');
|
|
404
408
|
},
|
|
405
409
|
event: 'domain_run',
|
|
406
|
-
telemetry: { subcommand:
|
|
410
|
+
telemetry: { subcommand: 'unknown' },
|
|
407
411
|
errorCode: 'UNKNOWN_DOMAIN_SUBCOMMAND',
|
|
408
412
|
reason: 'unknown-domain-subcommand',
|
|
409
413
|
});
|
package/src/commands/init.js
CHANGED
|
@@ -903,7 +903,7 @@ async function mainStackMain(input = {}) {
|
|
|
903
903
|
const gated = workflowContent ? injectMigrationGate(workflowContent, { cmd: migrationCmd, cliVersion: CLI_VERSION }) : null;
|
|
904
904
|
if (gated) {
|
|
905
905
|
atomicWriteFileSync(deployYmlPath, gated);
|
|
906
|
-
console.log(color.green('✅ Wired the pre-deploy database migration gate into .github/workflows/deploy.yml'));
|
|
906
|
+
console.log(color.green('✅ Wired the pre-deploy database migration gate into .github/workflows/deploy.yml (snapshot first, then migrate)'));
|
|
907
907
|
} else {
|
|
908
908
|
log.warn(color.yellow('⚠️ Could not wire the migration gate: the deploy workflow anchor was not found.'));
|
|
909
909
|
}
|