Skip to content

Commit 1a48344

Browse files
authored
Update Publish-AzWebApp to use OneDeploy API for all deployment artifacts (#21749)
1 parent 31e581c commit 1a48344

File tree

8 files changed

+2986
-861
lines changed

8 files changed

+2986
-861
lines changed

src/Websites/Websites.Test/ScenarioTests/WebAppTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ public void TestPublishWebAppFromWar()
103103
TestRunner.RunTestScript("Test-PublishAzureWebAppFromWar");
104104
}
105105

106+
[Fact]
107+
[Trait(Category.RunType, Category.LiveOnly)]
108+
public void TestPublishWebAppOneDeploy()
109+
{
110+
TestRunner.RunTestScript("Test-PublishAzureWebAppOneDeploy");
111+
}
112+
106113
[Fact]
107114
[Trait(Category.AcceptanceType, Category.CheckIn)]
108115
public void TestCloneNewWebApp()

src/Websites/Websites.Test/ScenarioTests/WebAppTests.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ function Test-WebAppPublishingProfile
14641464
}
14651465
}
14661466

1467+
# Keep existing test to ensure backwards compatibility with existing behavior
14671468
function Test-PublishAzureWebAppFromZip
14681469
{
14691470
# Setup
@@ -1494,6 +1495,7 @@ function Test-PublishAzureWebAppFromZip
14941495
}
14951496
}
14961497

1498+
# Keep existing test to ensure backwards compatibility with existing behavior
14971499
function Test-PublishAzureWebAppFromWar
14981500
{
14991501
# Setup
@@ -1533,6 +1535,46 @@ function Test-PublishAzureWebAppFromWar
15331535
}
15341536
}
15351537

1538+
# New tests for PublishAzureWebApp to test deploying against newer Onedeploy endpoint
1539+
function Test-PublishAzureWebAppOnedeploy
1540+
{
1541+
# Setup
1542+
$rgname = Get-ResourceGroupName
1543+
$appName = Get-WebsiteName
1544+
$location = Get-WebLocation
1545+
$planName = Get-WebHostPlanName
1546+
$tier = "Shared"
1547+
1548+
try
1549+
{
1550+
#Setup
1551+
New-AzureRmResourceGroup -Name $rgname -Location $location
1552+
$serverFarm = New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $planName -Location $location -Tier $tier
1553+
1554+
# Create new web app
1555+
$webapp = New-AzureRmWebApp -ResourceGroupName $rgname -Name $appName -Location $location -AppServicePlan $planName
1556+
1557+
#Configuring jdk and web container
1558+
# Set Java runtime to 1.8 | Tomcat. In order to deploy war, site should be configured to run with stack = TOMCAT
1559+
# or JBOSSEAP (only availble on Linux). In this test case, it creates Windows app.
1560+
$javaVersion="1.8"
1561+
$javaContainer="TOMCAT"
1562+
$javaContainerVersion="8.5"
1563+
$PropertiesObject = @{javaVersion = $javaVersion;javaContainer = $javaContainer;javaContainerVersion = $javaContainerVersion}
1564+
New-AzResource -PropertyObject $PropertiesObject -ResourceGroupName $rgname -ResourceType Microsoft.Web/sites/config -ResourceName "$appName/web" -ApiVersion 2018-02-01 -Force
1565+
1566+
$warPath = Join-Path $ResourcesPath "HelloJava.war"
1567+
$publishedApp = Publish-AzWebApp -ResourceGroupName $rgname -Name $appName -ArchivePath $warPath -Type war -Clean $true -TargetPath /home/site/wwwroot/webapps/ROOT -Force
1568+
1569+
Assert-NotNull $publishedApp
1570+
}
1571+
finally
1572+
{
1573+
# Cleanup
1574+
Remove-AzureRmResourceGroup -Name $rgname -Force
1575+
}
1576+
}
1577+
15361578
<#
15371579
.SYNOPSIS
15381580
Tests creating a web app with a simple parameterset.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests/TestPublishWebAppFromWar.json

Lines changed: 563 additions & 335 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests/TestPublishWebAppFromZip.json

Lines changed: 344 additions & 515 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests/TestPublishWebAppOneDeploy.json

Lines changed: 1856 additions & 0 deletions
Large diffs are not rendered by default.

src/Websites/Websites/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

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

2526
## Version 2.15.0
2627
* Fixed Tag parameter issues with ASE for `New-AzWebApp`

src/Websites/Websites/Cmdlets/WebApps/PublishAzureWebApp.cs

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2121
using System;
2222
using System.IO;
23+
using System.Linq;
2324
using System.Management.Automation;
2425
using System.Net;
2526
using System.Net.Http;
2627
using System.Net.Http.Headers;
2728
using System.Text;
2829
using System.Threading;
30+
using System.Web;
2931

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

47+
[Parameter(Mandatory = false, HelpMessage = "Used to override the type of artifact being deployed.")]
48+
[ValidateSet("war", "jar", "ear", "zip", "static")]
49+
public string Type { get; set; }
50+
51+
[Parameter(Mandatory = false, HelpMessage = "Cleans the target directory prior to deploying the file(s).")]
52+
public SwitchParameter Clean { get; set; }
53+
54+
[Parameter(Mandatory = false, HelpMessage = "The artifact is deployed asynchronously. (The command will exit once the artifact is pushed to the web app.)")]
55+
public SwitchParameter Async { get; set; }
56+
57+
[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.")]
58+
public SwitchParameter Restart { get; set; }
59+
60+
[Parameter(Mandatory = false, HelpMessage = "Absolute path that the artifact should be deployed to.")]
61+
public string TargetPath { get; set; }
62+
63+
[Parameter(Mandatory = false, HelpMessage = "Disables any language-specific defaults")]
64+
public SwitchParameter IgnoreStack { get; set; }
65+
66+
[Parameter(Mandatory = false, HelpMessage = "Reset Java web apps to default parking page")]
67+
public SwitchParameter Reset { get; set; }
68+
4569
[Parameter(Mandatory = false, HelpMessage = "Deploy the web app without prompting for confirmation.")]
4670
public SwitchParameter Force { get; set; }
4771

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

6084
HttpResponseMessage r;
61-
string deployUrl;
6285
string deploymentStatusUrl = user.ScmUri + "/api/deployments/latest";
6386

64-
if (ArchivePath.ToLower().EndsWith("war"))
87+
string apiPath = "/api/publish";
88+
var scmUrl = new Uri(user.ScmUri);
89+
var deployUri = new Uri(scmUrl, apiPath);
90+
91+
var uriBuilder = new UriBuilder(deployUri);
92+
var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query);
93+
94+
string fileExtention = Path.GetExtension(ArchivePath);
95+
string[] validTypes = { "war", "jar", "ear", "zip", "static" };
96+
97+
if (!string.IsNullOrEmpty(Type))
6598
{
66-
deployUrl = user.ScmUri + "/api/publish?type=war";
99+
paramValues["type"] = Type;
67100
}
68-
else if (ArchivePath.ToLower().EndsWith("zip") || ArchivePath.ToLower().EndsWith("jar"))
101+
102+
else if (!string.IsNullOrEmpty(fileExtention))
69103
{
70-
deployUrl = user.ScmUri + "/api/zipdeploy?isAsync=true";
104+
if (validTypes.Contains(fileExtention.Substring(1)))
105+
{
106+
paramValues["type"] = fileExtention.Substring(1);
107+
}
108+
109+
else
110+
{
111+
paramValues["type"] = "static";
112+
}
71113
}
114+
72115
else
73116
{
74-
throw new Exception("Unknown archive type.");
117+
throw new Exception("Unknown artifact type.");
75118
}
76119

