Refactor env variables (#2094)

* Rename the env to sync with BE/Docker

* Refactor envs

* Use the env.yml strategy
This commit is contained in:
Maurizio Vitale 2021-04-28 15:14:20 +01:00 committed by GitHub
parent cc6bb7e95b
commit 4ebc7447f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 248 deletions

View File

@ -1,3 +1,10 @@
import:
- source: .travis/env.yml
mode: deep_merge_prepend
# =================
# merge anchor
# =================
dist: bionic dist: bionic
sudo: required sudo: required
services: services:
@ -37,7 +44,6 @@ stages:
env: env:
global: global:
- API_AOS_HOST=$API_CONTENT_HOST
- ADMIN_EMAIL=$ADMIN_EMAIL_REMOTE - ADMIN_EMAIL=$ADMIN_EMAIL_REMOTE
- ADMIN_PASSWORD=$ADMIN_PASSWORD_REMOTE - ADMIN_PASSWORD=$ADMIN_PASSWORD_REMOTE

5
.travis/env.yml Normal file
View File

@ -0,0 +1,5 @@
env:
global:
# APP CONFIGURATION
- APP_CONFIG_NOTIFICATION_LAST=6000
- APP_CONFIG_SHOW_NOTIFICATION_HISTORY=true

View File

@ -13,7 +13,6 @@
"build.e2e": "npm run build.app -- --prod --configuration=e2e", "build.e2e": "npm run build.app -- --prod --configuration=e2e",
"build.release": "npm run build.app -- --configuration=production,release", "build.release": "npm run build.app -- --configuration=production,release",
"test": "ng test app --code-coverage", "test": "ng test app --code-coverage",
"lite-serve": "./scripts/run lite-serve",
"test:ci": "ng test adf-office-services-ext --watch=false && ng test app --code-coverage --watch=false", "test:ci": "ng test adf-office-services-ext --watch=false && ng test app --code-coverage --watch=false",
"lint": "ng lint && npm run spellcheck && npm run e2e.typecheck", "lint": "ng lint && npm run spellcheck && npm run e2e.typecheck",
"update-webdriver": "./scripts/update-webdriver.sh", "update-webdriver": "./scripts/update-webdriver.sh",

View File

@ -21,13 +21,13 @@ const width = 1366;
const height = 768; const height = 768;
const SAVE_SCREENSHOT = process.env.SAVE_SCREENSHOT === 'true'; const SAVE_SCREENSHOT = process.env.SAVE_SCREENSHOT === 'true';
const API_CONTENT_HOST = process.env.API_CONTENT_HOST || 'http://localhost:8080'; const APP_CONFIG_ECM_HOST = process.env.APP_CONFIG_ECM_HOST || 'http://localhost:8080';
const MAXINSTANCES = process.env.MAXINSTANCES || 1; const MAXINSTANCES = process.env.MAXINSTANCES || 1;
const MAX_RETRIES = process.env.MAX_RETRIES || 1; const MAX_RETRIES = process.env.MAX_RETRIES || 1;
const E2E_LOG_LEVEL = process.env.E2E_LOG_LEVEL || 'ERROR'; const E2E_LOG_LEVEL = process.env.E2E_LOG_LEVEL || 'ERROR';
const appConfig = { const appConfig = {
hostEcm: API_CONTENT_HOST, hostEcm: APP_CONFIG_ECM_HOST,
providers: 'ECM', providers: 'ECM',
authType: 'BASIC' authType: 'BASIC'
}; };

View File

@ -4,41 +4,38 @@ const program = require('commander');
require('dotenv').config({ path: process.env.ENV_FILE }); require('dotenv').config({ path: process.env.ENV_FILE });
const fs = require('fs'); const fs = require('fs');
const API_HOST = process.env.API_HOST || null; const APP_CONFIG_ECM_HOST = process.env.APP_CONFIG_ECM_HOST;
const API_CONTENT_HOST = process.env.API_CONTENT_HOST || API_HOST; const APP_CONFIG_BPM_HOST = process.env.APP_CONFIG_BPM_HOST;
const API_PROCESS_HOST = process.env.API_PROCESS_HOST || API_HOST; const APP_CONFIG_OAUTH2_HOST = process.env.APP_CONFIG_OAUTH2_HOST || 'oauth-host-default-replaced-value';
const API_AOS_HOST = process.env.API_AOS_HOST || API_HOST; const APP_CONFIG_IDENTITY_HOST = process.env.APP_CONFIG_IDENTITY_HOST || 'identity-host-default-replaced-value';
const OAUTH_HOST = process.env.OAUTH_HOST || 'oauth-host-default-replaced-value'; const APP_CONFIG_NOTIFICATION_LAST = parseInt(process.env.APP_CONFIG_NOTIFICATION_LAST, 10) || 2000;
const IDENTITY_HOST = process.env.IDENTITY_HOST || 'identity-host-default-replaced-value';
const NOTIFICATION_LAST = parseInt(process.env.NOTIFICATION_LAST, 10) || 2000;
const options = { const options = {
apiHost: { apiHost: {
flags: '-a, --api-host', flags: '-a, --api-host',
description: description:
'set apiHost=API_HOST, bpmHost=API_PROCESS_HOST, ecmHost=API_CONTENT_HOST, aosHost = API_AOS_HOST if present or fall back to API_HOST in each case', 'set bpmHost=APP_CONFIG_BPM_HOST, ecmHost=APP_CONFIG_ECM_HOST, aosHost = APP_CONFIG_ECM_HOST if present',
set: (appConfig) => { set: (appConfig) => {
appConfig.apiHost = API_HOST; appConfig.bpmHost = APP_CONFIG_BPM_HOST;
appConfig.bpmHost = API_PROCESS_HOST; appConfig.ecmHost = APP_CONFIG_ECM_HOST;
appConfig.ecmHost = API_CONTENT_HOST; appConfig.baseShareUrl = appConfig.baseShareUrl.replace('{protocol}//{hostname}{:port}', APP_CONFIG_ECM_HOST);
appConfig.baseShareUrl = appConfig.baseShareUrl.replace('{protocol}//{hostname}{:port}', API_CONTENT_HOST); appConfig.aosHost = appConfig.aosHost.replace('{protocol}//{hostname}{:port}', APP_CONFIG_ECM_HOST);
appConfig.aosHost = appConfig.aosHost.replace('{protocol}//{hostname}{:port}', API_AOS_HOST);
} }
}, },
identityHost: { identityHost: {
flags: '-i, --identity-host', flags: '-i, --identity-host',
description: "set identityHost's value with IDENTITY_HOST", description: "set identityHost's value with APP_CONFIG_IDENTITY_HOST",
set: (appConfig) => { set: (appConfig) => {
appConfig.authType = 'OAUTH'; appConfig.authType = 'OAUTH';
appConfig.identityHost = IDENTITY_HOST; appConfig.identityHost = APP_CONFIG_IDENTITY_HOST;
} }
}, },
oauthHost: { oauthHost: {
flags: '-o, --oauth-host', flags: '-o, --oauth-host',
description: "set oauth2.host's value with OAUTH_HOST", description: "set oauth2.host's value with APP_CONFIG_OAUTH2_HOST",
set: (appConfig) => { set: (appConfig) => {
appConfig.authType = 'OAUTH'; appConfig.authType = 'OAUTH';
appConfig.oauth2.host = OAUTH_HOST; appConfig.oauth2.host = APP_CONFIG_OAUTH2_HOST;
} }
}, },
notification: { notification: {
@ -46,7 +43,7 @@ const options = {
description: "set notificationDefaultDuration's value with <duration> and switch on showNotificationHistory", description: "set notificationDefaultDuration's value with <duration> and switch on showNotificationHistory",
set: (appConfig) => { set: (appConfig) => {
appConfig.showNotificationHistory = true; appConfig.showNotificationHistory = true;
appConfig.notificationDefaultDuration = NOTIFICATION_LAST; appConfig.notificationDefaultDuration = APP_CONFIG_NOTIFICATION_LAST;
} }
} }
}; };

View File

@ -3,4 +3,4 @@
# Upload protractor-smartrunner artifact related to this particular job to S3 # Upload protractor-smartrunner artifact related to this particular job to S3
./scripts/ci/utils/artifact-to-s3.sh -a "$SMART_RUNNER_DIRECTORY" -o "$S3_DBP_FOLDER/protractor-smartrunner-$TRAVIS_JOB_ID.tar.bz2" ./scripts/ci/utils/artifact-to-s3.sh -a "$SMART_RUNNER_DIRECTORY" -o "$S3_DBP_FOLDER/protractor-smartrunner-$TRAVIS_JOB_ID.tar.bz2"
./node_modules/@alfresco/adf-cli/bin/adf-cli scan-env --host "$API_CONTENT_HOST" -u "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD" ./node_modules/@alfresco/adf-cli/bin/adf-cli scan-env --host "$APP_CONFIG_ECM_HOST" -u "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD"

View File

@ -5,11 +5,11 @@ TO=$2;
PARAMS=$3; PARAMS=$3;
echo "====== Scan environment =====" echo "====== Scan environment ====="
./node_modules/@alfresco/adf-cli/bin/adf-cli scan-env --host "$API_CONTENT_HOST" -u "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD" ./node_modules/@alfresco/adf-cli/bin/adf-cli scan-env --host "$APP_CONFIG_ECM_HOST" -u "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD"
echo "====== Check content UP =====" echo "====== Check content UP ====="
./node_modules/@alfresco/adf-cli/bin/adf-cli check-cs-env --host "$API_CONTENT_HOST" -u "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD" || exit 1 ./node_modules/@alfresco/adf-cli/bin/adf-cli check-cs-env --host "$APP_CONFIG_ECM_HOST" -u "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD" || exit 1
echo "====== Download artifacts =====" echo "====== Download artifacts ====="
# Download built application artifact from S3 # Download built application artifact from S3

View File

@ -1,29 +0,0 @@
/*
* Copyright 2005-2019 Alfresco Software, Ltd. All rights reserved.
*
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
import * as angularJson from 'angular.json';
export const getApps = () => {
return Object.keys(angularJson.projects)
.map((projectName) => ({ name: projectName, ...angularJson.projects[projectName] }))
.filter((project) => project.projectType === 'application')
.filter((project) => project.name.indexOf('e2e') === -1);
};
export const getE2Es = () => {
return Object.keys(angularJson.projects)
.map((projectName) => ({ name: projectName, ...angularJson.projects[projectName] }))
.filter((project) => project.projectType === 'application')
.filter((project) => project.name.endsWith('-e2e'));
};
export const getLibs = () => {
return Object.keys(angularJson.projects)
.map((projectName) => ({ name: projectName, ...angularJson.projects[projectName] }))
.filter((project) => project.projectType === 'library');
};

View File

@ -1,191 +0,0 @@
/*
* Copyright 2005-2019 Alfresco Software, Ltd. All rights reserved.
*
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
import { getApps } from './helpers/project-selectors';
import { existsSync } from 'fs';
import { resolve } from 'path';
import { spawn } from 'child_process';
import { yellow, green, red } from 'chalk';
import { ListParam, ComplexListChoice } from 'clireader/list-param';
import { CheckboxParam } from '../clireader/checkbox-param';
import { CliReader, CliParam } from 'clireader/cli-reader';
import * as logger from '../../tools/helpers/logger';
import * as ora from 'ora';
require('dotenv').config({ path: process.env.ENV_FILE });
const API_HOST = process.env.API_HOST;
const API_CONTENT_HOST = process.env.API_CONTENT_HOST;
const OAUTH_HOST = process.env.OAUTH_HOST;
const IDENTITY_HOST = process.env.IDENTITY_HOST;
const NOTIFICATION_LAST = process.env.NOTIFICATION_LAST;
interface LiteServeRunnerInputs {
app: string;
configRewrite: string[];
}
export default class LiteServeRunner {
private cliReader: CliReader;
private inputParams: CliParam[];
constructor(private cliArgs: any[]) {
this.cliReader = new CliReader('lite-serve', '[options]', 'Start lite-serve for previously built app', '0.0.1');
this.inputParams = [
new ListParam({
name: 'app',
alias: 'a',
title: `Which ${yellow('prebuilt')} application to serve with lite-serve?`,
required: true,
choices: this.getAppList.bind(this),
pageSize: 30
}),
new CheckboxParam({
name: 'configRewrite',
alias: 'c',
title: 'Rewrite app.config.json with the following environment vars?',
required: false,
choices: this.getEnvVarChoices.bind(this)
})
];
}
run() {
const readerGenerator = this.cliReader.getReader(this.inputParams, this.cliArgs);
readerGenerator.next();
const builtApps = this.getAppList().filter((app) => !app.disabled);
if (!builtApps.length) {
logger.error('No prebuilt app found.');
process.exit(0);
}
const inputInquirer = readerGenerator.next().value as Promise<Object>;
return inputInquirer.then(this.appConfigReplace.bind(this)).then(this.spawnLiteServer.bind(this)).catch(logger.error.bind(logger));
}
private appConfigReplace(inputParams: LiteServeRunnerInputs) {
return new Promise((resolvePromise, reject) => {
if (!inputParams['configRewrite'] || !inputParams['configRewrite'].length) {
logger.verbose(green('No rewrite has been made'));
resolvePromise(inputParams);
return;
}
let appPath = getApps()
.filter((app) => app.name === inputParams.app)
.map((project) => this.getOutputPath(project))[0];
appPath = resolve(appPath, 'app.config.json');
const rewriteFlags = `-${inputParams['configRewrite'].join('')}`;
const spinner = ora(`Rewriting ${appPath} with flags: ${rewriteFlags}`).start();
const replace = spawn(process.cwd() + '/scripts/app-config-replace.js', [`--config=${appPath}`, rewriteFlags]);
replace.stdout.on('data', (data) => logger.verbose(data.toString()));
replace.stderr.on('data', (data) => {
logger.error(data.toString());
reject();
});
replace.on('exit', () => {
spinner.succeed();
logger.verbose(green(`Rewrite ${appPath} succeeded!`));
resolvePromise(inputParams);
});
});
}
private spawnLiteServer(inputParams: LiteServeRunnerInputs) {
const spinner = ora(`Starting lite-serve, please wait and don't move!`).start();
return new Promise((resolvePromise, reject) => {
const liteServe = spawn('npm', ['run', '--quiet', 'ng', 'run', `${inputParams.app}:lite-serve:standalone`]);
process.on('SIGINT', () => {
liteServe.kill('SIGINT');
spinner.text = red('Lite-serve terminated.');
spinner.fail();
});
liteServe.stdout.on('data', (data) => {
if (data.toString().includes(`lite-serve serving folder`)) {
spinner.text = green('Lite-serve is running.');
}
logger.verbose(data.toString());
});
liteServe.stderr.on('data', (data) => {
logger.error(data.toString());
reject();
});
liteServe.on('exit', (code) => {
logger.verbose('Lite-serve process exited with code ' + code.toString());
resolvePromise();
});
});
}
private getOutputPath(project) {
return resolve(process.cwd(), project.architect.build.options.outputPath);
}
private getAppList(): ComplexListChoice[] {
return getApps().map((project) => {
if (existsSync(this.getOutputPath(project))) {
return {
name: project.name,
disabled: false
};
}
return {
name: `${project.name} (not built)`,
disabled: true
};
});
}
private getEnvVarChoices() {
const choices = [];
if (API_HOST !== undefined || API_CONTENT_HOST !== undefined) {
choices.push({
name: `API_HOST=${API_HOST} && API_CONTENT_HOST=${API_CONTENT_HOST || API_HOST}`,
value: 'a',
short: 'API_HOST',
checked: true
});
}
if (OAUTH_HOST !== undefined) {
choices.push({
name: `OAUTH_HOST=${OAUTH_HOST} ${red('+ authType=OAUTH also!!!')}`,
value: 'o',
short: 'OAUTH_HOST',
checked: true
});
}
if (IDENTITY_HOST !== undefined) {
choices.push({
name: `IDENTITY_HOST=${IDENTITY_HOST} ${red('+ authType=OAUTH also!!!')}`,
value: 'i',
short: 'IDENTITY_HOST',
checked: true
});
}
if (NOTIFICATION_LAST !== undefined) {
choices.push({
name: `NOTIFICATION_LAST=${NOTIFICATION_LAST}`,
value: 'n',
short: 'NOTIFICATION_LAST',
checked: true
});
}
return choices;
}
}

View File

@ -1,10 +1,10 @@
require('dotenv').config(); require('dotenv').config();
const API_CONTENT_HOST = process.env.API_CONTENT_HOST || 'http://0.0.0.0:8080'; const APP_CONFIG_ECM_HOST = process.env.APP_CONFIG_ECM_HOST || 'http://0.0.0.0:8080';
module.exports = { module.exports = {
'/alfresco': { '/alfresco': {
target: API_CONTENT_HOST, target: APP_CONFIG_ECM_HOST,
secure: false, secure: false,
changeOrigin: true, changeOrigin: true,
// workaround for REPO-2260 // workaround for REPO-2260
@ -16,7 +16,7 @@ module.exports = {
} }
}, },
'/auth': { '/auth': {
target: API_CONTENT_HOST, target: APP_CONFIG_ECM_HOST,
secure: false, secure: false,
changeOrigin: true changeOrigin: true
} }