Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support webapp windows container #1148

Merged
merged 5 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions Tests/Fluent.Tests/WebApp/WebAppsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,43 @@ public void WebAppWithoutPhp()
}
}
}

[Fact]
public void CanCRUDWebAppWithContainer()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be better ...WithWindowsContainer?

{
using (var context = FluentMockContext.Start(this.GetType().FullName))
{
string GroupName1 = TestUtilities.GenerateName("javacsmrg");
string WebAppName1 = TestUtilities.GenerateName("java-webapp-");
string AppServicePlanName1 = TestUtilities.GenerateName("java-asp-");

var appServiceManager = TestHelper.CreateAppServiceManager();

try
{
var appServicePlan = appServiceManager.AppServicePlans
.Define(AppServicePlanName1)
.WithRegion(Region.USEast) // many other regions does not have quota for PremiumP1v3
.WithNewResourceGroup(GroupName1)
.WithPricingTier(PricingTier.PremiumP1v3)
.WithOperatingSystem(OperatingSystem.Windows)
.Create();

var webApp = appServiceManager.WebApps.Define(WebAppName1)
.WithExistingWindowsPlan(appServicePlan)
.WithExistingResourceGroup(GroupName1)
.WithPublicDockerHubImage("mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest")
.Create();
}
finally
{
try
{
TestHelper.CreateResourceManager().ResourceGroups.BeginDeleteByName(GroupName1);
}
catch { }
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ WebApp.Update.IWithCredentials WebApp.Update.IWithDockerContainerImage.WithPriva
/// </summary>
/// <param name="imageAndTag">Image and optional tag (eg 'image:tag').</param>
/// <return>The next stage of the definition.</return>
WebApp.Definition.IWithCredentials WebApp.Definition.IWithDockerContainerImage.WithPrivateDockerHubImage(string imageAndTag)
WebApp.Definition.IWithCredentials WebApp.Definition.IWithContainerImage.WithPrivateDockerHubImage(string imageAndTag)
{
return this.WithPrivateDockerHubImage(imageAndTag);
}
Expand All @@ -213,7 +213,7 @@ WebApp.Definition.IWithCredentials WebApp.Definition.IWithDockerContainerImage.W
/// </summary>
/// <param name="imageAndTag">Image and optional tag (eg 'image:tag').</param>
/// <return>The next stage of the definition.</return>
WebApp.Definition.IWithStartUpCommand WebApp.Definition.IWithDockerContainerImage.WithPublicDockerHubImage(string imageAndTag)
WebApp.Definition.IWithStartUpCommand WebApp.Definition.IWithContainerImage.WithPublicDockerHubImage(string imageAndTag)
{
return this.WithPublicDockerHubImage(imageAndTag);
}
Expand All @@ -234,7 +234,7 @@ WebApp.Definition.IWithCreate WebApp.Definition.IWithDockerContainerImage.WithBu
/// <param name="imageAndTag">Image and optional tag (eg 'image:tag').</param>
/// <param name="serverUrl">The URL to the private registry server.</param>
/// <return>The next stage of the definition.</return>
WebApp.Definition.IWithCredentials WebApp.Definition.IWithDockerContainerImage.WithPrivateRegistryImage(string imageAndTag, string serverUrl)
WebApp.Definition.IWithCredentials WebApp.Definition.IWithContainerImage.WithPrivateRegistryImage(string imageAndTag, string serverUrl)
{
return this.WithPrivateRegistryImage(imageAndTag, serverUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public interface IDefinition :
Microsoft.Azure.Management.AppService.Fluent.WebApp.Definition.IWithDockerContainerImage,
Microsoft.Azure.Management.AppService.Fluent.WebApp.Definition.IWithCredentials,
Microsoft.Azure.Management.AppService.Fluent.WebApp.Definition.IWithStartUpCommand,
IWithWindowsRuntimeStack,
Microsoft.Azure.Management.AppService.Fluent.WebApp.Definition.IWithCreate
{
}
Expand Down Expand Up @@ -226,9 +227,9 @@ public interface INewAppServicePlanWithGroup :
}

/// <summary>
/// A web app definition allowing docker image source to be specified.
/// A web app definition allowing container image source to be specified.
/// </summary>
public interface IWithDockerContainerImage
public interface IWithContainerImage
{
/// <summary>
/// Specifies the docker container image to be one from Docker Hub.
Expand All @@ -252,6 +253,13 @@ public interface IWithDockerContainerImage
/// <return>The next stage of the definition.</return>
Microsoft.Azure.Management.AppService.Fluent.WebApp.Definition.IWithCredentials WithPrivateRegistryImage(string imageAndTag, string serverUrl);

}

/// <summary>
/// A web app definition allowing docker image source to be specified.
/// </summary>
public interface IWithDockerContainerImage : IWithContainerImage
{
/// <summary>
/// Specifies the docker container image to be a built in one.
/// </summary>
Expand All @@ -263,7 +271,7 @@ public interface IWithDockerContainerImage
/// <summary>
/// A web app definition allowing runtime stack on Windows operating system to be specified.
/// </summary>
public interface IWithWindowsRuntimeStack : IWithCreate
public interface IWithWindowsRuntimeStack : IWithContainerImage, IWithCreate
{
/// <summary>
/// Specifies the runtime stack for the web app on Windows operating system.
Expand All @@ -272,4 +280,4 @@ public interface IWithWindowsRuntimeStack : IWithCreate
/// <returns>The next stage of the definition.</returns>
IWithCreate WithRuntimeStack(WebAppRuntimeStack runtimeStack);
}
}
}
3 changes: 3 additions & 0 deletions src/ResourceManagement/AppService/PricingTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public partial class PricingTier
public static readonly PricingTier PremiumP1v2 = new PricingTier("PremiumV2", "P1v2");
public static readonly PricingTier PremiumP2v2 = new PricingTier("PremiumV2", "P2v2");
public static readonly PricingTier PremiumP3v2 = new PricingTier("PremiumV2", "P3v2");
public static readonly PricingTier PremiumP1v3 = new PricingTier("PremiumV3", "P1v3");
public static readonly PricingTier PremiumP2v3 = new PricingTier("PremiumV3", "P2v3");
public static readonly PricingTier PremiumP3v3 = new PricingTier("PremiumV3", "P3v3");
public static readonly PricingTier FreeF1 = new PricingTier("Free", "F1");
public static readonly PricingTier SharedD1 = new PricingTier("Shared", "D1");
public static readonly PricingTier ConsumptionY1 = new PricingTier("Dynamic", "Y1");
Expand Down
38 changes: 23 additions & 15 deletions src/ResourceManagement/AppService/WebAppImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ internal partial class WebAppImpl :
WebApp.Update.IUpdate,
WebApp.Definition.IExistingWindowsPlanWithGroup,
WebApp.Definition.IExistingLinuxPlanWithGroup,
WebApp.Definition.IWithWindowsRuntimeStack,
WebApp.Update.IWithAppServicePlan,
WebApp.Update.IWithCredentials,
WebApp.Update.IWithStartUpCommand
Expand Down Expand Up @@ -109,13 +108,20 @@ internal override async Task<SiteInner> SubmitMetadataAsync(SiteInner site, Canc
///GENMHASH:E73A2BC2090FC3A00E0D2D18D7506D67:BFA1AA102FC308FAD095DF52D3D7C9F1
public WebAppImpl WithPrivateRegistryImage(string imageAndTag, string serverUrl)
{
EnsureLinuxPlan();
//EnsureLinuxPlan();
CleanUpContainerSettings();
if (SiteConfig == null)
{
SiteConfig = new SiteConfigResourceInner();
}
SiteConfig.LinuxFxVersion = string.Format("DOCKER|{0}", imageAndTag);
if (OperatingSystem() == Fluent.OperatingSystem.Windows)
{
SiteConfig.WindowsFxVersion = string.Format("DOCKER|{0}", imageAndTag);
}
else
{
SiteConfig.LinuxFxVersion = string.Format("DOCKER|{0}", imageAndTag);
}
WithAppSetting(SETTING_DOCKER_IMAGE, imageAndTag);
WithAppSetting(SETTING_REGISTRY_SERVER, serverUrl);
return this;
Expand All @@ -124,6 +130,10 @@ public WebAppImpl WithPrivateRegistryImage(string imageAndTag, string serverUrl)
///GENMHASH:602C33B7B682DA260F6CBFC17D1C7E12:E4FC04D27E28502A10F31E38E988A897
private void CleanUpContainerSettings()
{
if (SiteConfig != null && SiteConfig.WindowsFxVersion != null)
{
SiteConfig.WindowsFxVersion = null;
}
if (SiteConfig != null && SiteConfig.LinuxFxVersion != null)
{
SiteConfig.LinuxFxVersion = null;
Expand Down Expand Up @@ -165,24 +175,22 @@ public WebAppImpl WithExistingLinuxPlan(IAppServicePlan appServicePlan)
///GENMHASH:D15FB33BB43555A701A8FD43F244B1D9:2B645488043FF9B7C9FE21F5BC901768
public WebAppImpl WithPublicDockerHubImage(string imageAndTag)
{
EnsureLinuxPlan();
//EnsureLinuxPlan();
CleanUpContainerSettings();
if (SiteConfig == null)
{
SiteConfig = new SiteConfigResourceInner();
}
SiteConfig.LinuxFxVersion = string.Format("DOCKER|{0}", imageAndTag);
WithAppSetting(SETTING_DOCKER_IMAGE, imageAndTag);
return this;
}

///GENMHASH:4554623A20A1D1D6CA43597FA7713AD7:DD8E427B2F3E82987E90A2D5CCB5E193
private void EnsureLinuxPlan()
{
if (Fluent.OperatingSystem.Windows.Equals(OperatingSystem()))
if (OperatingSystem() == Fluent.OperatingSystem.Windows)
{
throw new InvalidOperationException("Docker container settings only apply to Linux app service plans.");
SiteConfig.WindowsFxVersion = string.Format("DOCKER|{0}", imageAndTag);
}
else
{
SiteConfig.LinuxFxVersion = string.Format("DOCKER|{0}", imageAndTag);
}
WithAppSetting(SETTING_DOCKER_IMAGE, imageAndTag);
return this;
}

///GENMHASH:6799EDFB0B008F8C0EB7E07EE71E6B34:9AA0391980CD01ABEA62130DB5348393
Expand Down Expand Up @@ -243,7 +251,7 @@ public WebAppImpl WithCredentials(string username, string password)
///GENMHASH:F7734222FF39440A50483317E5DF8156:998FF6187B952D74EE89FFECAAB847A3
public WebAppImpl WithBuiltInImage(RuntimeStack runtimeStack)
{
EnsureLinuxPlan();
//EnsureLinuxPlan();
CleanUpContainerSettings();
if (SiteConfig == null) {
SiteConfig = new SiteConfigResourceInner();
Expand Down