Skip to content

Reintroduce the AzureWebApp netcoreshim #1425

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8740bc2
Use Library
rain-on Dec 17, 2024
f1a5768
clean up cherry-pick
rain-on Jan 15, 2025
62d1377
revert some files not needed
rain-on Jan 15, 2025
e8c3b6f
fixing the tests, slowly
rain-on Jan 15, 2025
c7a1932
remove cruft
rain-on Jan 15, 2025
8f56bdb
its finally passing
rain-on Jan 15, 2025
d34754d
Pulled in the changes required
rain-on Jan 15, 2025
3bda1fc
working with library
rain-on Jan 15, 2025
97e74b9
Merge remote-tracking branch 'origin/main' into tmm/redo_everything_f…
rain-on Jan 15, 2025
5ecbc2d
moved everything out of common package
rain-on Jan 15, 2025
fdaef73
also publish the consolidated library - whatever that means
rain-on Jan 15, 2025
8426277
still trying
rain-on Jan 15, 2025
aba7f9e
trying to make it work
rain-on Jan 15, 2025
95b54f1
updated build-system to publish the consol library
rain-on Jan 16, 2025
a7611fa
updated proj to make nuget
rain-on Jan 16, 2025
2dc7956
added the DEFINE_VERSION_ATTRIB const
rain-on Jan 16, 2025
895e033
not sure - think its getting there
rain-on Jan 16, 2025
e10c836
pulled in bits and pieces from tentacle to make shared libs work
rain-on Jan 16, 2025
8480085
was this overkill?
rain-on Jan 16, 2025
39162f8
its making a nupkg for consolidated - but its also going into package
rain-on Jan 16, 2025
a324d4c
clean up
rain-on Jan 16, 2025
ea2ede5
remove superfluous things
rain-on Jan 16, 2025
0d7194a
don't need it
rain-on Jan 16, 2025
d4a6eb2
revert oddness in CalamariFlavourProgram
rain-on Jan 16, 2025
4c08188
Merge remote-tracking branch 'origin/main' into tmm/redo_everything_f…
rain-on Jan 16, 2025
aba14b0
clean up
rain-on Jan 16, 2025
490ec9e
personal review
rain-on Jan 16, 2025
c3594c4
auto gen assembly info
rain-on Jan 16, 2025
5e3b221
Rever soln file
rain-on Jan 16, 2025
c8e673f
fix the namespacing
rain-on Jan 16, 2025
07dcf9d
Pull in AzureWebApp Netcore changes
rain-on Jan 17, 2025
987d36c
Fix up the MigratedCalamariPackages
rain-on Jan 17, 2025
dcdddb9
still trying
rain-on Jan 17, 2025
d5245fe
add netcoreshim to soln
rain-on Jan 17, 2025
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
62 changes: 46 additions & 16 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Calamari.ConsolidateCalamariPackages;
using NuGet.Packaging;
using Nuke.Common;
using Nuke.Common.CI.TeamCity;
Expand All @@ -17,6 +15,7 @@
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.NuGet;
using Nuke.Common.Utilities.Collections;
using Octopus.Calamari.ConsolidatedPackage;
using Serilog;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
Expand Down Expand Up @@ -112,7 +111,7 @@ public Build()
static AbsolutePath LocalPackagesDirectory => RootDirectory / "../LocalPackages";
static AbsolutePath ConsolidateCalamariPackagesProject => SourceDirectory / "Calamari.ConsolidateCalamariPackages.Tests" / "Calamari.ConsolidateCalamariPackages.Tests.csproj";
static AbsolutePath ConsolidatedPackageDirectory => ArtifactsDirectory / "consolidated";
static AbsolutePath LegacyCalamariDirectory = PublishDirectory / "Calamari.Legacy";
static AbsolutePath LegacyCalamariDirectory => PublishDirectory / "Calamari.Legacy";

Lazy<string> NugetVersion { get; }

Expand Down Expand Up @@ -189,6 +188,7 @@ public Build()

