Skip to content

Commit

Permalink
Fixed an ElasticBeanstalk deployment issue for Linux platform where P…
Browse files Browse the repository at this point in the history
…rocfile was sometimes being generated with incorrect entrypoint when multiple runtimeconfig.json files were present.
  • Loading branch information
ashishdhingra committed Feb 19, 2025
1 parent b2735be commit bff906a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .autover/changes/a4b5c0a2-7029-491b-90d1-12bba898c249.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.ElasticBeanstalk.Tools",
"Type": "Patch",
"ChangelogMessages": [
"Fixed an ElasticBeanstalk deployment issue for Linux platform where Procfile was sometimes being generated with incorrect entrypoint when multiple runtimeconfig.json files were present."
]
}
]
}
12 changes: 12 additions & 0 deletions src/Amazon.Common.DotNetCli.Tools/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ public static string LookupTargetFrameworkFromProjectFile(string projectLocation
return null;
}

/// <summary>
/// Looks up the assembly name from a project file.
/// </summary>
/// <param name="projectLocation">The location of the project file.</param>
/// <param name="msBuildParameters">Additonal MSBuild paramteres passed by the user from the commandline</param>
/// <returns>The assembly name of the project.</returns>
public static string LookupAssemblyNameFromProjectFile(string projectLocation, string msBuildParameters)
{
var properties = LookupProjectProperties(projectLocation, msBuildParameters, "AssemblyName");
return properties.TryGetValue("AssemblyName", out var assemblyName) ? assemblyName : null;
}

/// <summary>
/// Retrieve the `OutputType` property of a given project
/// </summary>
Expand Down
14 changes: 8 additions & 6 deletions src/Amazon.ElasticBeanstalk.Tools/EBUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using Amazon.Common.DotNetCli.Tools;
using Amazon.Common.DotNetCli.Tools.Options;
using Amazon.ElasticBeanstalk.Model;
using Amazon.ElasticBeanstalk.Tools.Commands;
using ThirdParty.Json.LitJson;
Expand Down Expand Up @@ -114,20 +115,21 @@ public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand comman
// Setup Procfile
var procfilePath = Path.Combine(publishLocation, "Procfile");

if(File.Exists(procfilePath))
if (File.Exists(procfilePath))
{
logger?.WriteLine("Found existing Procfile file found and using that for deployment");
return;
}

logger?.WriteLine("Writing Procfile for deployment bundle");
var projectLocation = Utilities.DetermineProjectLocation(command.WorkingDirectory,
command.GetStringValueOrDefault(command.ProjectLocation, CommonDefinedCommandOptions.ARGUMENT_PROJECT_LOCATION, false));

var runtimeConfigFilePath = Directory.GetFiles(publishLocation, "*.runtimeconfig.json").FirstOrDefault();
var runtimeConfigFileName = Path.GetFileName(runtimeConfigFilePath);
var executingAssembly = runtimeConfigFileName.Substring(0, runtimeConfigFileName.Length - "runtimeconfig.json".Length - 1);
var executingAssembly = Utilities.LookupAssemblyNameFromProjectFile(projectLocation, null);
var runtimeConfigFilePath = Directory.GetFiles(publishLocation, $"{executingAssembly}.runtimeconfig.json").FirstOrDefault();

string webCommandLine;
if(IsSelfContainedPublish(runtimeConfigFilePath))
if (IsSelfContainedPublish(runtimeConfigFilePath))
{
webCommandLine = $"./{executingAssembly}";
}
Expand All @@ -136,7 +138,7 @@ public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand comman
webCommandLine = $"dotnet exec ./{executingAssembly}.dll";
}

if(string.Equals(reverseProxy, EBConstants.PROXY_SERVER_NONE, StringComparison.InvariantCulture))
if (string.Equals(reverseProxy, EBConstants.PROXY_SERVER_NONE, StringComparison.InvariantCulture))
{
logger?.WriteLine("... Proxy server disabled, configuring Kestrel to listen to traffic from all hosts");
var port = applicationPort.HasValue ? applicationPort.Value : EBConstants.DEFAULT_APPLICATION_PORT;
Expand Down

0 comments on commit bff906a

Please sign in to comment.