120+
paramValues.Add("path", TargetPath);
121+
paramValues.Add("isasync", Async.IsPresent.ToString());
122+
paramValues.Add("restart", Restart.IsPresent.ToString());
123+
paramValues.Add("clean", Clean.IsPresent.ToString());
124+
paramValues.Add("ignorestack", IgnoreStack.IsPresent.ToString());
125+
paramValues.Add("reset", Reset.IsPresent.ToString());
126+
127+
uriBuilder.Query = paramValues.ToString();
128+
129+
string deployUrl = uriBuilder.Uri.ToString();
130+
77131
Action zipDeployAction = () =>
78132
{
79133
if (!Path.IsPathRooted(ArchivePath))

src/Websites/Websites/help/Publish-AzWebApp.md

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ Deploys an Azure Web App from a ZIP, JAR, or WAR file using zipdeploy.
1414

1515
### FromWebApp (Default)
1616
```
17-
Publish-AzWebApp -ArchivePath <String> [-Force] [-AsJob] [-Timeout <Double>] [-WebApp] <PSSite>
18-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
17+
Publish-AzWebApp -ArchivePath <String> [-Type <String>] [-Clean <Boolean>] [-Async <Boolean>]
18+
[-Restart <Boolean>] [-TargetPath <String>] [-IgnoreStack <Boolean>] [-Reset <Boolean>] [-Force] [-AsJob]
19+
[-Timeout <Double>] [-WebApp] <PSSite> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
20+
[<CommonParameters>]
1921
```
2022

2123
### FromResourceName
2224
```
23-
Publish-AzWebApp -ArchivePath <String> [-Force] [-AsJob] [-Timeout <Double>] [-ResourceGroupName] <String>
24-
[-Name] <String> [[-Slot] <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
25-
[<CommonParameters>]
25+
Publish-AzWebApp -ArchivePath <String> [-Type <String>] [-Clean <Boolean>] [-Async <Boolean>]
26+
[-Restart <Boolean>] [-TargetPath <String>] [-IgnoreStack <Boolean>] [-Reset <Boolean>] [-Force] [-AsJob]
27+
[-Timeout <Double>] [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String>]
28+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2629
```
2730

2831
## DESCRIPTION
@@ -106,6 +109,36 @@ Accept pipeline input: False
106109
Accept wildcard characters: False
107110
```
108111
112+
### -Async
113+
The artifact is deployed asynchronously. (The command will exit once the artifact is pushed to the web app.)
114+
115+
```yaml
116+
Type: System.Boolean
117+
Parameter Sets: (All)
118+
Aliases:
119+
120+
Required: False
121+
Position: Named
122+
Default value: None
123+
Accept pipeline input: False
124+
Accept wildcard characters: False
125+
```
126+
127+
### -Clean
128+
Cleans the target directory prior to deploying the file(s).
129+
130+
```yaml
131+
Type: System.Boolean
132+
Parameter Sets: (All)
133+
Aliases:
134+
135+
Required: False
136+
Position: Named
137+
Default value: None
138+
Accept pipeline input: False
139+
Accept wildcard characters: False
140+
```
141+
109142
### -DefaultProfile
110143
The credentials, account, tenant, and subscription used for communication with Azure.
111144
@@ -136,6 +169,21 @@ Accept pipeline input: False
136169
Accept wildcard characters: False
137170
```
138171
172+
### -IgnoreStack
173+
Disables any language-specific defaults
174+
175+
```yaml
176+
Type: System.Boolean
177+
Parameter Sets: (All)
178+
Aliases:
179+
180+
Required: False
181+
Position: Named
182+
Default value: None
183+
Accept pipeline input: False
184+
Accept wildcard characters: False
185+
```
186+
139187
### -Name
140188
The name of the web app.
141189
@@ -151,6 +199,21 @@ Accept pipeline input: True (ByPropertyName)
151199
Accept wildcard characters: False
152200
```
153201
202+
### -Reset
203+
Reset Java web apps to default parking page
204+
205+
```yaml
206+
Type: System.Boolean
207+
Parameter Sets: (All)
208+
Aliases:
209+
210+
Required: False
211+
Position: Named
212+
Default value: None
213+
Accept pipeline input: False
214+
Accept wildcard characters: False
215+
```
216+
154217
### -ResourceGroupName
155218
The name of the resource group.
156219
@@ -166,6 +229,21 @@ Accept pipeline input: True (ByPropertyName)
166229
Accept wildcard characters: False
167230
```
168231
232+
### -Restart
233+
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.
234+
235+
```yaml
236+
Type: System.Boolean
237+
Parameter Sets: (All)
238+
Aliases:
239+
240+
Required: False
241+
Position: Named
242+
Default value: None
243+
Accept pipeline input: False
244+
Accept wildcard characters: False
245+
```
246+
169247
### -Slot
170248
The name of the web app slot.
171249
@@ -181,6 +259,21 @@ Accept pipeline input: True (ByPropertyName)
181259
Accept wildcard characters: False
182260
```
183261
262+
### -TargetPath
263+
Absolute path that the artifact should be deployed to.
264+
265+
```yaml
266+
Type: System.String
267+
Parameter Sets: (All)
268+
Aliases:
269+
270+
Required: False
271+
Position: Named
272+
Default value: None
273+
Accept pipeline input: False
274+
Accept wildcard characters: False
275+
```
276+
184277
### -Timeout
185278
Sets the timespan in Milliseconds to wait before the request times out.
186279
@@ -196,6 +289,21 @@ Accept pipeline input: False
196289
Accept wildcard characters: False
197290
```
198291
292+
### -Type
293+
Used to override the type of artifact being deployed.
294+
295+
```yaml
296+
Type: System.String
297+
Parameter Sets: (All)
298+
Aliases:
299+
300+
Required: False
301+
Position: Named
302+
Default value: None
303+
Accept pipeline input: False
304+
Accept wildcard characters: False
305+
```
306+
199307
### -WebApp
200308
The web app object
201309

0 commit comments

Comments
 (0)