Target Publish =>
_ => _.DependsOn(Compile)
.DependsOn(PublishAzureWebAppNetCoreShim)
.Executes(() =>
{
if (!OperatingSystem.IsWindows())
Expand Down Expand Up @@ -329,11 +329,10 @@ void PublishPackage(CalamariPackageMetadata calamariPackageMetadata)
}

File.Copy(RootDirectory / "global.json", outputDirectory / "global.json");

}

static void StageLegacyCalamariAssemblies(CalamariPackageMetadata[] packagesToPublish) {

static void StageLegacyCalamariAssemblies(CalamariPackageMetadata[] packagesToPublish)
{
if (!OperatingSystem.IsWindows())
{
Log.Warning($"Skipping the bundling of Calamari projects into the Calamari.Legacy bundle. "
Expand Down Expand Up @@ -367,6 +366,33 @@ void CompressCalamariProject(Project project)
ProjectCompressionTasks.Add(compressionTask);
}

Target PublishAzureWebAppNetCoreShim =>
_ => _.DependsOn(Compile)
.Executes(() =>
{
if (!OperatingSystem.IsWindows())
{
Log.Warning("Unable to build Calamari.AzureWebApp.NetCoreShim as it's a Full Framework application and can only be compiled on Windows");
return;
}

var project = Solution.GetProject("Calamari.AzureWebApp.NetCoreShim");

var outputPath = PublishDirectory / project.Name;

DotNetPublish(s => s
.SetConfiguration(Configuration)
.SetProject(project.Path)
.SetFramework(Frameworks.Net462)
.EnableNoBuild()
.SetOutput(outputPath));

var archivePath = SourceDirectory / "Calamari.AzureWebApp" / "netcoreshim" / "netcoreshim.zip";
archivePath.DeleteFile();

outputPath.CompressTo(archivePath);
});

Target PackLegacyCalamari =>
_ => _.DependsOn(Publish)
.DependsOn(PublishCalamariFlavourProjects)
Expand All @@ -376,6 +402,7 @@ void CompressCalamariProject(Project project)
{
return;
}

Log.Verbose($"Compressing Calamari.Legacy");
LegacyCalamariDirectory.ZipTo(ArtifactsDirectory / $"Calamari.Legacy.{NugetVersion.Value}.zip");
});
Expand Down Expand Up @@ -419,6 +446,12 @@ void CompressCalamariProject(Project project)
foreach (var project in commonProjects)
packageActions.Add(() => SignAndPack(project.ToString(), dotNetCorePackSettings));

// Pack the Consolidation Library
var consolidateCalamariPackagesProjectName = "Calamari.ConsolidateCalamariPackages";
var consolidationCalamariProject = Solution.Projects.First(project => project.Name == consolidateCalamariPackagesProjectName);
packageActions.Add(() => SignAndPack(consolidationCalamariProject, dotNetCorePackSettings));


var sourceProjectPath =
SourceDirectory / "Calamari.CloudAccounts" / "Calamari.CloudAccounts.csproj";
packageActions.Add(() => SignAndPack(sourceProjectPath,
Expand Down Expand Up @@ -609,7 +642,8 @@ AbsolutePath DoPublish(string project, string framework, string version, string?
.SetVersion(NugetVersion.Value)
.SetVerbosity(BuildVerbosity)
.SetRuntime(runtimeId)
.SetVersion(version));
.SetVersion(version)
.EnableSelfContained());

if (WillSignBinaries)
Signing.SignAndTimestampBinaries(publishedTo, AzureKeyVaultUrl, AzureKeyVaultAppId,
Expand Down Expand Up @@ -685,8 +719,8 @@ void DoPackage(string project, string framework, string version, string? runtime
void SetOctopusServerCalamariVersion(string projectFile)
{
var text = File.ReadAllText(projectFile);
text = Regex.Replace(text, @"<PackageReference Include=""Calamari.Consolidated"" Version=""([\S])+""",
$"<PackageReference Include=\"Calamari.Consolidated\" Version=\"{NugetVersion.Value}\"");
text = Regex.Replace(text, @"<PackageReference Include=""Calamari.Consolidated"" Version=""([\S])+"" />",
$"<PackageReference Include=\"Calamari.Consolidated\" Version=\"{NugetVersion.Value}\" />");
File.WriteAllText(projectFile, text);
}

Expand All @@ -711,11 +745,7 @@ IReadOnlyCollection<string> GetRuntimeIdentifiers(Project? project)
return runtimes ?? Array.Empty<string>();
}

static List<string> GetCalamariFlavours()
{
return IsLocalBuild && !OperatingSystem.IsWindows()
? MigratedCalamariFlavours.CrossPlatformFlavours
: MigratedCalamariFlavours.Flavours;
}
//All libraries/flavours now support .NET Core
static List<string> GetCalamariFlavours() => CalamariPackages.Flavours;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Calamari.AzureAppService.Json
namespace Calamari.Azure.AppServices
{
public class AppSetting
{
Expand All @@ -14,7 +9,7 @@ public class AppSetting

public bool SlotSetting { get; set; }

internal void Deconstruct(out string name, out string value, out bool isSlotSetting)
public void Deconstruct(out string name, out string value, out bool isSlotSetting)
{
name = Name;
value = Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
#nullable enable
using System;
using Azure.Core;
using Azure.ResourceManager.AppService;
using Calamari.CloudAccounts;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;
using Microsoft.Azure.Management.Fluent;

#nullable enable
namespace Calamari.AzureAppService.Azure
namespace Calamari.Azure.AppServices
{
public class AzureTargetSite
{
Expand Down Expand Up @@ -64,12 +68,33 @@ public ResourceIdentifier CreateResourceIdentifier()
? WebSiteSlotResource.CreateResourceIdentifier(SubscriptionId, ResourceGroupName, Site, Slot)
: CreateWebSiteResourceIdentifier();
}

/// <summary>
/// Creates a new <see cref="ResourceIdentifier"/> for the root <see cref="WebSiteSlotResource"/>, even if this is targeting a slot.
/// </summary>
/// <returns></returns>
public ResourceIdentifier CreateWebSiteResourceIdentifier()
=> WebSiteResource.CreateResourceIdentifier(SubscriptionId, ResourceGroupName, Site);

public static AzureTargetSite Create(IAzureAccount account, IVariables variables, ILog? log = null, bool allowEmptyResourceGroupName = false)
{
var resourceGroupName = variables.Get(AzureVariables.Action.Azure.ResourceGroupName);
if (!allowEmptyResourceGroupName && string.IsNullOrEmpty(resourceGroupName))
throw new Exception("resource group name must be specified");
log?.Verbose($"Using Azure Resource Group '{resourceGroupName}'.");

var webAppName = variables.Get(AzureVariables.Action.Azure.WebAppName);
if (string.IsNullOrEmpty(webAppName))
throw new Exception("Web App Name must be specified");
log?.Verbose($"Using App Service Name '{webAppName}'.");

var slotName = variables.Get(AzureVariables.Action.Azure.WebAppSlot);
log?.Verbose(string.IsNullOrEmpty(slotName)
? "No Deployment Slot specified"
: $"Using Deployment Slot '{slotName}'");

return new AzureTargetSite(account.SubscriptionNumber, resourceGroupName, webAppName, slotName);
}
}
}
#nullable restore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Azure.ResourceManager.AppService.Models;

namespace Calamari.AzureAppService.Json
namespace Calamari.Azure.AppServices
{
public class ConnectionStringSetting
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Azure;
using Azure.ResourceManager;
using Azure.ResourceManager.AppService;
using Azure.ResourceManager.AppService.Models;
using Calamari.AzureAppService.Azure;
using Calamari.AzureAppService.Json;
using Calamari.Azure.AppServices;
using Octopus.CoreUtilities.Extensions;

namespace Calamari.AzureAppService
namespace Calamari.Azure
{
///<summary>
/// Provides a set of static methods for interacting with an <see cref="ArmClient"/> using an <see cref="AzureTargetSite"/>.
Expand Down
13 changes: 13 additions & 0 deletions source/Calamari.Azure/AzureAccountExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Calamari.CloudAccounts;
using Calamari.Common.Plumbing.Variables;

namespace Calamari.Azure
{
public static class AzureAccountExtensionMethods
{
public static bool HasAzureAccountJwt(this IVariables variables)
{
return !string.IsNullOrEmpty(variables.Get(AzureAccountVariables.OpenIDJwt));
}
}
}
25 changes: 25 additions & 0 deletions source/Calamari.Azure/AzureVariables.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Calamari.Azure
{
public static class AzureVariables
{
public static class Action
{
public static class Azure
{
/// <summary>
/// Expected Values:
/// Package,
/// Container,
/// </summary>
public static readonly string DeploymentType = "Octopus.Action.Azure.DeploymentType";

public static readonly string ResourceGroupName = "Octopus.Action.Azure.ResourceGroupName";
public static readonly string WebAppName = "Octopus.Action.Azure.WebAppName";
public static readonly string WebAppSlot = "Octopus.Action.Azure.DeploymentSlot";
public static readonly string AppSettings = "Octopus.Action.Azure.AppSettings";
public static readonly string ConnectionStrings = "Octopus.Action.Azure.ConnectionStrings";
public static readonly string AsyncZipDeploymentTimeout = "Octopus.Action.Azure.AsyncZipDeploymentTimeout";
}
}
}
}
1 change: 1 addition & 0 deletions source/Calamari.Azure/Calamari.Azure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Azure.ResourceManager" Version="1.11.0" />
<PackageReference Include="Azure.ResourceManager.AppService" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Calamari.CloudAccounts\Calamari.CloudAccounts.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Azure.ResourceManager.AppService.Models;
using Azure.ResourceManager.Resources;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.AzureAppService.Json;
using Calamari.CloudAccounts;
Expand Down Expand Up @@ -97,7 +98,8 @@ public async Task Setup()
// We keep them for 14 days just in case we need to do debugging/investigation
["LifetimeInDays"] = "14"
}
});
},
cancellationToken);

ResourceGroupResource = response.Value;

Expand All @@ -110,7 +112,7 @@ public async Task Setup()
public virtual async Task Cleanup()
{
await ArmClient.GetResourceGroupResource(ResourceGroupResource.CreateResourceIdentifier(SubscriptionId, ResourceGroupName))
.DeleteAsync(WaitUntil.Started);
.DeleteAsync(WaitUntil.Started, cancellationToken: cancellationToken);
}

protected async Task AssertContent(string hostName, string actualText, string rootPath = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Azure;
using Azure.ResourceManager.AppService.Models;
using Azure.ResourceManager.Resources;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.AzureAppService.Behaviors;
using Calamari.AzureAppService.Json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
using Azure.ResourceManager.AppService;
using Azure.ResourceManager.AppService.Models;
using Azure.ResourceManager.Resources;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.AzureAppService.Behaviors;
using Calamari.Common.Commands;
using Calamari.Common.Plumbing.Variables;
using Calamari.Testing;
using Calamari.Testing.Helpers;
using FluentAssertions;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure.ResourceManager;
using Azure.ResourceManager.AppService.Models;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.AzureAppService.Json;
using Calamari.CloudAccounts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Azure.ResourceManager;
using Azure.ResourceManager.AppService;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.CloudAccounts;
using Calamari.Common.Commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Azure.ResourceManager.AppService;
using Azure.ResourceManager.Resources;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.CloudAccounts;
using Calamari.Common.Commands;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Calamari.Azure;
using Calamari.Azure.AppServices;
using Calamari.AzureAppService.Azure;
using Calamari.CloudAccounts;
using Calamari.Common.Commands;
Expand Down
4 changes: 0 additions & 4 deletions source/Calamari.AzureAppService/Json/SlotSettingsNames.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

/*
* JSON format
Expand Down
Loading