fix(core.gbapp): Self-replication on Azure
This commit is contained in:
parent
2ccae38f98
commit
05edafd7fa
8 changed files with 62 additions and 17 deletions
15
deploy.cmd
15
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
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -85,6 +85,19 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
|||
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) {
|
||||
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',
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue