Skip to content

Commit

Permalink
Merge branch 'release/7.0' into develop
Browse files Browse the repository at this point in the history
* release/7.0:
  Fix version number
  Plugin should be extracted by default
  ENG-3730 Exclude operator internal variables
  ENG-3730 Fix extraction when no environment variable is present
  fix for https://entando.myjetbrains.com/youtrack/issue/ENG-3654
  Update warning message about references
  Changed warning message; Added plugin descriptor version;
  Changed the endpoint to extract plugins from component-manager instead of k8s-service; Added plugin environment variables extraction; Added a warning when extracting a plugin that has external config/secret maps;
  ENG-3143 Releasing version 7.0.0
  • Loading branch information
w-caffiero-entando committed Sep 20, 2022
2 parents 0f3bd85 + f979f6b commit a10afc9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
1 change: 1 addition & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ program
.description('Generates an Entando Bundle from an existing environment into the current or selected location')
.option('--env <env>', 'The location for the env.json file containing the description of the environment to export', 'env.json')
.option('--location <location>', 'The location for where to store the generated Bundle', './')
.option('--exclude-microservices', 'Whether to include microservices in the export')
.requiredOption('--code <code>', 'The code for the Bundle')
.requiredOption('--description <description>', 'The description of the Bundle')
.action(generateFromEnv);
Expand Down
80 changes: 60 additions & 20 deletions lib/env-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ const ALL_TYPES = [
'contentModel',
'asset',
'content',
'plugin',
'category',
'label',
'language',
];

var coreBaseApi, k8ssvcApi, clientId, clientSecret, apiUrlTable;
var coreBaseApi, componentManagerApi, clientId, clientSecret, apiUrlTable;

