[AAE-13661] Modify init-aae-env file to accept env parameter (#8489)

* [AAE-13661] Modify init-aae-env file to accept env parameter

* [AAE-13661] Add multiple env support
This commit is contained in:
Diogo Bastos 2023-05-15 16:31:28 +01:00 committed by GitHub
parent a729852f34
commit d24726c884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

42
lib/cli/scripts/init-aae-env.ts Normal file → Executable file
View File

@ -42,6 +42,7 @@ export interface ConfigArgs {
scope: string;
host: string;
tag: string;
envs: string[];
}
export const AAE_MICROSERVICES = [
@ -296,7 +297,7 @@ function getAlfrescoJsApiInstance(configArgs: ConfigArgs) {
return new AlfrescoApi(config as unknown as AlfrescoApiConfig);
}
async function deployMissingApps(tag?: string) {
async function deployMissingApps(tag?: string, envs?: string[]) {
const deployedApps = await getApplicationByStatus('');
findMissingApps(deployedApps.list.entries);
findFailingApps(deployedApps.list.entries);
@ -311,7 +312,7 @@ async function deployMissingApps(tag?: string) {
process.exit(1);
} else if (absentApps.length > 0) {
logger.warn(`Missing apps: ${JSON.stringify(absentApps)}`);
await checkIfAppIsReleased(absentApps, tag);
await checkIfAppIsReleased(absentApps, tag, envs);
} else {
const reset = '\x1b[0m';
const green = '\x1b[32m';
@ -319,7 +320,7 @@ async function deployMissingApps(tag?: string) {
}
}
async function checkIfAppIsReleased(missingApps: any [], tag?: string) {
async function checkIfAppIsReleased(missingApps: any [], tag?: string, envs?: string[]) {
const projectList = await getProjects();
let TIME = 5000;
let noError = true;
@ -377,18 +378,31 @@ async function checkIfAppIsReleased(missingApps: any [], tag?: string) {
if (noError) {
await checkDescriptorExist(currentAbsentApp.name);
await sleep(TIME);
const deployPayload = {
name: currentAbsentApp.name,
releaseId: projectRelease.entry.id,
security: currentAbsentApp.security,
infrastructure: currentAbsentApp.infrastructure,
variables: currentAbsentApp.variables
};
await deploy(deployPayload);
if (envs && envs.length > 0) {
for (const envId of envs){
await deployWithPayload(currentAbsentApp, projectRelease, envId);
}
} else {
await deployWithPayload(currentAbsentApp, projectRelease);
}
}
}
}
async function deployWithPayload(currentAbsentApp: any, projectRelease: any, envId?: string) {
const deployPayload = {
name: currentAbsentApp.name,
releaseId: projectRelease.entry.id,
security: currentAbsentApp.security,
infrastructure: currentAbsentApp.infrastructure,
variables: currentAbsentApp.variables,
environmentId: envId
};
deploy(deployPayload);
}
async function checkDescriptorExist(name: string) {
logger.info(`Check descriptor ${name} exist in the list `);
const descriptorList = await getDescriptors();
@ -482,6 +496,7 @@ async function main() {
.option('--devopsUsername [type]', 'username of a user with role ACTIVIT_DEVOPS')
.option('--devopsPassword [type]', 'devops password')
.option('--tag [type]', 'tag name of the codebase')
.option('--envs [type...]', 'environment ids of the envs where to deploy the app')
.parse(process.argv);
if (process.argv.includes('-h') || process.argv.includes('--help')) {
@ -502,7 +517,8 @@ async function main() {
tokenEndpoint: options.tokenEndpoint,
scope: options.scope,
secret: options.secret,
tag: options.tag
tag: options.tag,
envs: options.envs
};
alfrescoJsApiModeler = getAlfrescoJsApiInstance(args);
@ -532,7 +548,7 @@ async function main() {
process.exit(1);
});
await deployMissingApps(args.tag);
await deployMissingApps(args.tag, args.envs);
} else {
logger.error('The environment is not up');
process.exit(1);