Skip to content

Commit

Permalink
Implement auto-detect deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
nturinski committed Dec 1, 2017
1 parent 63a7d01 commit 94a8cca
Showing 1 changed file with 62 additions and 48 deletions.
110 changes: 62 additions & 48 deletions appservice/src/SiteWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class SiteWrapper {

public async updateConfiguration(client: WebSiteManagementClient, config: SiteConfigResource): Promise<SiteConfigResource> {
return this.slotName ?
await client.webApps.updateConfigurationSlot(this.resourceGroup, this.appName, config, this.slotName) :
await client.webApps.updateConfiguration(this.resourceGroup, this.appName, config);
await client.webApps.updateConfigurationSlot(this.resourceGroup, this.name, config, this.slotName) :
await client.webApps.updateConfiguration(this.resourceGroup, this.name, config);
}

public async getAppServicePlan(client: WebSiteManagementClient): Promise<AppServicePlan> {
Expand Down Expand Up @@ -138,7 +138,62 @@ export class SiteWrapper {
outputChannel.appendLine(localize('DeleteSucceeded', 'Successfully deleted "{0}".', this.appName));
}

public async deployZip(fsPath: string, client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<void> {
public async deploy(fsPath: string, client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<void> {
const config: SiteConfigResource = await this.getSiteConfig(client);
switch (config.scmType) {
case 'LocalGit':
await this.localGitDeploy(fsPath, client, outputChannel);
break;
default:
await this.deployZip(fsPath, client, outputChannel);
break;
}
}

public async isHttpLogsEnabled(client: WebSiteManagementClient): Promise<boolean> {
const logsConfig: SiteLogsConfig = this.slotName ? await client.webApps.getDiagnosticLogsConfigurationSlot(this.resourceGroup, this.name, this.slotName) :
await client.webApps.getDiagnosticLogsConfiguration(this.resourceGroup, this.name);
return logsConfig.httpLogs && logsConfig.httpLogs.fileSystem && logsConfig.httpLogs.fileSystem.enabled;
}

public async enableHttpLogs(client: WebSiteManagementClient): Promise<void> {
const logsConfig: SiteLogsConfig = {
location: this.location,
httpLogs: {
fileSystem: {
enabled: true,
retentionInDays: 7,
retentionInMb: 35
}
}
};

if (this.slotName) {
await client.webApps.updateDiagnosticLogsConfigSlot(this.resourceGroup, this.name, logsConfig, this.slotName);
} else {
await client.webApps.updateDiagnosticLogsConfig(this.resourceGroup, this.name, logsConfig);
}
}

public async getKuduClient(client: WebSiteManagementClient): Promise<KuduClient> {
const user: User = await this.getWebAppPublishCredential(client);
if (!user.publishingUserName || !user.publishingPassword) {
throw new ArgumentError(user);
}

const cred: BasicAuthenticationCredentials = new BasicAuthenticationCredentials(user.publishingUserName, user.publishingPassword);

return new KuduClient(cred, `https://${this.appName}.scm.azurewebsites.net`);
}

public async editScmType(client: WebSiteManagementClient): Promise<string | undefined> {
const config: SiteConfigResource = await this.getSiteConfig(client);
const newScmType: string = await this.showScmPrompt(config.scmType);
// returns the updated scmType
return await this.updateScmType(client, config, newScmType);
}

private async deployZip(fsPath: string, client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<void> {
const warning: string = localize('zipWarning', 'Are you sure you want to deploy to "{0}"? This will overwrite any previous deployment and cannot be undone.', this.appName);
if (await vscode.window.showWarningMessage(warning, DialogResponses.yes, DialogResponses.cancel) !== DialogResponses.yes) {
throw new UserCancelledError();
Expand Down Expand Up @@ -182,7 +237,7 @@ export class SiteWrapper {
this.log(outputChannel, 'Deployment completed.');
}

public async localGitDeploy(fsPath: string, client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<DeployResult | undefined> {
private async localGitDeploy(fsPath: string, client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<void> {
const kuduClient: KuduClient = await this.getKuduClient(client);
const pushReject: string = localize('localGitPush', 'Push rejected due to Git history diverging. Force push?');
const publishCredentials: User = await this.getWebAppPublishCredential(client);
Expand Down Expand Up @@ -217,50 +272,9 @@ export class SiteWrapper {
throw err;
}
}
return await this.waitForDeploymentToComplete(kuduClient, outputChannel);
}

public async isHttpLogsEnabled(client: WebSiteManagementClient): Promise<boolean> {
const logsConfig: SiteLogsConfig = this.slotName ? await client.webApps.getDiagnosticLogsConfigurationSlot(this.resourceGroup, this.name, this.slotName) :
await client.webApps.getDiagnosticLogsConfiguration(this.resourceGroup, this.name);
return logsConfig.httpLogs && logsConfig.httpLogs.fileSystem && logsConfig.httpLogs.fileSystem.enabled;
}

public async enableHttpLogs(client: WebSiteManagementClient): Promise<void> {
const logsConfig: SiteLogsConfig = {
location: this.location,
httpLogs: {
fileSystem: {
enabled: true,
retentionInDays: 7,
retentionInMb: 35
}
}
};

if (this.slotName) {
await client.webApps.updateDiagnosticLogsConfigSlot(this.resourceGroup, this.name, logsConfig, this.slotName);
} else {
await client.webApps.updateDiagnosticLogsConfig(this.resourceGroup, this.name, logsConfig);
}
}

public async getKuduClient(client: WebSiteManagementClient): Promise<KuduClient> {
const user: User = await this.getWebAppPublishCredential(client);
if (!user.publishingUserName || !user.publishingPassword) {
throw new ArgumentError(user);
}

const cred: BasicAuthenticationCredentials = new BasicAuthenticationCredentials(user.publishingUserName, user.publishingPassword);

return new KuduClient(cred, `https://${this.appName}.scm.azurewebsites.net`);
}

public async editScmType(client: WebSiteManagementClient): Promise<string | undefined> {
const config: SiteConfigResource = await this.getSiteConfig(client);
const newScmType: string = await this.showScmPrompt(config.scmType);
// returns the updated scmType
return await this.updateScmType(client, config, newScmType);
this.log(outputChannel, (localize('localGitDeploy', `Deploying Local Git repository to "${this.appName}"...`)));
await this.waitForDeploymentToComplete(kuduClient, outputChannel);
this.log(outputChannel, 'Deployment completed.');
}

private async showScmPrompt(currentScmType: string): Promise<string> {
Expand Down

0 comments on commit 94a8cca

Please sign in to comment.