Skip to content

Commit

Permalink
Merge pull request #33 from Microsoft/nturinski/autoDetectDeploy
Browse files Browse the repository at this point in the history
Implement auto-detect deploy
  • Loading branch information
nturinski authored Dec 1, 2017
2 parents 63a7d01 + abf3dd8 commit e2e077c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 55 deletions.
2 changes: 1 addition & 1 deletion appservice/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-azureappservice",
"author": "Microsoft Corporation",
"version": "0.6.0",
"version": "0.7.0",
"description": "Common tools for developing Azure App Service extensions for VS Code",
"tags": [
"azure",
Expand Down
120 changes: 67 additions & 53 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 All @@ -153,14 +208,14 @@ export class SiteWrapper {
zipFilePath = fsPath;
} else if (await FileUtilities.isDirectory(fsPath)) {
createdZip = true;
this.log(outputChannel, 'Creating zip package...');
this.log(outputChannel, localize('zipCreate', 'Creating zip package...'));
zipFilePath = await FileUtilities.zipDirectory(fsPath);
} else {
throw new Error(localize('NotAZipError', 'Path specified is not a folder or a zip file'));
}

try {
this.log(outputChannel, 'Starting deployment...');
this.log(outputChannel, localize('deployStart', 'Starting deployment...'));
await kuduClient.pushDeployment.zipPushDeploy(fs.createReadStream(zipFilePath), { isAsync: true });
await this.waitForDeploymentToComplete(kuduClient, outputChannel);
} catch (error) {
Expand All @@ -179,10 +234,10 @@ export class SiteWrapper {
}
}

this.log(outputChannel, 'Deployment completed.');
this.log(outputChannel, localize('deployComplete', '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, localize('deployComplete', 'Deployment completed.'));
}

private async showScmPrompt(currentScmType: string): Promise<string> {
Expand Down Expand Up @@ -315,8 +329,8 @@ export class SiteWrapper {
}

private async showInstallPrompt(): Promise<void> {
const installString: string = 'Install';
const input: string | undefined = await vscode.window.showErrorMessage('Git must be installed to use Local Git Deploy.', installString);
const installString: string = localize('Install', 'Install');
const input: string | undefined = await vscode.window.showErrorMessage(localize('GitRequired', 'Git must be installed to use Local Git Deploy.'), installString);
if (input === installString) {
// tslint:disable-next-line:no-unsafe-any
opn('https://git-scm.com/downloads');
Expand Down
2 changes: 1 addition & 1 deletion kudu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"moment": "^2.18.1"
},
"devDependencies": {
"autorest": "^2.0.4147",
"autorest": "2.0.4147",
"typescript": "^2.5.3"
}
}

0 comments on commit e2e077c

Please sign in to comment.