const componentDetailExtractors = {
page: (components) =>
Expand Down Expand Up @@ -480,13 +479,18 @@ const componentResponseProcessor = {
const plugins = componentsToFetch;

const schema = {
'descriptorVersion': {
key: 'descriptorVersion',
default: () => { return 'v4' }
},
'metadata.name': 'name',
'spec.image': 'image',
'spec.dbms': 'dbms',
'spec.healthCheckPath': 'healthCheckPath',
'spec.ingressPath': 'ingressPath',
'spec.roles[].code': 'roles[]',
'spec.permissions': 'permissions',
'spec.environmentVariables': 'environmentVariables',
};

return plugins.map(p => objectMapper(p, schema));
Expand Down Expand Up @@ -695,6 +699,10 @@ const processContentAttribute = function(attribute) {
return attribute;
}

const shouldExportEnvironmentVariable=function(environmentVariable) {
return environmentVariable.name != "ENTANDO_TIMESTAMP";
}

const defaultComponentDescriptorProcessor = function(type, location, code, components) {
const typePlural = typeToPlural(type);
const codeExtractor = componentCodeExtractors[type];
Expand All @@ -704,12 +712,33 @@ const defaultComponentDescriptorProcessor = function(type, location, code, compo
console.log(`Processing ${type}: ${code}`);

const descriptorName = `${typePlural}/${code}-descriptor.yaml`;
if (type == "plugin") {
if (component.environmentVariables) {
component.environmentVariables = component.environmentVariables.filter(e => shouldExportEnvironmentVariable(e));
}
}
fs.promises.writeFile(`${location}/${descriptorName}`, yaml.safeDump(component, { lineWidth: 1000000 }));

return descriptorName;
});
}

const pluginComponentDescriptorProcessor = function(type, location, code, components) {
const result = defaultComponentDescriptorProcessor(type, location, code, components);

components.forEach(c => {
if (c.environmentVariables) {
c.environmentVariables.forEach(v => {
if ('valueFrom' in v) {
console.warn(`WARNING: Extracted plugin variable "${c.name}" references a k8s secret or configmap "${v.name}" that will not be extracted`);
}
});
}
});

return result;
}

const assetComponentDescriptorProcessor = function(type, location, code, components) {
const typePlural = typeToPlural(type);
const codeExtractor = componentCodeExtractors[type];
Expand Down Expand Up @@ -788,7 +817,7 @@ const componentDescriptorProcessors = {
return assetComponentDescriptorProcessor(type, location, code, components);
},
plugin: (type, location, code, components) => {
return defaultComponentDescriptorProcessor(type, location, code, components);
return pluginComponentDescriptorProcessor(type, location, code, components);
},
group: (type, location, code, components) => {
return groupIntoSingleComponentDescriptorProcessor(type, location, code, components);
Expand Down Expand Up @@ -849,13 +878,7 @@ async function getComponents (type, componentsToFetch) {
headers: { Authorization: `Bearer ${token}` },
});

if (type === 'plugin') {
componentsToFetch = response.data._embedded &&
response.data._embedded.entandoPlugins ||
[];
} else {
componentsToFetch = response.data.payload;
}
componentsToFetch = response.data.payload;
}

// Process response and extract any aditional details
Expand Down Expand Up @@ -940,7 +963,8 @@ const collectQuestions = [
name: 'componentType',
message: 'Which type of components do you want to add to the bundle?',
choices: [
{ name: 'All components', value: 'all' },
{ name: 'All components', value: 'complete' },
{ name: 'All components no Microservices', value: 'all-no-plugin' },
{ name: 'Pages', value: 'page' },
{ name: 'Page templates', value: 'pageModel' },
{ name: 'UX Fragments', value: 'fragment' },
Expand All @@ -956,7 +980,7 @@ const collectQuestions = [
],
},
{
when: (answers) => answers.componentType !== 'all',
when: (answers) => answers.componentType !== 'all-no-plugin' && answers.componentType !== 'complete',
type: 'checkbox',
name: 'components',
message: 'Which components do you want to include in the bundle?',
Expand All @@ -977,7 +1001,7 @@ const collectQuestions = [
name: 'addMoreComponents',
message: 'Do you want to add more components to the Bundle?',
default: true,
when: (answers) => answers.componentType !== 'all',
when: (answers) => answers.componentType !== 'all-no-plugin' && answers.componentType !== 'complete',
},
];

Expand Down Expand Up @@ -1122,11 +1146,20 @@ async function inquireComponents () {
var answers;
do {
answers = await inquirer.prompt(collectQuestions);
const type = answers.componentType;
var type = answers.componentType;
var components;

if (type === 'all') {
if (type === 'all-no-plugin' || type === 'complete') {
console.log('Collecting all components from the provided environment...');
if (type === 'complete') {
ALL_TYPES.push('plugin');
type = 'plugin';
} else {
const offset=ALL_TYPES.indexOf("plugin")
if (offset != -1) {
ALL_TYPES.splice(offset,1)
}
}
components = await collectAllComponents();

for (const type of ALL_TYPES) {
Expand All @@ -1136,7 +1169,7 @@ async function inquireComponents () {
components = answers.components;
allAnswers[type] = components;
}
} while (answers.componentType !== 'all' && answers.addMoreComponents);
} while (answers.componentType !== 'all-no-plugin' && answers.componentType !== 'complete' && answers.addMoreComponents);
}

async function checkFileExists (file) {
Expand All @@ -1153,9 +1186,14 @@ async function setupEnvironment (options) {

const envContent = JSON.parse(fs.readFileSync(options.env));

// plugins excluded only if specified
if (options.excludeMicroservices !== true) {
ALL_TYPES.push('plugin');
}

// Setup env variables
coreBaseApi = envContent.coreBaseApi;
k8ssvcApi = envContent.k8ssvcApi;
componentManagerApi = envContent.componentManagerApi || envContent.k8ssvcApi;
clientId = envContent.clientId;
clientSecret = envContent.clientSecret;

Expand All @@ -1178,18 +1216,20 @@ async function setupEnvironment (options) {
contentModel: `${coreBaseApi}/api/plugins/cms/contentmodels`,
content: `${coreBaseApi}/api/plugins/cms/contents`,
asset: `${coreBaseApi}/api/plugins/cms/assets`,
plugin: `${k8ssvcApi}/plugins`,
plugin: `${componentManagerApi}/plugins`,
resource: `${coreBaseApi}/api/fileBrowser?protectedFolder=false&currentPath=`,
resourceDetails: `${coreBaseApi}/api/fileBrowser/file?protectedFolder=false&currentPath={path}`,
};

token = await getToken();


}

async function interactiveSession () {
const envAnswer = await inquirer.prompt(environmentQuestions);
await setupEnvironment(envAnswer);

token = await getToken();

let confirmation;
do {
await inquireComponents();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@entando/entando-bundler",
"version": "6.3.2",
"version": "7.0.2",
"license": "LGPL-3.0",
"description": "Command line interface to generate Entando Bundles",
"repository": {
Expand Down

0 comments on commit a10afc9

Please sign in to comment.