Skip to content

Commit

Permalink
fix(core.gbapp): Self-replication on Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 27, 2019
1 parent 2ccae38 commit 05edafd
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 17 deletions.
15 changes: 8 additions & 7 deletions deploy.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions packages/admin.gbapp/services/GBAdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 19 additions & 2 deletions packages/admin.gbapp/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:'
}
};
21 changes: 18 additions & 3 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(';'));
}
Expand Down Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 2 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 05edafd

Please sign in to comment.