@mikarinneoracle/oci-cdk-code-only-preview 0.0.29 → 0.0.31
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/README.md +4 -4
- package/bin/deploy-code-only.js +42 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ Only **`OCI_COMPARTMENT_ID`** (or `OCI_COMPARTMENT_OCID`) is required for deploy
|
|
|
57
57
|
| `OCI_IMAGE_TAG` | Image tag for OCIR | func.yaml version or `latest` |
|
|
58
58
|
| `OCI_CODE_ONLY` | When `1`, use the Code-only Functions ZIP deploy path | `0` |
|
|
59
59
|
| `OCI_CODE_ONLY_SOURCE_DIR` | Source directory to archive for code-only deploy | current directory |
|
|
60
|
-
| `OCI_CODE_ONLY_RUNTIME_NAME` |
|
|
60
|
+
| `OCI_CODE_ONLY_RUNTIME_NAME` | Optional explicit OCI Functions runtime name for code-only deploy (for example `python312.ol9`). OCDK resolves Python automatically from `func.yaml`. | — |
|
|
61
61
|
| **API Gateway** | | |
|
|
62
62
|
| `OCI_APIGATEWAY_DEPLOYMENT_JSON` | Path to deployment spec JSON | `oci_apigateway_deployment.json` in project root |
|
|
63
63
|
| **Stack / networking** | | |
|
|
@@ -115,8 +115,8 @@ export OCI_CLI_PATH="/Users/MRINNE/projects/ocdk/.tools/oci-preview-bin/oci"
|
|
|
115
115
|
# Required: OCI target
|
|
116
116
|
export OCI_COMPARTMENT_ID='ocid1.compartment.oc1...'
|
|
117
117
|
|
|
118
|
-
# Required:
|
|
119
|
-
export OCI_CODE_ONLY_RUNTIME_NAME='python312.ol9'
|
|
118
|
+
# Required: handler. OCDK resolves the latest available Python runtime.
|
|
119
|
+
# Optionally pin one: export OCI_CODE_ONLY_RUNTIME_NAME='python312.ol9'
|
|
120
120
|
export OCI_FUNCTION_HANDLER='func.handler'
|
|
121
121
|
|
|
122
122
|
# Required in func.yaml: name: my-function
|
|
@@ -161,7 +161,7 @@ OCDK also runs this build automatically when no artifact exists yet, and searche
|
|
|
161
161
|
|
|
162
162
|
#### Find the available code-only runtimes
|
|
163
163
|
|
|
164
|
-
The exact `OCI_CODE_ONLY_RUNTIME_NAME` values are enabled per tenancy and region during this Limited Availability preview. Query the Preview CLI
|
|
164
|
+
The exact `OCI_CODE_ONLY_RUNTIME_NAME` values are enabled per tenancy and region during this Limited Availability preview. For Python, OCDK queries this list automatically and selects the newest matching runtime when `func.yaml` contains `runtime: python` (or a versioned value such as `python3.12`). Set `OCI_CODE_ONLY_RUNTIME_NAME` to pin or override that choice. Query the Preview CLI to inspect available runtimes or when deploying another language:
|
|
165
165
|
|
|
166
166
|
```bash
|
|
167
167
|
# List every runtime available to the active OCI profile
|
package/bin/deploy-code-only.js
CHANGED
|
@@ -49,12 +49,52 @@ function integerValue(value, name, fallback) {
|
|
|
49
49
|
return String(parsed);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function runtimeResourceName(runtime) {
|
|
53
|
+
return runtime.name || runtime['runtime-name'] || runtime.runtimeName || runtime['runtimeName'] || '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function listItems(result) {
|
|
57
|
+
if (Array.isArray(result?.data)) return result.data;
|
|
58
|
+
if (Array.isArray(result?.data?.items)) return result.data.items;
|
|
59
|
+
if (Array.isArray(result?.items)) return result.items;
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function pythonRuntimeSortKey(runtimeName) {
|
|
64
|
+
const match = runtimeName.toLowerCase().match(/^python(\d+)/);
|
|
65
|
+
return match ? Number.parseInt(match[1], 10) : -1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function resolvePythonRuntime(runtime) {
|
|
69
|
+
// OCI's preview runtime names omit separators from the Python version:
|
|
70
|
+
// func.yaml's "python3.12" therefore maps to the runtime-list prefix
|
|
71
|
+
// "python312". A plain "python" selects the newest available version.
|
|
72
|
+
const normalizedRuntime = runtime.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
73
|
+
const namePrefix = normalizedRuntime === 'python' ? 'python' : normalizedRuntime;
|
|
74
|
+
const result = jsonOci(['fn', 'runtime', 'list', '--all', '--name-starts-with', namePrefix]);
|
|
75
|
+
const candidates = listItems(result)
|
|
76
|
+
.map(runtimeResourceName)
|
|
77
|
+
.filter((name) => name.toLowerCase().startsWith(namePrefix));
|
|
78
|
+
if (!candidates.length) {
|
|
79
|
+
fail(`no available code-only runtime matches ${runtime}. Set OCI_CODE_ONLY_RUNTIME_NAME to a runtime returned by "oci fn runtime list --all".`);
|
|
80
|
+
}
|
|
81
|
+
candidates.sort((left, right) => {
|
|
82
|
+
const versionDifference = pythonRuntimeSortKey(right) - pythonRuntimeSortKey(left);
|
|
83
|
+
return versionDifference || right.localeCompare(left);
|
|
84
|
+
});
|
|
85
|
+
const selected = candidates[0];
|
|
86
|
+
console.log(`Selected OCI code-only runtime ${selected} for func.yaml runtime ${runtime}. Set OCI_CODE_ONLY_RUNTIME_NAME to pin a different runtime.`);
|
|
87
|
+
return selected;
|
|
88
|
+
}
|
|
89
|
+
|
|
52
90
|
function readFunctionMetadata() {
|
|
53
91
|
const funcYamlPath = path.join(projectDir, 'func.yaml');
|
|
54
92
|
const yaml = fs.existsSync(funcYamlPath) ? fs.readFileSync(funcYamlPath, 'utf8') : '';
|
|
55
93
|
const functionName = (process.env.OCI_FUNCTION_NAME || yamlValue(yaml, 'name')).trim();
|
|
56
94
|
const appName = (process.env.OCI_FUNCTION_APP_NAME || functionName).trim();
|
|
57
|
-
const
|
|
95
|
+
const configuredRuntime = yamlValue(yaml, 'runtime');
|
|
96
|
+
const runtimeName = (process.env.OCI_CODE_ONLY_RUNTIME_NAME || '').trim()
|
|
97
|
+
|| (configuredRuntime.toLowerCase().startsWith('python') ? resolvePythonRuntime(configuredRuntime) : '');
|
|
58
98
|
const configuredHandler = (process.env.OCI_FUNCTION_HANDLER || yamlValue(yaml, 'cmd') || yamlValue(yaml, 'entrypoint')).trim();
|
|
59
99
|
// The managed Node runtime already invokes `node`; its handler is the script
|
|
60
100
|
// path, whereas a conventional func.yaml entrypoint is `node func.js`.
|
|
@@ -66,7 +106,7 @@ function readFunctionMetadata() {
|
|
|
66
106
|
|
|
67
107
|
if (!functionName) fail('set OCI_FUNCTION_NAME or add name: to func.yaml.');
|
|
68
108
|
if (!appName) fail('set OCI_FUNCTION_APP_NAME.');
|
|
69
|
-
if (!runtimeName) fail('set OCI_CODE_ONLY_RUNTIME_NAME (for example python312.ol9).');
|
|
109
|
+
if (!runtimeName) fail('set OCI_CODE_ONLY_RUNTIME_NAME (for example python312.ol9). Automatic runtime resolution currently supports Python functions with runtime: python in func.yaml.');
|
|
70
110
|
if (!handler) fail('set OCI_FUNCTION_HANDLER or add cmd: to func.yaml.');
|
|
71
111
|
|
|
72
112
|
return { functionName, appName, handler, runtimeName, memory, timeout };
|