openkbs 0.0.60 → 0.0.63
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/package.json +1 -1
- package/src/actions.js +115 -8
- package/src/index.js +13 -11
- package/version.json +3 -3
package/package.json
CHANGED
package/src/actions.js
CHANGED
|
@@ -931,7 +931,7 @@ async function fnAction(subCommand, args = []) {
|
|
|
931
931
|
switch (subCommand) {
|
|
932
932
|
case 'list':
|
|
933
933
|
return await fnListAction(kbToken);
|
|
934
|
-
case '
|
|
934
|
+
case 'push':
|
|
935
935
|
return await fnDeployAction(kbToken, args[0], args.slice(1));
|
|
936
936
|
case 'delete':
|
|
937
937
|
return await fnDeleteAction(kbToken, args[0]);
|
|
@@ -946,13 +946,13 @@ async function fnAction(subCommand, args = []) {
|
|
|
946
946
|
console.log('');
|
|
947
947
|
console.log('Commands:');
|
|
948
948
|
console.log(' list List all elastic functions');
|
|
949
|
-
console.log('
|
|
949
|
+
console.log(' push <name> Push a function from ./functions/<name>/');
|
|
950
950
|
console.log(' delete <name> Delete a function');
|
|
951
951
|
console.log(' logs <name> View function logs');
|
|
952
952
|
console.log(' env <name> [KEY=value] View or set environment variables');
|
|
953
953
|
console.log(' invoke <name> [payload] Invoke a function');
|
|
954
954
|
console.log('');
|
|
955
|
-
console.log('Options for
|
|
955
|
+
console.log('Options for push:');
|
|
956
956
|
console.log(' --region <region> Region (us-east-1, eu-central-1, ap-southeast-1)');
|
|
957
957
|
console.log(' --memory <mb> Memory size (128-3008 MB)');
|
|
958
958
|
console.log(' --timeout <seconds> Timeout (1-900 seconds)');
|
|
@@ -1005,6 +1005,8 @@ async function fnDeployAction(kbToken, functionName, args) {
|
|
|
1005
1005
|
let region = findRegion();
|
|
1006
1006
|
let memorySize = 256;
|
|
1007
1007
|
let timeout = 30;
|
|
1008
|
+
let runtime = null; // null = use default (nodejs24.x)
|
|
1009
|
+
let handler = null; // null = use default (index.handler)
|
|
1008
1010
|
|
|
1009
1011
|
for (let i = 0; i < args.length; i++) {
|
|
1010
1012
|
if (args[i] === '--region' && args[i + 1]) {
|
|
@@ -1013,6 +1015,10 @@ async function fnDeployAction(kbToken, functionName, args) {
|
|
|
1013
1015
|
memorySize = parseInt(args[++i]);
|
|
1014
1016
|
} else if (args[i] === '--timeout' && args[i + 1]) {
|
|
1015
1017
|
timeout = parseInt(args[++i]);
|
|
1018
|
+
} else if (args[i] === '--runtime' && args[i + 1]) {
|
|
1019
|
+
runtime = args[++i];
|
|
1020
|
+
} else if (args[i] === '--handler' && args[i + 1]) {
|
|
1021
|
+
handler = args[++i];
|
|
1016
1022
|
}
|
|
1017
1023
|
}
|
|
1018
1024
|
|
|
@@ -1082,7 +1088,7 @@ async function fnDeployAction(kbToken, functionName, args) {
|
|
|
1082
1088
|
} else {
|
|
1083
1089
|
// Create new function
|
|
1084
1090
|
console.log('Creating new function...');
|
|
1085
|
-
|
|
1091
|
+
const createParams = {
|
|
1086
1092
|
token: kbToken,
|
|
1087
1093
|
action: 'createElasticFunction',
|
|
1088
1094
|
functionName,
|
|
@@ -1090,7 +1096,10 @@ async function fnDeployAction(kbToken, functionName, args) {
|
|
|
1090
1096
|
region,
|
|
1091
1097
|
memorySize,
|
|
1092
1098
|
timeout
|
|
1093
|
-
}
|
|
1099
|
+
};
|
|
1100
|
+
if (runtime) createParams.runtime = runtime;
|
|
1101
|
+
if (handler) createParams.handler = handler;
|
|
1102
|
+
response = await makePostRequest(KB_API_URL, createParams);
|
|
1094
1103
|
}
|
|
1095
1104
|
|
|
1096
1105
|
if (response.error) {
|
|
@@ -1837,11 +1846,20 @@ async function siteAction(subCommand, args = []) {
|
|
|
1837
1846
|
const { kbToken } = await fetchKBJWT(kbId);
|
|
1838
1847
|
|
|
1839
1848
|
switch (subCommand) {
|
|
1840
|
-
case '
|
|
1849
|
+
case 'push':
|
|
1850
|
+
// If a folder path is provided, use it
|
|
1851
|
+
if (args.length > 0 && args[0] && !args[0].startsWith('-')) {
|
|
1852
|
+
const customDir = path.resolve(process.cwd(), args[0]);
|
|
1853
|
+
if (fs.existsSync(customDir) && fs.statSync(customDir).isDirectory()) {
|
|
1854
|
+
siteDir = customDir;
|
|
1855
|
+
} else {
|
|
1856
|
+
return console.red(`Directory not found: ${args[0]}`);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1841
1859
|
return await siteDeployAction(kbToken, kbId, siteDir, args);
|
|
1842
1860
|
default:
|
|
1843
1861
|
console.log('Site management commands:\n');
|
|
1844
|
-
console.log(' openkbs site
|
|
1862
|
+
console.log(' openkbs site push [folder] Upload files to S3 (defaults to current dir or site/)');
|
|
1845
1863
|
console.log('\nRun from a folder containing settings.json with kbId, or from parent with site/ subdirectory');
|
|
1846
1864
|
}
|
|
1847
1865
|
}
|
|
@@ -2113,6 +2131,94 @@ async function pulsePublishAction(kbToken, channel, message) {
|
|
|
2113
2131
|
}
|
|
2114
2132
|
}
|
|
2115
2133
|
|
|
2134
|
+
/**
|
|
2135
|
+
* Deploy from openkbs.json config file
|
|
2136
|
+
* Enables elastic services and deploys functions/site
|
|
2137
|
+
*/
|
|
2138
|
+
async function elasticDeployAction() {
|
|
2139
|
+
// Find openkbs.json
|
|
2140
|
+
const configPaths = [
|
|
2141
|
+
path.join(process.cwd(), 'openkbs.json'),
|
|
2142
|
+
path.join(process.cwd(), '..', 'openkbs.json')
|
|
2143
|
+
];
|
|
2144
|
+
|
|
2145
|
+
let configPath = null;
|
|
2146
|
+
for (const p of configPaths) {
|
|
2147
|
+
if (fs.existsSync(p)) {
|
|
2148
|
+
configPath = p;
|
|
2149
|
+
break;
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
if (!configPath) {
|
|
2154
|
+
return console.red('openkbs.json not found. Create one with your deployment config.');
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
2158
|
+
const projectDir = path.dirname(configPath);
|
|
2159
|
+
const region = config.region || findRegion() || 'us-east-1';
|
|
2160
|
+
|
|
2161
|
+
console.log(`Deploying ${config.name || 'project'} to ${region}...`);
|
|
2162
|
+
|
|
2163
|
+
// Get KB token
|
|
2164
|
+
const settings = findSettings();
|
|
2165
|
+
if (!settings?.kbId) {
|
|
2166
|
+
return console.red('No kbId found. Run from a directory with settings.json');
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
const res = await fetchKBJWT(settings.kbId);
|
|
2170
|
+
if (!res?.kbToken) {
|
|
2171
|
+
return console.red(`KB ${settings.kbId} not found`);
|
|
2172
|
+
}
|
|
2173
|
+
const kbToken = res.kbToken;
|
|
2174
|
+
|
|
2175
|
+
// Deploy elastic services if configured
|
|
2176
|
+
if (config.elastic) {
|
|
2177
|
+
console.log('\nEnabling Elastic services...');
|
|
2178
|
+
const elasticRes = await makePostRequest(KB_API_URL, {
|
|
2179
|
+
token: kbToken,
|
|
2180
|
+
action: 'deployElastic',
|
|
2181
|
+
elastic: config.elastic
|
|
2182
|
+
});
|
|
2183
|
+
|
|
2184
|
+
if (elasticRes.error) {
|
|
2185
|
+
console.red('Elastic deploy error:', elasticRes.error);
|
|
2186
|
+
} else {
|
|
2187
|
+
if (elasticRes.pulse?.enabled) console.green(' ✓ Pulse enabled');
|
|
2188
|
+
if (elasticRes.postgres?.enabled) console.green(' ✓ Postgres enabled');
|
|
2189
|
+
if (elasticRes.storage?.enabled) console.green(' ✓ Storage enabled');
|
|
2190
|
+
if (elasticRes.storage?.cloudfront) console.green(' ✓ CloudFront configured');
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
// Deploy functions if configured
|
|
2195
|
+
if (config.functions && config.functions.length > 0) {
|
|
2196
|
+
console.log('\nDeploying functions...');
|
|
2197
|
+
for (const fnName of config.functions) {
|
|
2198
|
+
const fnConfig = typeof fnName === 'object' ? fnName : { name: fnName };
|
|
2199
|
+
const name = fnConfig.name || fnName;
|
|
2200
|
+
|
|
2201
|
+
const args = ['--region', region];
|
|
2202
|
+
if (fnConfig.memory) args.push('--memory', String(fnConfig.memory));
|
|
2203
|
+
if (fnConfig.timeout) args.push('--timeout', String(fnConfig.timeout));
|
|
2204
|
+
if (fnConfig.runtime) args.push('--runtime', fnConfig.runtime);
|
|
2205
|
+
if (fnConfig.handler) args.push('--handler', fnConfig.handler);
|
|
2206
|
+
|
|
2207
|
+
console.log(` Deploying ${name}...`);
|
|
2208
|
+
await fnDeployAction(kbToken, name, args);
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// Deploy site if configured
|
|
2213
|
+
if (config.site) {
|
|
2214
|
+
console.log('\nDeploying site...');
|
|
2215
|
+
const sitePath = path.resolve(projectDir, config.site);
|
|
2216
|
+
await siteDeployAction(kbToken, settings.kbId, sitePath, []);
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
console.green('\nDeploy complete!');
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2116
2222
|
module.exports = {
|
|
2117
2223
|
signAction,
|
|
2118
2224
|
loginAction,
|
|
@@ -2138,5 +2244,6 @@ module.exports = {
|
|
|
2138
2244
|
siteAction,
|
|
2139
2245
|
storageAction,
|
|
2140
2246
|
postgresAction,
|
|
2141
|
-
pulseAction
|
|
2247
|
+
pulseAction,
|
|
2248
|
+
elasticDeployAction
|
|
2142
2249
|
};
|
package/src/index.js
CHANGED
|
@@ -18,7 +18,8 @@ const {
|
|
|
18
18
|
siteAction,
|
|
19
19
|
storageAction,
|
|
20
20
|
postgresAction,
|
|
21
|
-
pulseAction
|
|
21
|
+
pulseAction,
|
|
22
|
+
elasticDeployAction
|
|
22
23
|
} = require('./actions');
|
|
23
24
|
|
|
24
25
|
|
|
@@ -113,16 +114,17 @@ program
|
|
|
113
114
|
.action(describeAction);
|
|
114
115
|
|
|
115
116
|
program
|
|
116
|
-
.command('deploy
|
|
117
|
-
.description('
|
|
118
|
-
.action(
|
|
117
|
+
.command('deploy')
|
|
118
|
+
.description('Deploy from openkbs.json - enables elastic services, deploys functions and site')
|
|
119
|
+
.action(elasticDeployAction)
|
|
119
120
|
.addHelpText('after', `
|
|
120
121
|
Examples:
|
|
121
122
|
$ openkbs deploy
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
|
|
124
|
+
Reads openkbs.json and deploys:
|
|
125
|
+
- Elastic services (pulse, postgres, storage)
|
|
126
|
+
- Functions
|
|
127
|
+
- Site
|
|
126
128
|
`);
|
|
127
129
|
|
|
128
130
|
// program
|
|
@@ -210,7 +212,7 @@ program
|
|
|
210
212
|
.addHelpText('after', `
|
|
211
213
|
Examples:
|
|
212
214
|
$ openkbs fn list List all functions
|
|
213
|
-
$ openkbs fn
|
|
215
|
+
$ openkbs fn push hello --region us-east-1 Push function from ./functions/hello/
|
|
214
216
|
$ openkbs fn delete hello Delete a function
|
|
215
217
|
$ openkbs fn logs hello View function logs
|
|
216
218
|
$ openkbs fn env hello View environment variables
|
|
@@ -224,10 +226,10 @@ program
|
|
|
224
226
|
.action((subCommand, args) => siteAction(subCommand, args))
|
|
225
227
|
.addHelpText('after', `
|
|
226
228
|
Examples:
|
|
227
|
-
$ openkbs site
|
|
229
|
+
$ openkbs site push Push site/ folder (or current dir) to S3
|
|
230
|
+
$ openkbs site push ./dist Push specific folder to S3
|
|
228
231
|
|
|
229
232
|
Run from a directory containing settings.json with kbId.
|
|
230
|
-
Files are uploaded to the whitelabel domain's files bucket.
|
|
231
233
|
`);
|
|
232
234
|
|
|
233
235
|
program
|
package/version.json
CHANGED