@mikarinneoracle/oci-cdk-code-only-preview 0.0.32 → 0.0.34

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 CHANGED
@@ -105,6 +105,15 @@ The repository-local preview installation is required only for preview-only feat
105
105
 
106
106
  Code-only deployment first uses Terraform to create or manage the Function Application and its networking/logging resources. It then uploads a ZIP archive directly to OCI Functions with OCI CLI preview. OCI builds and manages the execution image: no Docker build, OCIR repository, or image push occurs.
107
107
 
108
+ After the Function App exists, use the direct OCI CLI upload command to update only the code-only function and skip Terraform entirely:
109
+
110
+ ```bash
111
+ export OCI_FUNCTION_APP_ID='ocid1.fnapp.oc1...'
112
+ npx ocdk deploy-code-only
113
+ ```
114
+
115
+ `deploy-code-only` requires `OCI_FUNCTION_APP_ID`; it does not create, look up, or change the Function App, API Gateway, networking, logging, or Terraform state.
116
+
108
117
  Activate the path with either `-code-only`, `--code-only`, or `OCI_CODE_ONLY=1`. The compatibility environment key `code-only=1` is also recognized when a process launcher can set a hyphenated environment name.
109
118
 
110
119
  ```bash
@@ -184,7 +193,7 @@ export OCI_FUNCTION_APP_NAME='my-existing-function-app'
184
193
 
185
194
  These settings are optional: `OCI_CODE_ONLY_SOURCE_DIR` (defaults to the current directory), `OCI_FUNCTION_MEMORY_MB` (from `func.yaml`, otherwise `256`), and `OCI_FUNCTION_TIMEOUT_SECONDS` (from `func.yaml`, otherwise `30`). `OCI_TENANCY_ID`, `OCI_REGION`, and `OCI_NAMESPACE` are also optional when they can be resolved from the active OCI CLI profile.
186
195
 
187
- Each deploy re-builds `<function-name>.zip` in the project root and uploads that file. For Python and Node.js, source files are at the ZIP root because OCI extracts the archive into `/function`; this makes a standard Python entrypoint such as `/python/bin/fdk /function/func.py handler` resolve correctly. The archive excludes `node_modules`, `package-lock.json`, `.git`, `.tools`, `.terraform`, `cdktf.out`, and the generated `.ocdk/` directory. For Node.js functions, a sanitized `package.json` remains so OCI can install the FDK and other dependencies; OCDK removes its own package dependency (`@mikarinneoracle/oci-cdk-code-only-preview`, and the legacy package name) from that copied manifest. For Python and Java code-only functions, `package.json` is excluded entirely. A successful code-only destroy removes this ZIP after Terraform has destroyed the Function App and infrastructure. With the default `OCI_STACK_ACTION=full-stack`, OCDK creates the API Gateway and uses a Terraform data source to resolve the CLI-managed function OCID for its route. The first code-only deploy therefore runs Terraform once to create the Function App, uploads the function, then runs Terraform again to create the Gateway deployment. Set `OCI_STACK_ACTION=function-only` to omit API Gateway.
196
+ Each deploy re-builds `<function-name>.zip` in the project root and uploads that file. The ZIP has the required `function/` directory at its root and excludes `node_modules`, `package-lock.json`, `.git`, `.tools`, `.terraform`, `cdktf.out`, and the generated `.ocdk/` directory. For Python, OCDK automatically changes Fn's normal `/function/func.py` handler path to `/function/function/func.py`, matching the required archive layout. For Node.js functions, a sanitized `package.json` remains so OCI can install the FDK and other dependencies; OCDK removes its own package dependency (`@mikarinneoracle/oci-cdk-code-only-preview`, and the legacy package name) from that copied manifest. For Python and Java code-only functions, `package.json` is excluded entirely. A successful code-only destroy removes this ZIP after Terraform has destroyed the Function App and infrastructure. With the default `OCI_STACK_ACTION=full-stack`, OCDK creates the API Gateway and uses a Terraform data source to resolve the CLI-managed function OCID for its route. The first code-only deploy therefore runs Terraform once to create the Function App, uploads the function, then runs Terraform again to create the Gateway deployment. Set `OCI_STACK_ACTION=function-only` to omit API Gateway.
188
197
 
189
198
  After a successful code-only deploy, OCDK writes the log IDs for `npx ocdk tail:execution-log` automatically.
190
199
 
@@ -98,9 +98,15 @@ function readFunctionMetadata() {
98
98
  const configuredHandler = (process.env.OCI_FUNCTION_HANDLER || yamlValue(yaml, 'cmd') || yamlValue(yaml, 'entrypoint')).trim();
99
99
  // The managed Node runtime already invokes `node`; its handler is the script
100
100
  // path, whereas a conventional func.yaml entrypoint is `node func.js`.
101
+ const isPythonRuntime = runtimeName.toLowerCase().startsWith('python');
101
102
  const handler = runtimeName.toLowerCase().startsWith('node')
102
103
  ? configuredHandler.replace(/^node\s+/, '')
103
- : configuredHandler;
104
+ // Code-only archives must have a function/ directory at their ZIP root.
105
+ // OCI retains that directory beneath /function, so adapt Fn's standard
106
+ // Python entrypoint path to the archive layout.
107
+ : isPythonRuntime
108
+ ? configuredHandler.replace(/\/function\/(?!function\/)/g, '/function/function/')
109
+ : configuredHandler;
104
110
  const memory = integerValue(process.env.OCI_FUNCTION_MEMORY_MB || yamlValue(yaml, 'memory'), 'OCI_FUNCTION_MEMORY_MB', 256);
105
111
  const timeout = integerValue(process.env.OCI_FUNCTION_TIMEOUT_SECONDS || yamlValue(yaml, 'timeout'), 'OCI_FUNCTION_TIMEOUT_SECONDS', 30);
106
112
 
@@ -208,11 +214,9 @@ function createArchive(functionName, runtimeName) {
208
214
  }
209
215
  return { tempDir, archivePath };
210
216
  }
211
- // OCI extracts a source archive directly into /function. Do not add a
212
- // "function/" wrapper directory here: a standard Fn Python entrypoint such
213
- // as "/python/bin/fdk /function/func.py handler" must resolve func.py at
214
- // the ZIP root after extraction.
215
- const archiveRoot = tempDir;
217
+ // OCI code-only source archives must contain a function/ directory at the
218
+ // ZIP root. Python handler paths are adapted in readFunctionMetadata().
219
+ const archiveRoot = path.join(tempDir, 'function');
216
220
  const excludedTopLevel = new Set(['node_modules', '.git', '.tools', '.terraform', 'cdktf.out', '.ocdk', 'tail-function-logs.js', 'package-lock.json']);
217
221
  if (!isNodeRuntime) excludedTopLevel.add('package.json');
218
222
  fs.cpSync(projectDir, archiveRoot, {
@@ -226,7 +230,7 @@ function createArchive(functionName, runtimeName) {
226
230
  });
227
231
  if (isNodeRuntime) preparePackageManifest(archiveRoot);
228
232
  fs.rmSync(archivePath, { force: true });
229
- const zip = spawnSync('zip', ['-q', '-r', archivePath, '.'], { cwd: tempDir, encoding: 'utf8', shell: false });
233
+ const zip = spawnSync('zip', ['-q', '-r', archivePath, 'function'], { cwd: tempDir, encoding: 'utf8', shell: false });
230
234
  if (zip.error || zip.status !== 0) {
231
235
  fs.rmSync(tempDir, { recursive: true, force: true });
232
236
  fs.rmSync(archivePath, { force: true });
package/bin/ocdk.js CHANGED
@@ -83,6 +83,7 @@ Usage: ocdk <command> [options]
83
83
 
84
84
  Commands (same as CDK):
85
85
  deploy Deploy the stack
86
+ deploy-code-only Upload/update an existing code-only Function App without Terraform
86
87
  diff Compare stack with current state
87
88
  synth Synthesize Terraform
88
89
  destroy Destroy the stack
@@ -155,6 +156,32 @@ if (command === 'tail:execution-log') {
155
156
 
156
157
  // Code-only Functions use CDKTF for the Function Application/infrastructure,
157
158
  // then OCI CLI preview for the archive-function itself.
159
+ if (command === 'deploy-code-only') {
160
+ const projectDir = process.cwd();
161
+ const script = path.join(root, 'bin', 'deploy-code-only.js');
162
+ const applicationId = process.env.OCI_FUNCTION_APP_ID?.trim();
163
+ if (!script || !fs.existsSync(script)) {
164
+ console.error('Missing script: "deploy-code-only". Update @mikarinneoracle/oci-cdk-code-only-preview.');
165
+ process.exit(1);
166
+ }
167
+ if (!applicationId) {
168
+ console.error('Code-only deploy failed: OCI_FUNCTION_APP_ID is required for "ocdk deploy-code-only". This command does not run Terraform to create or discover the Function App.');
169
+ process.exit(1);
170
+ }
171
+ const result = spawnSync('node', [script, ...args.slice(1)], {
172
+ stdio: 'inherit',
173
+ cwd: projectDir,
174
+ shell: false,
175
+ env: {
176
+ ...process.env,
177
+ OCI_CODE_ONLY: '1',
178
+ OCI_PROJECT_DIR: projectDir,
179
+ OCI_FUNCTION_APP_ID: applicationId,
180
+ },
181
+ });
182
+ process.exit(result.status ?? 1);
183
+ }
184
+
158
185
  if (command === 'deploy' && codeOnlyEnabled) {
159
186
  const projectDir = process.cwd();
160
187
  const script = path.join(root, 'bin', 'deploy-code-only.js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikarinneoracle/oci-cdk-code-only-preview",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "description": "OCI CDK stack for OCI Functions, API Gateway, and related infrastructure",
5
5
  "main": "lib/index.js",
6
6
  "bin": {