@mikarinneoracle/oci-cdk-code-only-preview 0.0.24 → 0.0.26
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 +1 -1
- package/bin/deploy-code-only.js +23 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -167,7 +167,7 @@ export OCI_FUNCTION_APP_NAME='my-existing-function-app'
|
|
|
167
167
|
|
|
168
168
|
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.
|
|
169
169
|
|
|
170
|
-
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, includes source files, and excludes `node_modules`, `.git`, `.tools`, `.terraform`, `cdktf.out`, and the generated `tail-function-logs.js`. For Node.js functions,
|
|
170
|
+
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, includes source files, and excludes `node_modules`, `package-lock.json`, `.git`, `.tools`, `.terraform`, `cdktf.out`, and the generated `tail-function-logs.js`. 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.
|
|
171
171
|
|
|
172
172
|
After a successful code-only deploy, OCDK writes the log IDs for `npx ocdk tail:execution-log` automatically.
|
|
173
173
|
|
package/bin/deploy-code-only.js
CHANGED
|
@@ -77,7 +77,24 @@ function codeOnlyArchiveFileName(functionName) {
|
|
|
77
77
|
return `${safeName || 'function'}.zip`;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function
|
|
80
|
+
function preparePackageManifest(archiveRoot) {
|
|
81
|
+
const manifestPath = path.join(archiveRoot, 'package.json');
|
|
82
|
+
if (!fs.existsSync(manifestPath)) return;
|
|
83
|
+
try {
|
|
84
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
85
|
+
for (const section of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
86
|
+
if (!manifest[section]) continue;
|
|
87
|
+
delete manifest[section]['@mikarinneoracle/oci-cdk-code-only-preview'];
|
|
88
|
+
delete manifest[section]['@mikarinneoracle/oci-cdk'];
|
|
89
|
+
if (Object.keys(manifest[section]).length === 0) delete manifest[section];
|
|
90
|
+
}
|
|
91
|
+
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
92
|
+
} catch {
|
|
93
|
+
fail('could not read package.json while preparing the code-only archive.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createArchive(functionName, runtimeName) {
|
|
81
98
|
if (!fs.existsSync(projectDir) || !fs.statSync(projectDir).isDirectory()) {
|
|
82
99
|
fail(`source directory does not exist: ${projectDir}`);
|
|
83
100
|
}
|
|
@@ -85,7 +102,9 @@ function createArchive(functionName) {
|
|
|
85
102
|
const archiveFileName = codeOnlyArchiveFileName(functionName);
|
|
86
103
|
const archivePath = path.join(projectDir, archiveFileName);
|
|
87
104
|
const archiveRoot = path.join(tempDir, 'function');
|
|
88
|
-
const
|
|
105
|
+
const isNodeRuntime = runtimeName.toLowerCase().startsWith('node');
|
|
106
|
+
const excludedTopLevel = new Set(['node_modules', '.git', '.tools', '.terraform', 'cdktf.out', 'tail-function-logs.js', 'package-lock.json']);
|
|
107
|
+
if (!isNodeRuntime) excludedTopLevel.add('package.json');
|
|
89
108
|
fs.cpSync(projectDir, archiveRoot, {
|
|
90
109
|
recursive: true,
|
|
91
110
|
filter: (sourcePath) => {
|
|
@@ -95,6 +114,7 @@ function createArchive(functionName) {
|
|
|
95
114
|
return !excludedTopLevel.has(relativePath.split(path.sep)[0]);
|
|
96
115
|
},
|
|
97
116
|
});
|
|
117
|
+
if (isNodeRuntime) preparePackageManifest(archiveRoot);
|
|
98
118
|
fs.rmSync(archivePath, { force: true });
|
|
99
119
|
const zip = spawnSync('zip', ['-q', '-r', archivePath, 'function'], { cwd: tempDir, encoding: 'utf8', shell: false });
|
|
100
120
|
if (zip.error || zip.status !== 0) {
|
|
@@ -147,7 +167,7 @@ function main() {
|
|
|
147
167
|
const metadata = readFunctionMetadata();
|
|
148
168
|
const applicationId = (process.env.OCI_FUNCTION_APP_ID || '').trim();
|
|
149
169
|
if (!applicationId) fail('Terraform output OCI_FUNCTION_APP_ID is missing. Run through "ocdk deploy --code-only".');
|
|
150
|
-
const archive = createArchive(metadata.functionName);
|
|
170
|
+
const archive = createArchive(metadata.functionName, metadata.runtimeName);
|
|
151
171
|
try {
|
|
152
172
|
const functionId = findFunctionId(applicationId, metadata.functionName);
|
|
153
173
|
const commonArgs = [
|