chore: update cloudly dependency stack
Align Cloudly with the current typedserver, smartconfig, smartstate, and Docker tooling releases so builds and Docker output stay compatible with the upgraded stack.
This commit is contained in:
@@ -34,10 +34,10 @@ export class ClusterNode extends plugins.smartdata.SmartDataDbDoc<
|
||||
|
||||
// INSTANCE
|
||||
@plugins.smartdata.unI()
|
||||
public id: string;
|
||||
public id!: string;
|
||||
|
||||
@plugins.smartdata.svDb()
|
||||
public data: plugins.servezoneInterfaces.data.IClusterNode['data'];
|
||||
public data!: plugins.servezoneInterfaces.data.IClusterNode['data'];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { logger } from '../logger.js';
|
||||
import * as plugins from '../plugins.js';
|
||||
import type { CloudlyNodeManager } from './classes.nodemanager.js';
|
||||
import type { Cluster } from '../manager.cluster/classes.cluster.js';
|
||||
|
||||
export class CurlFresh {
|
||||
public optionsArg = {
|
||||
@@ -39,33 +40,33 @@ bash -c "npm config set registry ${this.optionsArg.npmRegistry}"
|
||||
bash -c "pnpm install -g @serve.zone/spark"
|
||||
|
||||
# lets install the spark daemon
|
||||
bash -c "spark installdaemon"
|
||||
|
||||
# TODO: start spark with jump code
|
||||
bash -c "spark installdaemon --mode=coreflow-node --cloudlyUrl='__CLOUDLY_URL__' --jumpcode='__JUMPCODE__'"
|
||||
`,
|
||||
};
|
||||
|
||||
public nodeManagerRef: CloudlyNodeManager;
|
||||
public curlFreshRoute: plugins.typedserver.servertools.Route;
|
||||
public handler = new plugins.typedserver.servertools.Handler('ALL', async (req, res) => {
|
||||
public async handleRequest(ctx: plugins.typedserver.IRequestContext): Promise<Response> {
|
||||
logger.log('info', 'curlfresh handler called. a server might be coming online soon :)');
|
||||
const scriptname = req.params.scriptname;
|
||||
const scriptname = ctx.params.scriptname;
|
||||
switch (scriptname) {
|
||||
case 'setup.sh':
|
||||
logger.log('info', 'sending setup.sh');
|
||||
res.type('application/x-sh');
|
||||
res.send(this.scripts['setup.sh']);
|
||||
break;
|
||||
return new Response(this.scripts['setup.sh']
|
||||
.replaceAll('__CLOUDLY_URL__', ctx.url.searchParams.get('cloudlyUrl') || '')
|
||||
.replaceAll('__JUMPCODE__', ctx.url.searchParams.get('jumpcode') || ''), {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-sh',
|
||||
},
|
||||
});
|
||||
default:
|
||||
res.send('no script found');
|
||||
break;
|
||||
return new Response('no script found', { status: 404 });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
constructor(nodeManagerRefArg: CloudlyNodeManager) {
|
||||
this.nodeManagerRef = nodeManagerRefArg;
|
||||
}
|
||||
public async getServerUserData(): Promise<string> {
|
||||
public async getServerUserData(clusterArg?: Cluster): Promise<string> {
|
||||
const sslMode =
|
||||
await this.nodeManagerRef.cloudlyRef.config.appData.waitForAndGetKey('sslMode');
|
||||
let protocol: 'http' | 'https';
|
||||
@@ -80,9 +81,19 @@ bash -c "spark installdaemon"
|
||||
const port =
|
||||
await this.nodeManagerRef.cloudlyRef.config.appData.waitForAndGetKey('publicPort');
|
||||
|
||||
let cloudlyUrl = `${protocol}://${domain}:${port}/`;
|
||||
let jumpcode = '';
|
||||
if (clusterArg?.data.userId) {
|
||||
const clusterUser = await this.nodeManagerRef.cloudlyRef.authManager.CUser.getInstance({
|
||||
id: clusterArg.data.userId,
|
||||
});
|
||||
jumpcode = clusterUser?.data.tokens?.[0]?.token || '';
|
||||
cloudlyUrl = clusterArg.data.cloudlyUrl || cloudlyUrl;
|
||||
}
|
||||
|
||||
const serverUserData = `#cloud-config
|
||||
runcmd:
|
||||
- curl -o- ${protocol}://${domain}:${port}/curlfresh/setup.sh | sh
|
||||
- curl -o- '${protocol}://${domain}:${port}/curlfresh/setup.sh?cloudlyUrl=${encodeURIComponent(cloudlyUrl)}&jumpcode=${encodeURIComponent(jumpcode)}' | sh
|
||||
`;
|
||||
console.log(serverUserData);
|
||||
return serverUserData;
|
||||
|
||||
@@ -9,7 +9,7 @@ export class CloudlyNodeManager {
|
||||
public typedRouter = new plugins.typedrequest.TypedRouter();
|
||||
public curlfreshInstance = new CurlFresh(this);
|
||||
|
||||
public hetznerAccount: plugins.hetznercloud.HetznerAccount;
|
||||
public hetznerAccount?: plugins.hetznercloud.HetznerAccount;
|
||||
|
||||
public get db() {
|
||||
return this.cloudlyRef.mongodbConnector.smartdataDb;
|
||||
@@ -65,13 +65,17 @@ export class CloudlyNodeManager {
|
||||
console.log(`Skipping node provisioning for cluster ${cluster.id} - setupMode is ${cluster.data.setupMode || 'manual'}`);
|
||||
continue;
|
||||
}
|
||||
const hetznerAccount = this.hetznerAccount;
|
||||
if (!hetznerAccount) {
|
||||
throw new Error('Hetzner account is not configured');
|
||||
}
|
||||
|
||||
// get existing nodes
|
||||
const nodes = await this.getNodesByCluster(cluster);
|
||||
|
||||
// if there is no node, create one
|
||||
if (nodes.length === 0) {
|
||||
const hetznerServer = await this.hetznerAccount.createServer({
|
||||
const hetznerServer = await hetznerAccount.createServer({
|
||||
name: plugins.smartunique.uniSimple('node'),
|
||||
location: 'nbg1',
|
||||
type: 'cpx41',
|
||||
@@ -79,7 +83,7 @@ export class CloudlyNodeManager {
|
||||
clusterId: cluster.id,
|
||||
priority: '1',
|
||||
},
|
||||
userData: await this.curlfreshInstance.getServerUserData(),
|
||||
userData: await this.curlfreshInstance.getServerUserData(cluster),
|
||||
});
|
||||
|
||||
// First create BareMetal record
|
||||
@@ -94,12 +98,12 @@ export class CloudlyNodeManager {
|
||||
);
|
||||
// if there is a node, make sure that it exists
|
||||
for (const node of nodes) {
|
||||
const hetznerServers = await this.hetznerAccount.getServersByLabel({
|
||||
const hetznerServers = await hetznerAccount.getServersByLabel({
|
||||
clusterId: cluster.id,
|
||||
});
|
||||
if (!hetznerServers || hetznerServers.length === 0) {
|
||||
console.log(`node ${node.id} does not exist in the real world. Creating it now...`);
|
||||
const hetznerServer = await this.hetznerAccount.createServer({
|
||||
const hetznerServer = await hetznerAccount.createServer({
|
||||
name: plugins.smartunique.uniSimple('node'),
|
||||
location: 'nbg1',
|
||||
type: 'cpx41',
|
||||
@@ -107,6 +111,7 @@ export class CloudlyNodeManager {
|
||||
clusterId: cluster.id,
|
||||
priority: '1',
|
||||
},
|
||||
userData: await this.curlfreshInstance.getServerUserData(cluster),
|
||||
});
|
||||
|
||||
// First create BareMetal record
|
||||
|
||||
Reference in New Issue
Block a user