diff --git a/deploy.cmd b/deploy.cmd index 851442fc..7887d7c0 100644 --- a/deploy.cmd +++ b/deploy.cmd @@ -59,7 +59,7 @@ IF DEFINED KUDU_SELECT_NODE_VERSION_CMD ( SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp" IF !ERRORLEVEL! NEQ 0 goto error ) - + IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" ( SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp" IF !ERRORLEVEL! NEQ 0 goto error @@ -96,7 +96,7 @@ call :SelectNodeVersion :: 3. Install npm packages IF EXIST "%DEPLOYMENT_TARGET%\package.json" ( pushd "%DEPLOYMENT_TARGET%" - echo [GUARIBASDEPLOYER] Installing packages for server. + echo [General Bots Deployer] Installing packages for server... call :ExecuteCmd !NPM_CMD! install --production IF !ERRORLEVEL! NEQ 0 goto error popd @@ -106,19 +106,20 @@ IF EXIST "%DEPLOYMENT_TARGET%\package.json" ( IF EXIST "%DEPLOYMENT_TARGET%\deploy\default.gbui\package.json" ( call :ExecuteCmd !NPM_CMD! config set scripts-prepend-node-path true 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 - echo [GUARIBASDEPLOYER] Building default.gbui. + echo [General Bots Deployer] Building default.gbui... call :ExecuteCmd !NPM_CMD! run build IF !ERRORLEVEL! NEQ 0 goto error popd -) +) -:: 4. Install typescript -echo [GUARIBASDEPLOYER] Transpiling... +:: 4. Install typescript +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 -p "%DEPLOYMENT_TARGET%" +echo [General Bots Deployer] Deployment Finished. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: goto end diff --git a/packages/admin.gbapp/dialogs/AdminDialog.ts b/packages/admin.gbapp/dialogs/AdminDialog.ts index 80eaaa8b..f785011a 100644 --- a/packages/admin.gbapp/dialogs/AdminDialog.ts +++ b/packages/admin.gbapp/dialogs/AdminDialog.ts @@ -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. * @@ -138,6 +144,10 @@ export class AdminDialog extends IGBDialog { } else if (cmdName === 'rebuildIndex') { 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 }); } else if (cmdName === 'setupSecurity') { return await step.beginDialog('/setupSecurity'); diff --git a/packages/admin.gbapp/services/GBAdminService.ts b/packages/admin.gbapp/services/GBAdminService.ts index 4f125057..84027f89 100644 --- a/packages/admin.gbapp/services/GBAdminService.ts +++ b/packages/admin.gbapp/services/GBAdminService.ts @@ -39,7 +39,9 @@ import { AuthenticationContext, TokenResponse } from 'adal-node'; import { IGBAdminService, IGBCoreService, IGBInstance } from 'botlib'; import urlJoin = require('url-join'); +import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService'; import { GuaribasInstance } from '../../core.gbapp/models/GBModel'; +import { GBConfigService } from '../../core.gbapp/services/GBConfigService'; import { GuaribasAdmin } from '../models/AdminModel'; const msRestAzure = require('ms-rest-azure'); const PasswordGenerator = require('strict-password-generator').default; diff --git a/packages/admin.gbapp/strings.ts b/packages/admin.gbapp/strings.ts index 30beca96..2bede1af 100644 --- a/packages/admin.gbapp/strings.ts +++ b/packages/admin.gbapp/strings.ts @@ -21,7 +21,24 @@ export const Messages = { enter_authenticator_client_secret: 'Enter the Client Secret:' }, 'pt-BR': { - show_video: 'Vou te mostrar um vĂ­deo. Por favor, aguarde...', - hi: msg => `Oi, ${msg}.` + authenticate: 'Please, authenticate:', + 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:' } }; diff --git a/packages/azuredeployer.gbapp/services/AzureDeployerService.ts b/packages/azuredeployer.gbapp/services/AzureDeployerService.ts index 8c153f80..19123964 100644 --- a/packages/azuredeployer.gbapp/services/AzureDeployerService.ts +++ b/packages/azuredeployer.gbapp/services/AzureDeployerService.ts @@ -85,6 +85,19 @@ export class AzureDeployerService implements IGBInstallationDeployer { this.deployer = deployer; } + public static async createInstance(deployer: GBDeployer): Promise { + + 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) { const req = new WebResource(); 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.webSiteClient = new WebSiteManagementClient(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.update - const souceControlConfig: SiteSourceControl = { repoUrl: 'https://github.com/GeneralBots/BotServer.git', branch: 'master', diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 3409daca..9fc0e1a4 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -93,8 +93,8 @@ export class GBDeployer { (resolve: any, reject: any): any => { GBLog.info(`PWD ${process.env.PWD}...`); let totalPackages = 0; + let paths = [urlJoin(process.env.PWD, '..', GBDeployer.deployFolder)]; const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH'); - let paths = [GBDeployer.deployFolder]; if (additionalPath !== undefined && additionalPath !== '') { paths = paths.concat(additionalPath.toLowerCase().split(';')); } @@ -412,6 +412,7 @@ export class GBDeployer { GBLog.info(`Deploying app: ${e}...`); let folder = Path.join(e, 'node_modules'); + let if (!Fs.existsSync(folder)) { GBLog.info(`Installing modules for ${e}...`); child_process.execSync('npm install', { cwd: e }); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 7933166a..f96859d7 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -141,7 +141,7 @@ export class GBMinService { // 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. diff --git a/src/app.ts b/src/app.ts index 3361d704..5b0be517 100644 --- a/src/app.ts +++ b/src/app.ts @@ -72,10 +72,9 @@ export class GBServer { public static run() { 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 - // bot instance. + // Creates a basic HTTP server that will serve several URL, one for each bot instance. GBServer.globals = new RootData(); const port = GBConfigService.getServerPort();