@mikarinneoracle/oci-cdk-code-only-preview 0.0.26 → 0.0.27
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 +10 -0
- package/bin/deploy-code-only.js +37 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -142,6 +142,16 @@ entrypoint: node func.js
|
|
|
142
142
|
|
|
143
143
|
Keep `@fnproject/fdk` in `package.json` dependencies. The function source file uses `fdk.handle(...)`; it is not the OCI handler value.
|
|
144
144
|
|
|
145
|
+
For Java, the code-only archive must contain exactly one fat/uber JAR at the ZIP root. Build it first and point OCDK to it when necessary:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
export OCI_CODE_ONLY_RUNTIME_NAME='java21.ol9'
|
|
149
|
+
export OCI_FUNCTION_HANDLER='com.example.fn.HelloFunction::handleRequest'
|
|
150
|
+
export OCI_FUNCTION_JAR_PATH='target/my-function.jar'
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
If exactly one non-source JAR exists in the project root or `target/`, `OCI_FUNCTION_JAR_PATH` is optional. Java archives do not contain the project source tree or a `function/` directory.
|
|
154
|
+
|
|
145
155
|
#### Find the available code-only runtimes
|
|
146
156
|
|
|
147
157
|
The exact `OCI_CODE_ONLY_RUNTIME_NAME` values are enabled per tenancy and region during this Limited Availability preview. Query the Preview CLI instead of copying a runtime name from another environment:
|
package/bin/deploy-code-only.js
CHANGED
|
@@ -94,6 +94,28 @@ function preparePackageManifest(archiveRoot) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
function resolveJavaJar() {
|
|
98
|
+
const configuredPath = (process.env.OCI_CODE_ONLY_JAR_PATH || process.env.OCI_FUNCTION_JAR_PATH || '').trim();
|
|
99
|
+
if (configuredPath) {
|
|
100
|
+
const jarPath = path.resolve(projectDir, configuredPath);
|
|
101
|
+
if (!fs.existsSync(jarPath) || !fs.statSync(jarPath).isFile() || !jarPath.endsWith('.jar')) {
|
|
102
|
+
fail(`OCI_FUNCTION_JAR_PATH must point to an existing .jar file: ${jarPath}`);
|
|
103
|
+
}
|
|
104
|
+
return jarPath;
|
|
105
|
+
}
|
|
106
|
+
const candidates = [projectDir, path.join(projectDir, 'target')]
|
|
107
|
+
.flatMap((directory) => {
|
|
108
|
+
if (!fs.existsSync(directory)) return [];
|
|
109
|
+
return fs.readdirSync(directory)
|
|
110
|
+
.filter((name) => name.endsWith('.jar') && !name.endsWith('-sources.jar') && !name.endsWith('-javadoc.jar') && !name.startsWith('original-'))
|
|
111
|
+
.map((name) => path.join(directory, name));
|
|
112
|
+
});
|
|
113
|
+
const uniqueCandidates = [...new Set(candidates)];
|
|
114
|
+
if (uniqueCandidates.length === 1) return uniqueCandidates[0];
|
|
115
|
+
const found = uniqueCandidates.length ? ` Found: ${uniqueCandidates.join(', ')}` : '';
|
|
116
|
+
fail(`Java code-only deploy requires exactly one fat/uber JAR. Build the function first, or set OCI_FUNCTION_JAR_PATH to the JAR file.${found}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
97
119
|
function createArchive(functionName, runtimeName) {
|
|
98
120
|
if (!fs.existsSync(projectDir) || !fs.statSync(projectDir).isDirectory()) {
|
|
99
121
|
fail(`source directory does not exist: ${projectDir}`);
|
|
@@ -101,8 +123,22 @@ function createArchive(functionName, runtimeName) {
|
|
|
101
123
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ocdk-code-only-'));
|
|
102
124
|
const archiveFileName = codeOnlyArchiveFileName(functionName);
|
|
103
125
|
const archivePath = path.join(projectDir, archiveFileName);
|
|
104
|
-
const
|
|
126
|
+
const isJavaRuntime = runtimeName.toLowerCase().startsWith('java');
|
|
105
127
|
const isNodeRuntime = runtimeName.toLowerCase().startsWith('node');
|
|
128
|
+
if (isJavaRuntime) {
|
|
129
|
+
const jarPath = resolveJavaJar();
|
|
130
|
+
const jarName = path.basename(jarPath);
|
|
131
|
+
fs.copyFileSync(jarPath, path.join(tempDir, jarName));
|
|
132
|
+
fs.rmSync(archivePath, { force: true });
|
|
133
|
+
const zip = spawnSync('zip', ['-q', '-r', archivePath, jarName], { cwd: tempDir, encoding: 'utf8', shell: false });
|
|
134
|
+
if (zip.error || zip.status !== 0) {
|
|
135
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
136
|
+
fs.rmSync(archivePath, { force: true });
|
|
137
|
+
fail(`could not create Java archive with zip: ${zip.stderr?.trim() || zip.error?.message || 'unknown error'}`);
|
|
138
|
+
}
|
|
139
|
+
return { tempDir, archivePath };
|
|
140
|
+
}
|
|
141
|
+
const archiveRoot = path.join(tempDir, 'function');
|
|
106
142
|
const excludedTopLevel = new Set(['node_modules', '.git', '.tools', '.terraform', 'cdktf.out', 'tail-function-logs.js', 'package-lock.json']);
|
|
107
143
|
if (!isNodeRuntime) excludedTopLevel.add('package.json');
|
|
108
144
|
fs.cpSync(projectDir, archiveRoot, {
|