oci-cdk-test 0.0.2 → 0.0.3
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/tail-execution-log.js +26 -11
- package/package.json +1 -1
|
@@ -20,41 +20,56 @@ function fail(msg) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function main() {
|
|
23
|
-
const
|
|
23
|
+
const packageRoot = path.join(__dirname, '..');
|
|
24
|
+
// Prefer caller's cwd (e.g. project that ran npx oci-cdk-test deploy) so we find the same state
|
|
25
|
+
const cwd = process.env.OCDK_PROJECT_DIR || process.cwd();
|
|
24
26
|
|
|
25
27
|
const compId = process.env.OCI_COMPARTMENT_ID || process.env.OCI_COMPARTMENT_OCID;
|
|
26
28
|
if (!compId) {
|
|
27
29
|
fail('OCI_COMPARTMENT_ID (or OCI_COMPARTMENT_OCID) must be set to tail execution logs.');
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
// Read Terraform outputs via cdktf
|
|
31
|
-
|
|
32
|
-
cwd
|
|
32
|
+
// Read Terraform outputs via cdktf; try caller cwd first, then package root
|
|
33
|
+
let output = spawnSync('cdktf', ['output', '-json'], {
|
|
34
|
+
cwd,
|
|
33
35
|
shell: true,
|
|
34
36
|
encoding: 'utf8',
|
|
35
37
|
});
|
|
38
|
+
if (output.status !== 0 || !output.stdout || output.stdout.trim() === '') {
|
|
39
|
+
output = spawnSync('cdktf', ['output', '-json'], {
|
|
40
|
+
cwd: packageRoot,
|
|
41
|
+
shell: true,
|
|
42
|
+
encoding: 'utf8',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
36
45
|
if (output.status !== 0) {
|
|
37
|
-
console.error(output.
|
|
38
|
-
fail('Failed to run "cdktf output -json".
|
|
46
|
+
console.error(output.stderr || output.stdout || '');
|
|
47
|
+
fail('Failed to run "cdktf output -json". Run from the project where you deployed (or set OCDK_PROJECT_DIR) and ensure the stack is deployed.');
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
const raw = (output.stdout || '').trim();
|
|
41
51
|
let parsed;
|
|
42
52
|
try {
|
|
43
|
-
parsed = JSON.parse(
|
|
53
|
+
parsed = JSON.parse(raw || '{}');
|
|
44
54
|
} catch (e) {
|
|
45
|
-
|
|
55
|
+
console.error('Raw output from "cdktf output -json":');
|
|
56
|
+
console.error(raw || '(empty)');
|
|
57
|
+
fail('Failed to parse "cdktf output -json". Ensure the stack is deployed and cdktf is available.');
|
|
46
58
|
}
|
|
47
59
|
|
|
60
|
+
// cdktf may return outputs keyed by stack name (e.g. { "oci-stack": { "log_group_id": {...} } })
|
|
61
|
+
const outputs = parsed.log_group_id != null ? parsed : Object.values(parsed).find((v) => v && typeof v === 'object' && (v.log_group_id != null || v.execution_log_id != null)) || parsed;
|
|
62
|
+
|
|
48
63
|
function valueOf(out, key) {
|
|
49
64
|
const v = out[key];
|
|
50
65
|
if (!v) return undefined;
|
|
51
66
|
if (typeof v === 'string') return v;
|
|
52
|
-
if (typeof v.value === 'string') return v.value;
|
|
67
|
+
if (v && typeof v.value === 'string') return v.value;
|
|
53
68
|
return undefined;
|
|
54
69
|
}
|
|
55
70
|
|
|
56
|
-
const logGroupId = valueOf(
|
|
57
|
-
const executionLogId = valueOf(
|
|
71
|
+
const logGroupId = valueOf(outputs, 'log_group_id');
|
|
72
|
+
const executionLogId = valueOf(outputs, 'execution_log_id');
|
|
58
73
|
|
|
59
74
|
if (!logGroupId || !executionLogId) {
|
|
60
75
|
fail('Outputs "log_group_id" and "execution_log_id" not found. Deploy the stack first.');
|