fix(core.gbapp): Self-replication on Azure

This commit is contained in:
Rodrigo Rodriguez 2019-05-27 07:45:23 -03:00
parent 2ccae38f98
commit 05edafd7fa
8 changed files with 62 additions and 17 deletions

View file

@ -96,7 +96,7 @@ call :SelectNodeVersion
:: 3. Install npm packages :: 3. Install npm packages
IF EXIST "%DEPLOYMENT_TARGET%\package.json" ( IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
pushd "%DEPLOYMENT_TARGET%" pushd "%DEPLOYMENT_TARGET%"
echo [GUARIBASDEPLOYER] Installing packages for server. echo [General Bots Deployer] Installing packages for server...
call :ExecuteCmd !NPM_CMD! install --production call :ExecuteCmd !NPM_CMD! install --production
IF !ERRORLEVEL! NEQ 0 goto error IF !ERRORLEVEL! NEQ 0 goto error
popd popd
@ -106,19 +106,20 @@ IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
IF EXIST "%DEPLOYMENT_TARGET%\deploy\default.gbui\package.json" ( IF EXIST "%DEPLOYMENT_TARGET%\deploy\default.gbui\package.json" (
call :ExecuteCmd !NPM_CMD! config set scripts-prepend-node-path true call :ExecuteCmd !NPM_CMD! config set scripts-prepend-node-path true
pushd "%DEPLOYMENT_TARGET%\deploy\default.gbui" pushd "%DEPLOYMENT_TARGET%\deploy\default.gbui"
echo [GUARIBASDEPLOYER] Installing packages for default.gbui. echo [General Bots Deployer] Installing packages for default.gbui...
call :ExecuteCmd !NPM_CMD! install call :ExecuteCmd !NPM_CMD! install
echo [GUARIBASDEPLOYER] Building default.gbui. echo [General Bots Deployer] Building default.gbui...
call :ExecuteCmd !NPM_CMD! run build call :ExecuteCmd !NPM_CMD! run build
IF !ERRORLEVEL! NEQ 0 goto error IF !ERRORLEVEL! NEQ 0 goto error
popd popd
) )
:: 4. Install typescript :: 4. Install typescript
echo [GUARIBASDEPLOYER] Transpiling... echo [General Bots Deployer] Transpiling...
call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -v call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -v
call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -p "%DEPLOYMENT_TARGET%" call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -p "%DEPLOYMENT_TARGET%"
echo [General Bots Deployer] Deployment Finished.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end goto end

View file

@ -80,6 +80,12 @@ export class AdminDialog extends IGBDialog {
); );
} }
public static async syncBotServerCommand(min: GBMinInstance, deployer: GBDeployer) {
const serverName = `${min.instance.botId}-server`;
const service = await AzureDeployerService.createInstance(deployer);
service.syncBotServerRepository(min.instance.botId, serverName);
}
/** /**
* Setup dialogs flows and define services call. * Setup dialogs flows and define services call.
* *
@ -138,6 +144,10 @@ export class AdminDialog extends IGBDialog {
} else if (cmdName === 'rebuildIndex') { } else if (cmdName === 'rebuildIndex') {
await AdminDialog.rebuildIndexPackageCommand(min, deployer); await AdminDialog.rebuildIndexPackageCommand(min, deployer);
return await step.replaceDialog('/admin', { firstRun: false });
} else if (cmdName === 'syncBotServer') {
await AdminDialog.syncBotServerCommand(min, deployer);
return await step.replaceDialog('/admin', { firstRun: false }); return await step.replaceDialog('/admin', { firstRun: false });
} else if (cmdName === 'setupSecurity') { } else if (cmdName === 'setupSecurity') {
return await step.beginDialog('/setupSecurity'); return await step.beginDialog('/setupSecurity');

View file

@ -39,7 +39,9 @@
import { AuthenticationContext, TokenResponse } from 'adal-node'; import { AuthenticationContext, TokenResponse } from 'adal-node';
import { IGBAdminService, IGBCoreService, IGBInstance } from 'botlib'; import { IGBAdminService, IGBCoreService, IGBInstance } from 'botlib';
import urlJoin = require('url-join'); import urlJoin = require('url-join');
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService';
import { GuaribasInstance } from '../../core.gbapp/models/GBModel'; import { GuaribasInstance } from '../../core.gbapp/models/GBModel';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
import { GuaribasAdmin } from '../models/AdminModel'; import { GuaribasAdmin } from '../models/AdminModel';
const msRestAzure = require('ms-rest-azure'); const msRestAzure = require('ms-rest-azure');
const PasswordGenerator = require('strict-password-generator').default; const PasswordGenerator = require('strict-password-generator').default;

View file

@ -21,7 +21,24 @@ export const Messages = {
enter_authenticator_client_secret: 'Enter the Client Secret:' enter_authenticator_client_secret: 'Enter the Client Secret:'
}, },
'pt-BR': { 'pt-BR': {
show_video: 'Vou te mostrar um vídeo. Por favor, aguarde...', authenticate: 'Please, authenticate:',
hi: msg => `Oi, ${msg}.` welcome: 'Welcome to Pragmatismo.io GeneralBots Administration.',
which_task: 'Which task do you wanna run now?',
working: (command) => `I'm working on ${command}...`,
finished_working: 'Done.',
unknown_command: text =>
`Well, but ${text} is not a administrative General Bots command, I will try to search for it.`,
hi: text => `Hello, ${text}.`,
undeployPackage: text => `Undeploying package ${text}...`,
deployPackage: text => `Deploying package ${text}...`,
redeployPackage: text => `Redeploying package ${text}...`,
packageUndeployed: text => `Package ${text} undeployed...`,
consent: (url) => `Please, consent access to this app at: [Microsoft Online](${url}).`,
wrong_password: 'Sorry, wrong password. Please, try again.',
enter_authenticator_tenant: 'Enter the Authenticator Tenant (eg.: domain.onmicrosoft.com):',
enter_authenticator_authority_host_url: 'Enter the Authority Host URL (eg.: https://login.microsoftonline.com): ',
enter_authenticator_client_id: `Enter the Client Id GUID: Get from
[this url](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview)`,
enter_authenticator_client_secret: 'Enter the Client Secret:'
} }
}; };

View file

@ -85,6 +85,19 @@ export class AzureDeployerService implements IGBInstallationDeployer {
this.deployer = deployer; this.deployer = deployer;
} }
public static async createInstance(deployer: GBDeployer): Promise<AzureDeployerService> {
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const credentials = await GBAdminService.getADALCredentialsFromUsername(username, password);
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
const service = new AzureDeployerService(deployer);
service.initServices(credentials, subscriptionId);
return service;
}
private static createRequestObject(url: string, accessToken: string, verb: HttpMethods, body: string) { private static createRequestObject(url: string, accessToken: string, verb: HttpMethods, body: string) {
const req = new WebResource(); const req = new WebResource();
req.method = verb; req.method = verb;
@ -520,7 +533,11 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}); });
} }
private initServices(credentials: any, subscriptionId: string) { public async syncBotServerRepository(group, name) {
await this.webSiteClient.webApps.syncRepository(group, name);
}
public initServices(credentials: any, subscriptionId: string) {
this.resourceClient = new ResourceManagementClient.default(credentials, subscriptionId); this.resourceClient = new ResourceManagementClient.default(credentials, subscriptionId);
this.webSiteClient = new WebSiteManagementClient(credentials, subscriptionId); this.webSiteClient = new WebSiteManagementClient(credentials, subscriptionId);
this.storageClient = new SqlManagementClient(credentials, subscriptionId); this.storageClient = new SqlManagementClient(credentials, subscriptionId);
@ -686,8 +703,6 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}; };
await this.webSiteClient.webApps.updateDiagnosticLogsConfig(group, name, siteLogsConfig); await this.webSiteClient.webApps.updateDiagnosticLogsConfig(group, name, siteLogsConfig);
await this.webSiteClient.webApps.update
const souceControlConfig: SiteSourceControl = { const souceControlConfig: SiteSourceControl = {
repoUrl: 'https://github.com/GeneralBots/BotServer.git', repoUrl: 'https://github.com/GeneralBots/BotServer.git',
branch: 'master', branch: 'master',

View file

@ -93,8 +93,8 @@ export class GBDeployer {
(resolve: any, reject: any): any => { (resolve: any, reject: any): any => {
GBLog.info(`PWD ${process.env.PWD}...`); GBLog.info(`PWD ${process.env.PWD}...`);
let totalPackages = 0; let totalPackages = 0;
let paths = [urlJoin(process.env.PWD, '..', GBDeployer.deployFolder)];
const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH'); const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH');
let paths = [GBDeployer.deployFolder];
if (additionalPath !== undefined && additionalPath !== '') { if (additionalPath !== undefined && additionalPath !== '') {
paths = paths.concat(additionalPath.toLowerCase().split(';')); paths = paths.concat(additionalPath.toLowerCase().split(';'));
} }
@ -412,6 +412,7 @@ export class GBDeployer {
GBLog.info(`Deploying app: ${e}...`); GBLog.info(`Deploying app: ${e}...`);
let folder = Path.join(e, 'node_modules'); let folder = Path.join(e, 'node_modules');
let
if (!Fs.existsSync(folder)) { if (!Fs.existsSync(folder)) {
GBLog.info(`Installing modules for ${e}...`); GBLog.info(`Installing modules for ${e}...`);
child_process.execSync('npm install', { cwd: e }); child_process.execSync('npm install', { cwd: e });

View file

@ -141,7 +141,7 @@ export class GBMinService {
// Install default VBA module. // Install default VBA module.
deployer.deployPackage(min, 'packages/default.gbdialog'); // DISABLED: deployer.deployPackage(min, 'packages/default.gbdialog');
// Call the loadBot context.activity for all packages. // Call the loadBot context.activity for all packages.

View file

@ -72,10 +72,9 @@ export class GBServer {
public static run() { public static run() {
GBLog.info(`The Bot Server is in STARTING mode...`); GBLog.info(`The Bot Server is in STARTING mode...`);
process.env.PWD = process.cwd(); process.env.PWD = __dirname;
// Creates a basic HTTP server that will serve several URL, one for each // Creates a basic HTTP server that will serve several URL, one for each bot instance.
// bot instance.
GBServer.globals = new RootData(); GBServer.globals = new RootData();
const port = GBConfigService.getServerPort(); const port = GBConfigService.getServerPort();