Skip to content

Commit

Permalink
Update Publish-AzWebApp to use OneDeploy API for all deployment artif…
Browse files Browse the repository at this point in the history
…acts (#21749)
  • Loading branch information
dannysongg authored May 12, 2023
1 parent 31e581c commit 1a48344
Show file tree
Hide file tree
Showing 8 changed files with 2,986 additions and 861 deletions.
7 changes: 7 additions & 0 deletions src/Websites/Websites.Test/ScenarioTests/WebAppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ public void TestPublishWebAppFromWar()
TestRunner.RunTestScript("Test-PublishAzureWebAppFromWar");
}

[Fact]
[Trait(Category.RunType, Category.LiveOnly)]
public void TestPublishWebAppOneDeploy()
{
TestRunner.RunTestScript("Test-PublishAzureWebAppOneDeploy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCloneNewWebApp()
Expand Down
42 changes: 42 additions & 0 deletions src/Websites/Websites.Test/ScenarioTests/WebAppTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ function Test-WebAppPublishingProfile
}
}

# Keep existing test to ensure backwards compatibility with existing behavior
function Test-PublishAzureWebAppFromZip
{
# Setup
Expand Down Expand Up @@ -1494,6 +1495,7 @@ function Test-PublishAzureWebAppFromZip
}
}

# Keep existing test to ensure backwards compatibility with existing behavior
function Test-PublishAzureWebAppFromWar
{
# Setup
Expand Down Expand Up @@ -1533,6 +1535,46 @@ function Test-PublishAzureWebAppFromWar
}
}

# New tests for PublishAzureWebApp to test deploying against newer Onedeploy endpoint
function Test-PublishAzureWebAppOnedeploy
{
# Setup
$rgname = Get-ResourceGroupName
$appName = Get-WebsiteName
$location = Get-WebLocation
$planName = Get-WebHostPlanName
$tier = "Shared"

try
{
#Setup
New-AzureRmResourceGroup -Name $rgname -Location $location
$serverFarm = New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $planName -Location $location -Tier $tier

# Create new web app
$webapp = New-AzureRmWebApp -ResourceGroupName $rgname -Name $appName -Location $location -AppServicePlan $planName

#Configuring jdk and web container
# Set Java runtime to 1.8 | Tomcat. In order to deploy war, site should be configured to run with stack = TOMCAT
# or JBOSSEAP (only availble on Linux). In this test case, it creates Windows app.
$javaVersion="1.8"
$javaContainer="TOMCAT"
$javaContainerVersion="8.5"
$PropertiesObject = @{javaVersion = $javaVersion;javaContainer = $javaContainer;javaContainerVersion = $javaContainerVersion}
New-AzResource -PropertyObject $PropertiesObject -ResourceGroupName $rgname -ResourceType Microsoft.Web/sites/config -ResourceName "$appName/web" -ApiVersion 2018-02-01 -Force

$warPath = Join-Path $ResourcesPath "HelloJava.war"
$publishedApp = Publish-AzWebApp -ResourceGroupName $rgname -Name $appName -ArchivePath $warPath -Type war -Clean $true -TargetPath /home/site/wwwroot/webapps/ROOT -Force

Assert-NotNull $publishedApp
}
finally
{
# Cleanup
Remove-AzureRmResourceGroup -Name $rgname -Force
}
}

<#
.SYNOPSIS
Tests creating a web app with a simple parameterset.
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Websites/Websites/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

## Version 2.15.1
* Used AAD Auth instead of Basic Auth for PublishAzureWebApps
* Add support for OneDeploy API in PublishAzureWebApps while maintaining backwards compatibility with existing behavior

## Version 2.15.0
* Fixed Tag parameter issues with ASE for `New-AzWebApp`
Expand Down
66 changes: 60 additions & 6 deletions src/Websites/Websites/Cmdlets/WebApps/PublishAzureWebApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Web;

namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
{
Expand All @@ -42,6 +44,28 @@ public class PublishAzureWebAppCmdlet : WebAppOptionalSlotBaseCmdlet
[ValidateNotNullOrEmpty]
public string ArchivePath { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Used to override the type of artifact being deployed.")]
[ValidateSet("war", "jar", "ear", "zip", "static")]
public string Type { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Cleans the target directory prior to deploying the file(s).")]
public SwitchParameter Clean { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The artifact is deployed asynchronously. (The command will exit once the artifact is pushed to the web app.)")]
public SwitchParameter Async { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The web app will be restarted following the deployment. Set this to false if you are deploying multiple artifacts and do not want to restart the site on the earlier deployments.")]
public SwitchParameter Restart { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Absolute path that the artifact should be deployed to.")]
public string TargetPath { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Disables any language-specific defaults")]
public SwitchParameter IgnoreStack { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Reset Java web apps to default parking page")]
public SwitchParameter Reset { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Deploy the web app without prompting for confirmation.")]
public SwitchParameter Force { get; set; }

Expand All @@ -58,22 +82,52 @@ public override void ExecuteCmdlet()
User user = WebsitesClient.GetPublishingCredentials(ResourceGroupName, Name, Slot);

HttpResponseMessage r;
string deployUrl;
string deploymentStatusUrl = user.ScmUri + "/api/deployments/latest";

if (ArchivePath.ToLower().EndsWith("war"))
string apiPath = "/api/publish";
var scmUrl = new Uri(user.ScmUri);
var deployUri = new Uri(scmUrl, apiPath);

var uriBuilder = new UriBuilder(deployUri);
var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query);

string fileExtention = Path.GetExtension(ArchivePath);
string[] validTypes = { "war", "jar", "ear", "zip", "static" };

if (!string.IsNullOrEmpty(Type))
{
deployUrl = user.ScmUri + "/api/publish?type=war";
paramValues["type"] = Type;
}
else if (ArchivePath.ToLower().EndsWith("zip") || ArchivePath.ToLower().EndsWith("jar"))

else if (!string.IsNullOrEmpty(fileExtention))
{
deployUrl = user.ScmUri + "/api/zipdeploy?isAsync=true";
if (validTypes.Contains(fileExtention.Substring(1)))
{
paramValues["type"] = fileExtention.Substring(1);
}

else
{
paramValues["type"] = "static";
}
}

else
{
throw new Exception("Unknown archive type.");
throw new Exception("Unknown artifact type.");
}

paramValues.Add("path", TargetPath);
paramValues.Add("isasync", Async.IsPresent.ToString());
paramValues.Add("restart", Restart.IsPresent.ToString());
paramValues.Add("clean", Clean.IsPresent.ToString());
paramValues.Add("ignorestack", IgnoreStack.IsPresent.ToString());
paramValues.Add("reset", Reset.IsPresent.ToString());

uriBuilder.Query = paramValues.ToString();

string deployUrl = uriBuilder.Uri.ToString();

Action zipDeployAction = () =>
{
if (!Path.IsPathRooted(ArchivePath))
Expand Down
118 changes: 113 additions & 5 deletions src/Websites/Websites/help/Publish-AzWebApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ Deploys an Azure Web App from a ZIP, JAR, or WAR file using zipdeploy.

### FromWebApp (Default)
```
Publish-AzWebApp -ArchivePath <String> [-Force] [-AsJob] [-Timeout <Double>] [-WebApp] <PSSite>
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Publish-AzWebApp -ArchivePath <String> [-Type <String>] [-Clean <Boolean>] [-Async <Boolean>]
[-Restart <Boolean>] [-TargetPath <String>] [-IgnoreStack <Boolean>] [-Reset <Boolean>] [-Force] [-AsJob]
[-Timeout <Double>] [-WebApp] <PSSite> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

### FromResourceName
```
Publish-AzWebApp -ArchivePath <String> [-Force] [-AsJob] [-Timeout <Double>] [-ResourceGroupName] <String>
[-Name] <String> [[-Slot] <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
Publish-AzWebApp -ArchivePath <String> [-Type <String>] [-Clean <Boolean>] [-Async <Boolean>]
[-Restart <Boolean>] [-TargetPath <String>] [-IgnoreStack <Boolean>] [-Reset <Boolean>] [-Force] [-AsJob]
[-Timeout <Double>] [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -106,6 +109,36 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Async
The artifact is deployed asynchronously. (The command will exit once the artifact is pushed to the web app.)
```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Clean
Cleans the target directory prior to deploying the file(s).
```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.
Expand Down Expand Up @@ -136,6 +169,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -IgnoreStack
Disables any language-specific defaults
```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
The name of the web app.
Expand All @@ -151,6 +199,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Reset
Reset Java web apps to default parking page
```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ResourceGroupName
The name of the resource group.
Expand All @@ -166,6 +229,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Restart
The web app will be restarted following the deployment. Set this to false if you are deploying multiple artifacts and do not want to restart the site on the earlier deployments.
```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Slot
The name of the web app slot.
Expand All @@ -181,6 +259,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -TargetPath
Absolute path that the artifact should be deployed to.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Timeout
Sets the timespan in Milliseconds to wait before the request times out.
Expand All @@ -196,6 +289,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Type
Used to override the type of artifact being deployed.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WebApp
The web app object
Expand Down

0 comments on commit 1a48344

Please sign in to comment.