Skip to content

Commit e247673

Browse files
committed
Fixed an ElasticBeanstalk deployment issue for Linux platform where Procfile was sometimes being generated with incorrect entrypoint when multiple runtimeconfig.json files were present.
1 parent b2735be commit e247673

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.ElasticBeanstalk.Tools",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Fixed an ElasticBeanstalk deployment issue for Linux platform where Procfile was sometimes being generated with incorrect entrypoint when multiple runtimeconfig.json files were present."
8+
]
9+
}
10+
]
11+
}

src/Amazon.Common.DotNetCli.Tools/Utilities.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ public static string LookupTargetFrameworkFromProjectFile(string projectLocation
334334
return null;
335335
}
336336

337+
/// <summary>
338+
/// Looks up the assembly name from a project file.
339+
/// </summary>
340+
/// <param name="projectLocation">The location of the project file.</param>
341+
/// <param name="msBuildParameters">Additonal MSBuild paramteres passed by the user from the commandline</param>
342+
/// <returns>The assembly name of the project.</returns>
343+
public static string LookupAssemblyNameFromProjectFile(string projectLocation, string msBuildParameters)
344+
{
345+
var properties = LookupProjectProperties(projectLocation, msBuildParameters, "AssemblyName");
346+
return properties.TryGetValue("AssemblyName", out var assemblyName) ? assemblyName : null;
347+
}
348+
337349
/// <summary>
338350
/// Retrieve the `OutputType` property of a given project
339351
/// </summary>

src/Amazon.ElasticBeanstalk.Tools/Commands/DeployEnvironmentCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected override async Task<bool> PerformActionAsync()
183183
}
184184

185185
this.Logger?.WriteLine("Configuring application bundle for a Linux deployment");
186-
EBUtilities.SetupPackageForLinux(this.Logger, this, this.DeployEnvironmentOptions, publishLocation, proxyServer, applicationPort);
186+
EBUtilities.SetupPackageForLinux(this.Logger, this, this.DeployEnvironmentOptions, publishLocation, proxyServer, applicationPort, projectLocation);
187187
}
188188

189189
zipArchivePath = Path.Combine(Directory.GetParent(publishLocation).FullName, new DirectoryInfo(projectLocation).Name + "-" + DateTime.Now.Ticks + ".zip");

src/Amazon.ElasticBeanstalk.Tools/EBUtilities.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Runtime.CompilerServices;
77
using Amazon.Common.DotNetCli.Tools;
8+
using Amazon.Common.DotNetCli.Tools.Options;
89
using Amazon.ElasticBeanstalk.Model;
910
using Amazon.ElasticBeanstalk.Tools.Commands;
1011
using ThirdParty.Json.LitJson;
@@ -109,25 +110,23 @@ public static bool IsLoadBalancedEnvironmentType(string environmentType)
109110
}
110111

111112

112-
public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand command, DeployEnvironmentProperties options, string publishLocation, string reverseProxy, int? applicationPort)
113+
public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand command, DeployEnvironmentProperties options, string publishLocation, string reverseProxy, int? applicationPort, string projectLocation)
113114
{
114115
// Setup Procfile
115116
var procfilePath = Path.Combine(publishLocation, "Procfile");
116117

117-
if(File.Exists(procfilePath))
118+
if (File.Exists(procfilePath))
118119
{
119120
logger?.WriteLine("Found existing Procfile file found and using that for deployment");
120121
return;
121122
}
122123

123124
logger?.WriteLine("Writing Procfile for deployment bundle");
124-
125-
var runtimeConfigFilePath = Directory.GetFiles(publishLocation, "*.runtimeconfig.json").FirstOrDefault();
126-
var runtimeConfigFileName = Path.GetFileName(runtimeConfigFilePath);
127-
var executingAssembly = runtimeConfigFileName.Substring(0, runtimeConfigFileName.Length - "runtimeconfig.json".Length - 1);
125+
var executingAssembly = Utilities.LookupAssemblyNameFromProjectFile(projectLocation, null);
126+
var runtimeConfigFilePath = Directory.GetFiles(publishLocation, $"{executingAssembly}.runtimeconfig.json").FirstOrDefault();
128127

129128
string webCommandLine;
130-
if(IsSelfContainedPublish(runtimeConfigFilePath))
129+
if (IsSelfContainedPublish(runtimeConfigFilePath))
131130
{
132131
webCommandLine = $"./{executingAssembly}";
133132
}
@@ -136,7 +135,7 @@ public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand comman
136135
webCommandLine = $"dotnet exec ./{executingAssembly}.dll";
137136
}
138137

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

0 commit comments

Comments
 (0)