[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

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

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