@mikarinneoracle/oci-cdk-code-only-preview 0.0.15 → 0.0.17
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/ocdk.js +12 -0
- package/bin/write-log-config.js +32 -12
- package/package.json +1 -1
package/bin/ocdk.js
CHANGED
|
@@ -122,6 +122,18 @@ if (command === 'tail:execution-log') {
|
|
|
122
122
|
const projectDir = process.cwd();
|
|
123
123
|
const projectScript = path.join(projectDir, 'tail-function-logs.js');
|
|
124
124
|
if (fs.existsSync(projectScript)) {
|
|
125
|
+
// A stack synth creates a placeholder script. Refresh it from Terraform
|
|
126
|
+
// outputs before executing so it never masks the working fallback tailer.
|
|
127
|
+
const projectScriptContent = fs.readFileSync(projectScript, 'utf8');
|
|
128
|
+
if (projectScriptContent.includes('__EXECUTION_LOG_ID__') || projectScriptContent.includes('__LOG_GROUP_ID__')) {
|
|
129
|
+
const configureLogs = spawnSync('node', [path.join(root, 'bin', 'write-log-config.js')], {
|
|
130
|
+
stdio: 'inherit',
|
|
131
|
+
cwd: projectDir,
|
|
132
|
+
shell: false,
|
|
133
|
+
env: process.env,
|
|
134
|
+
});
|
|
135
|
+
if (configureLogs.status !== 0) process.exit(configureLogs.status ?? 1);
|
|
136
|
+
}
|
|
125
137
|
const result = spawnSync('node', [projectScript, ...args.slice(1)], {
|
|
126
138
|
stdio: 'inherit',
|
|
127
139
|
cwd: projectDir,
|
package/bin/write-log-config.js
CHANGED
|
@@ -3,29 +3,49 @@
|
|
|
3
3
|
* Write tail-function-logs.js to the project root with log IDs from terraform output.
|
|
4
4
|
* Run from project root after deploy. Usage: npx ocdk write-log-config
|
|
5
5
|
*/
|
|
6
|
-
const {
|
|
6
|
+
const { spawnSync } = require('child_process');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const fs = require('fs');
|
|
9
9
|
|
|
10
10
|
const packageRoot = path.join(__dirname, '..');
|
|
11
11
|
const projectRoot = process.cwd();
|
|
12
12
|
const stackName = process.env.OCI_STACK_NAME || 'oci-stack';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
function outputValue(value, key) {
|
|
14
|
+
if (!value || typeof value !== 'object') return undefined;
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
16
|
+
const output = value[key];
|
|
17
|
+
if (typeof output === 'string') return output;
|
|
18
|
+
if (output && typeof output === 'object' && typeof output.value === 'string') return output.value;
|
|
19
|
+
}
|
|
20
|
+
for (const child of Object.values(value)) {
|
|
21
|
+
const found = outputValue(child, key);
|
|
22
|
+
if (found) return found;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
const tempDir = fs.mkdtempSync(path.join(require('os').tmpdir(), 'ocdk-log-output-'));
|
|
28
|
+
const outputFile = path.join(tempDir, 'outputs.json');
|
|
21
29
|
let logGroupId;
|
|
22
30
|
let executionLogId;
|
|
23
31
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
const result = spawnSync('npm', ['run', '--silent', 'cdktf', '--', 'output', stackName, '--outputs-file', outputFile], {
|
|
33
|
+
cwd: packageRoot,
|
|
34
|
+
encoding: 'utf8',
|
|
35
|
+
shell: false,
|
|
36
|
+
});
|
|
37
|
+
if (result.status !== 0 || !fs.existsSync(outputFile)) {
|
|
38
|
+
throw new Error((result.stderr || result.stdout || '').trim() || 'cdktf output did not produce an output file.');
|
|
39
|
+
}
|
|
40
|
+
const outputs = JSON.parse(fs.readFileSync(outputFile, 'utf8'));
|
|
41
|
+
logGroupId = outputValue(outputs, 'log_group_id');
|
|
42
|
+
executionLogId = outputValue(outputs, 'execution_log_id');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
45
|
+
console.error(`Could not read Terraform outputs: ${error.message}`);
|
|
28
46
|
process.exit(1);
|
|
47
|
+
} finally {
|
|
48
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
29
49
|
}
|
|
30
50
|
|
|
31
51
|
if (!logGroupId || !executionLogId) {
|
|
@@ -44,4 +64,4 @@ if (fs.existsSync(srcScript)) {
|
|
|
44
64
|
console.warn('Source script not found:', srcScript);
|
|
45
65
|
}
|
|
46
66
|
|
|
47
|
-
console.log('Done. Run:
|
|
67
|
+
console.log('Done. Run: npx ocdk tail:execution-log');
|