Skip to content

Commit

Permalink
Enable jar file deployments for Azure app service (#1386)
Browse files Browse the repository at this point in the history
* Allow jar files for Azure App Service deployments

* Add jar deploy test

* Replace test jar file

* Simplify test due to long jar servlet startup time

* Add upload path param for java deployments

* Configure test app services to allow java deployments
  • Loading branch information
bec-callow-oct authored Nov 21, 2024
1 parent a1c2fad commit fb29d51
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,48 @@ await DoWithRetries(3,
},
secondsBetweenRetries: 10);
}

[Test]
public async Task CanDeployJarPackage()
{
// Need to spin up a specific app service with Java installed
var javaSite = await ResourceGroupResource.GetWebSites()
.CreateOrUpdateAsync(WaitUntil.Completed,
$"{ResourceGroupName}-java",
new WebSiteData(ResourceGroupResource.Data.Location)
{
AppServicePlanId = appServicePlanResource.Data.Id,
SiteConfig = new SiteConfigProperties
{
JavaVersion = "1.8",
JavaContainer = "JAVA",
JavaContainerVersion = "9.0",
AppSettings = new List<AppServiceNameValuePair>
{
new AppServiceNameValuePair { Name = "WEBSITES_CONTAINER_START_TIME_LIMIT", Value = "600" },
new AppServiceNameValuePair { Name = "WEBSITE_SCM_ALWAYS_ON_ENABLED", Value = "true" }
}
}
});

(string packagePath, string packageName, string packageVersion) packageinfo;
var assemblyFileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
packageinfo.packagePath = Path.Combine(assemblyFileInfo.Directory.FullName, "sample4-1.0.0.jar");
packageinfo.packageVersion = "1.0.0";
packageinfo.packageName = "sample4";
greeting = "java";

var commandResult = await CommandTestBuilder.CreateAsync<DeployAzureAppServiceCommand, Program>()
.WithArrange(context =>
{
context.WithPackage(packageinfo.packagePath, packageinfo.packageName, packageinfo.packageVersion);
AddVariables(context);
context.Variables[SpecialVariables.Action.Azure.WebAppName] = javaSite.Value.Data.Name;
})
.Execute();

commandResult.Outcome.Should().Be(TestExecutionOutcome.Successful);
}

[Test]
public async Task DeployingWithInvalidEnvironment_ThrowsAnException()
Expand Down Expand Up @@ -369,6 +411,7 @@ public class WhenUsingALinuxAppService : AppServiceIntegrationTest

static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
readonly CancellationToken cancellationToken = CancellationTokenSource.Token;
AppServicePlanResource appServicePlanResource;

protected override async Task ConfigureTestResources(ResourceGroupResource resourceGroup)
{
Expand Down Expand Up @@ -405,6 +448,8 @@ protected override async Task ConfigureTestResources(ResourceGroupResource resou

await linuxAppServicePlan.WaitForCompletionAsync(cancellationToken);

appServicePlanResource = linuxAppServicePlan.Value;

var linuxWebSiteResponse = await resourceGroup.GetWebSites()
.CreateOrUpdateAsync(WaitUntil.Completed,
$"{resourceGroup.Data.Name}-linux",
Expand Down Expand Up @@ -523,6 +568,48 @@ await AssertContent(WebSiteResource.Data.DefaultHostName,
},
secondsBetweenRetries: 10);
}

[Test]
public async Task CanDeployJarPackage()
{
// Need to spin up a specific app service with Java installed
var javaSite = await ResourceGroupResource.GetWebSites()
.CreateOrUpdateAsync(WaitUntil.Completed,
$"{ResourceGroupName}-java",
new WebSiteData(ResourceGroupResource.Data.Location)
{
AppServicePlanId = appServicePlanResource.Data.Id,
SiteConfig = new SiteConfigProperties
{
IsAlwaysOn = true,
LinuxFxVersion = "JAVA|21-java21",
Use32BitWorkerProcess = true,
AppSettings = new List<AppServiceNameValuePair>
{
new AppServiceNameValuePair { Name = "WEBSITES_CONTAINER_START_TIME_LIMIT", Value = "460" },
new AppServiceNameValuePair { Name = "WEBSITE_SCM_ALWAYS_ON_ENABLED", Value = "true"}
}
}
});

(string packagePath, string packageName, string packageVersion) packageinfo;
var assemblyFileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
packageinfo.packagePath = Path.Combine(assemblyFileInfo.Directory.FullName, "sample4-1.0.0.jar");
packageinfo.packageVersion = "1.0.0";
packageinfo.packageName = "sample4";
greeting = "java";

var commandResult = await CommandTestBuilder.CreateAsync<DeployAzureAppServiceCommand, Program>()
.WithArrange(context =>
{
context.WithPackage(packageinfo.packagePath, packageinfo.packageName, packageinfo.packageVersion);
AddVariables(context);
context.Variables[SpecialVariables.Action.Azure.WebAppName] = javaSite.Value.Data.Name;
})
.Execute();

commandResult.Outcome.Should().Be(TestExecutionOutcome.Successful);
}

private static (string packagePath, string packageName, string packageVersion) PrepareZipPackage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<None Update="sample.1.0.0.war">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="sample4-1.0.0.jar">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="functionapp.1.0.0.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@

namespace Calamari.AzureAppService
{
public class WarPackageProvider : IPackageProvider
public class JavaPackageProvider : IPackageProvider
{
readonly ICalamariFileSystem fileSystem;
public bool SupportsAsynchronousDeployment => false;
private ILog Log { get; }
private IVariables Variables { get; }
private RunningDeployment Deployment { get; }
public string UploadUrlPath { get; }

public WarPackageProvider(ILog log, ICalamariFileSystem fileSystem, IVariables variables, RunningDeployment deployment)
public JavaPackageProvider(ILog log, ICalamariFileSystem fileSystem, IVariables variables, RunningDeployment deployment, string uploadUrlPath)
{
this.fileSystem = fileSystem;
Log = log;
Variables = variables;
Deployment = deployment;
UploadUrlPath = uploadUrlPath;
}

public string UploadUrlPath => @"/api/wardeploy";

public async Task<FileInfo> PackageArchive(string sourceDirectory, string targetDirectory)
{
var cmdLineRunner = new CommandLineRunner(Log, Variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public async Task Execute(RunningDeployment context)
{
".zip" => new ZipPackageProvider(),
".nupkg" => new NugetPackageProvider(),
".war" => new WarPackageProvider(Log, fileSystem, variables, context),
".war" => new JavaPackageProvider(Log, fileSystem, variables, context, "/api/wardeploy"),
".jar" => new JavaPackageProvider(Log, fileSystem, variables, context, "/api/publish?type=jar"),
_ => throw new Exception("Unsupported archive type")
};

Expand Down

0 comments on commit fb29d51

Please sign in to comment.