diff --git a/.autover/changes/a4b5c0a2-7029-491b-90d1-12bba898c249.json b/.autover/changes/a4b5c0a2-7029-491b-90d1-12bba898c249.json new file mode 100644 index 0000000..c92ceed --- /dev/null +++ b/.autover/changes/a4b5c0a2-7029-491b-90d1-12bba898c249.json @@ -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." + ] + } + ] +} \ No newline at end of file diff --git a/src/Amazon.Common.DotNetCli.Tools/Utilities.cs b/src/Amazon.Common.DotNetCli.Tools/Utilities.cs index acc264b..bf18c50 100644 --- a/src/Amazon.Common.DotNetCli.Tools/Utilities.cs +++ b/src/Amazon.Common.DotNetCli.Tools/Utilities.cs @@ -334,6 +334,18 @@ public static string LookupTargetFrameworkFromProjectFile(string projectLocation return null; } + /// + /// Looks up the assembly name from a project file. + /// + /// The location of the project file. + /// Additional MSBuild parameters passed by the user from the commandline + /// The assembly name of the project. + public static string LookupAssemblyNameFromProjectFile(string projectLocation, string msBuildParameters) + { + var properties = LookupProjectProperties(projectLocation, msBuildParameters, "AssemblyName"); + return properties.TryGetValue("AssemblyName", out var assemblyName) ? assemblyName : null; + } + /// /// Retrieve the `OutputType` property of a given project /// diff --git a/src/Amazon.ElasticBeanstalk.Tools/Commands/DeployEnvironmentCommand.cs b/src/Amazon.ElasticBeanstalk.Tools/Commands/DeployEnvironmentCommand.cs index 07505f1..9aa1bec 100644 --- a/src/Amazon.ElasticBeanstalk.Tools/Commands/DeployEnvironmentCommand.cs +++ b/src/Amazon.ElasticBeanstalk.Tools/Commands/DeployEnvironmentCommand.cs @@ -183,7 +183,7 @@ protected override async Task PerformActionAsync() } this.Logger?.WriteLine("Configuring application bundle for a Linux deployment"); - EBUtilities.SetupPackageForLinux(this.Logger, this, this.DeployEnvironmentOptions, publishLocation, proxyServer, applicationPort); + EBUtilities.SetupPackageForLinux(this.Logger, this, this.DeployEnvironmentOptions, publishLocation, proxyServer, applicationPort, projectLocation); } zipArchivePath = Path.Combine(Directory.GetParent(publishLocation).FullName, new DirectoryInfo(projectLocation).Name + "-" + DateTime.Now.Ticks + ".zip"); diff --git a/src/Amazon.ElasticBeanstalk.Tools/EBUtilities.cs b/src/Amazon.ElasticBeanstalk.Tools/EBUtilities.cs index 964397b..be0e79b 100644 --- a/src/Amazon.ElasticBeanstalk.Tools/EBUtilities.cs +++ b/src/Amazon.ElasticBeanstalk.Tools/EBUtilities.cs @@ -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; @@ -109,25 +110,23 @@ public static bool IsLoadBalancedEnvironmentType(string environmentType) } - public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand command, DeployEnvironmentProperties options, string publishLocation, string reverseProxy, int? applicationPort) + public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand command, DeployEnvironmentProperties options, string publishLocation, string reverseProxy, int? applicationPort, string projectLocation) { // 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 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}"; } @@ -136,7 +135,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;