Skip to content

Commit

Permalink
perf(dashmate)!: disable config auto render (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic authored Oct 24, 2023
1 parent c97a0c9 commit 87fb68c
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 54 deletions.
4 changes: 4 additions & 0 deletions packages/dashmate/configs/defaults/getLocalConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
} = require('../../src/constants');

const Config = require('../../src/config/Config');
const { SSL_PROVIDERS } = require('../../src/constants');

/**
* @param {getBaseConfig} getBaseConfig
Expand Down Expand Up @@ -34,6 +35,9 @@ function getLocalConfigFactory(getBaseConfig) {
platform: {
dapi: {
envoy: {
ssl: {
provider: SSL_PROVIDERS.SELF_SIGNED,
},
http: {
port: 2443,
},
Expand Down
11 changes: 11 additions & 0 deletions packages/dashmate/src/commands/config/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class ConfigCreateCommand extends BaseCommand {
/**
* @param {Object} args
* @param {Object} flags
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {ConfigFileJsonRepository} configFileRepository
* @param {ConfigFile} configFile
* @return {Promise<void>}
*/
Expand All @@ -13,10 +16,18 @@ class ConfigCreateCommand extends BaseCommand {
from: fromConfigName,
},
flags,
renderServiceTemplates,
writeServiceConfigs,
configFileRepository,
configFile,
) {
configFile.createConfig(configName, fromConfigName);

configFileRepository.write(configFile);

const serviceConfigs = renderServiceTemplates(configFile.getConfig(configName));
writeServiceConfigs(configName, serviceConfigs);

// eslint-disable-next-line no-console
console.log(`${configName} created`);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/dashmate/src/commands/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ class ConfigCommand extends ConfigBaseCommand {
* @param {Object} args
* @param {Object} flags
* @param {Config} config
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @return {Promise<void>}
*/
async runWithDependencies(
args,
flags,
config,
renderServiceTemplates,
writeServiceConfigs,
) {
const output = `${config.getName()} config:\n\n${inspect(
config.getOptions(),
{ colors: true, depth: null, maxArrayLength: 2 },
)}`;

const serviceConfigs = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigs);

// eslint-disable-next-line no-console
console.log(output);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/dashmate/src/commands/config/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class ConfigRemoveCommand extends BaseCommand {
* @param {Object} flags
* @param {ConfigFile} configFile
* @param {DefaultConfigs} defaultConfigs
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {ConfigFileJsonRepository} configFileRepository
* @return {Promise<void>}
*/
async runWithDependencies(
Expand All @@ -15,13 +18,21 @@ class ConfigRemoveCommand extends BaseCommand {
flags,
configFile,
defaultConfigs,
renderServiceTemplates,
writeServiceConfigs,
configFileRepository,
) {
if (defaultConfigs.has(configName)) {
throw new Error(`system config ${configName} can't be removed.\nPlease use 'dashmate reset --hard --config=${configName}' command to reset the configuration`);
}

configFile.removeConfig(configName);

configFileRepository.write(configFile);

const serviceConfigs = renderServiceTemplates(configFile.getConfig(configName));
writeServiceConfigs(configName, serviceConfigs);

// eslint-disable-next-line no-console
console.log(`${configName} removed`);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/dashmate/src/commands/config/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class ConfigSetCommand extends ConfigBaseCommand {
* @param args
* @param flags
* @param {Config} config
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {ConfigFileJsonRepository} configFileRepository
* @param {ConfigFile} configFile
* @return {Promise<void>}
*/
async runWithDependencies(
Expand All @@ -14,6 +18,10 @@ class ConfigSetCommand extends ConfigBaseCommand {
},
flags,
config,
renderServiceTemplates,
writeServiceConfigs,
configFileRepository,
configFile,
) {
// check for existence
config.get(optionPath);
Expand All @@ -28,6 +36,11 @@ class ConfigSetCommand extends ConfigBaseCommand {

config.set(optionPath, value);

configFileRepository.write(configFile);

const serviceConfigs = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigs);

// eslint-disable-next-line no-console
console.log(`${optionPath} set to ${optionValue}`);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/dashmate/src/listr/tasks/resetNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const wait = require('../../util/wait');
* @param {ConfigFile} configFile
* @param {HomeDir} homeDir
* @param {generateEnvs} generateEnvs
* @param {ConfigFileJsonRepository} configFileRepository
* @return {resetNodeTask}
*/
function resetNodeTaskFactory(
Expand All @@ -23,6 +24,7 @@ function resetNodeTaskFactory(
configFile,
homeDir,
generateEnvs,
configFileRepository,
) {
/**
* @typedef {resetNodeTask}
Expand Down Expand Up @@ -131,6 +133,8 @@ function resetNodeTaskFactory(
configFile.removeConfig(config.getName());
}

configFileRepository.write(configFile);

// Remove service configs
let serviceConfigsPath = homeDir.joinPath(baseConfigName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { Listr } = require('listr2');

const {
PRESET_LOCAL,
SSL_PROVIDERS,
} = require('../../../constants');

const generateTenderdashNodeKey = require('../../../tenderdash/generateTenderdashNodeKey');
Expand All @@ -18,6 +17,8 @@ const generateRandomString = require('../../../util/generateRandomString');
* @param {configFileRepository} configFileRepository
* @param {generateHDPrivateKeys} generateHDPrivateKeys
* @param {HomeDir} homeDir
* @param {writeServiceConfigs} writeServiceConfigs
* @param {renderServiceTemplates} renderServiceTemplates
*/
function setupLocalPresetTaskFactory(
configFile,
Expand All @@ -28,6 +29,8 @@ function setupLocalPresetTaskFactory(
configFileRepository,
generateHDPrivateKeys,
homeDir,
writeServiceConfigs,
renderServiceTemplates,
) {
/**
* @typedef {setupLocalPresetTask}
Expand Down Expand Up @@ -268,16 +271,6 @@ function setupLocalPresetTaskFactory(
}
));

subTasks.push({
title: 'Save configs',
task: async () => {
configFile.setDefaultGroupName(PRESET_LOCAL);

// Persist configs
configFileRepository.write(configFile);
},
});

return new Listr(subTasks);
},
options: {
Expand All @@ -292,19 +285,29 @@ function setupLocalPresetTaskFactory(
title: 'Configure Tenderdash nodes',
task: (ctx) => configureTenderdashTask(ctx.configGroup),
},
{
title: 'Persist configs',
task: (ctx) => {
configFile.setDefaultGroupName(PRESET_LOCAL);

for (const config of ctx.configGroup) {
const serviceConfigFiles = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigFiles);
}

configFileRepository.write(configFile);
},
},
{
title: 'Configure SSL certificates',
task: (ctx) => {
const platformConfigs = ctx.configGroup.filter((config) => config.get('platform.enable'));

const subTasks = platformConfigs.map((config) => {
config.set('platform.dapi.envoy.ssl.provider', SSL_PROVIDERS.SELF_SIGNED);

return {
title: `Generate certificate for ${config.getName()}`,
task: async () => obtainSelfSignedCertificateTask(config),
};
});
const subTasks = platformConfigs.map((config) => ({
title: `Generate certificate for ${config.getName()}`,
task: async () => obtainSelfSignedCertificateTask(config),
}
));

return new Listr(subTasks);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const generateRandomString = require('../../../util/generateRandomString');
* @param {ConfigFile} configFile
* @param {generateBlsKeys} generateBlsKeys
* @param {registerMasternodeTask} registerMasternodeTask
* @param {ConfigFileJsonRepository} configFileRepository
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {obtainZeroSSLCertificateTask} obtainZeroSSLCertificateTask
Expand All @@ -34,6 +35,7 @@ function setupRegularPresetTaskFactory(
configFile,
generateBlsKeys,
registerMasternodeTask,
configFileRepository,
renderServiceTemplates,
writeServiceConfigs,
obtainZeroSSLCertificateTask,
Expand Down Expand Up @@ -150,6 +152,11 @@ function setupRegularPresetTaskFactory(
configFile.setConfig(ctx.config);
configFile.setDefaultConfigName(ctx.preset);

configFileRepository.write(configFile);

const serviceConfigFiles = renderServiceTemplates(ctx.config);
writeServiceConfigs(ctx.config.getName(), serviceConfigFiles);

// eslint-disable-next-line no-param-reassign
task.output = chalk`Node configuration completed successfully!
Expand Down
8 changes: 0 additions & 8 deletions packages/dashmate/src/oclif/command/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class BaseCommand extends Command {
async finally(err) {
// Save configs collection
if (this.container) {
const configFileRepository = this.container.resolve('configFileRepository');

if (this.container.has('configFile')) {
const configFile = this.container.resolve('configFile');

configFileRepository.write(configFile);
}

// Stop all running containers
const stopAllContainers = this.container.resolve('stopAllContainers');
const startedContainers = this.container.resolve('startedContainers');
Expand Down
8 changes: 1 addition & 7 deletions packages/dashmate/src/oclif/command/ConfigBaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConfigBaseCommand extends BaseCommand {

if (defaultConfigName === null) {
throw new Error(`Default config is not set.
You probably need to set up a node with the 'dashmate setup' command first.
You can also use the '--config' option, or set the default config with 'dashmate config default'`);
Expand All @@ -43,12 +43,6 @@ You can also use the '--config' option, or set the default config with 'dashmate
config: asValue(config),
});

const renderServiceTemplates = this.container.resolve('renderServiceTemplates');
const writeServiceConfigs = this.container.resolve('writeServiceConfigs');

const serviceConfigFiles = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigFiles);

return super.run();
}
}
Expand Down
8 changes: 0 additions & 8 deletions packages/dashmate/src/oclif/command/GroupBaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ class GroupBaseCommand extends BaseCommand {
configGroup: asValue(group),
});

const renderServiceTemplates = this.container.resolve('renderServiceTemplates');
const writeServiceConfigs = this.container.resolve('writeServiceConfigs');

for (const config of group) {
const serviceConfigFiles = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigFiles);
}

return super.run();
}
}
Expand Down
Loading

0 comments on commit 87fb68c

Please sign in to comment.