openkbs 0.0.62 → 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 +90 -1
- package/src/index.js +10 -8
package/package.json
CHANGED
package/src/actions.js
CHANGED
|
@@ -2131,6 +2131,94 @@ async function pulsePublishAction(kbToken, channel, message) {
|
|
|
2131
2131
|
}
|
|
2132
2132
|
}
|
|
2133
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
|
+
|
|
2134
2222
|
module.exports = {
|
|
2135
2223
|
signAction,
|
|
2136
2224
|
loginAction,
|
|
@@ -2156,5 +2244,6 @@ module.exports = {
|
|
|
2156
2244
|
siteAction,
|
|
2157
2245
|
storageAction,
|
|
2158
2246
|
postgresAction,
|
|
2159
|
-
pulseAction
|
|
2247
|
+
pulseAction,
|
|
2248
|
+
elasticDeployAction
|
|
2160
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
|