6
6
using System . Runtime . CompilerServices ;
7
7
using Amazon . Common . DotNetCli . Tools ;
8
8
using Amazon . ElasticBeanstalk . Model ;
9
+ using Amazon . ElasticBeanstalk . Model . Internal . MarshallTransformations ;
9
10
using Amazon . ElasticBeanstalk . Tools . Commands ;
10
11
using ThirdParty . Json . LitJson ;
11
12
@@ -108,26 +109,24 @@ public static bool IsLoadBalancedEnvironmentType(string environmentType)
108
109
return string . Equals ( environmentType , EBConstants . ENVIRONMENT_TYPE_LOADBALANCED , StringComparison . OrdinalIgnoreCase ) ;
109
110
}
110
111
111
-
112
112
public static void SetupPackageForLinux ( IToolLogger logger , EBBaseCommand command , DeployEnvironmentProperties options , string publishLocation , string reverseProxy , int ? applicationPort )
113
113
{
114
114
// Setup Procfile
115
115
var procfilePath = Path . Combine ( publishLocation , "Procfile" ) ;
116
116
117
- if ( File . Exists ( procfilePath ) )
117
+ if ( File . Exists ( procfilePath ) )
118
118
{
119
119
logger ? . WriteLine ( "Found existing Procfile file found and using that for deployment" ) ;
120
120
return ;
121
121
}
122
122
123
123
logger ? . WriteLine ( "Writing Procfile for deployment bundle" ) ;
124
-
125
- var runtimeConfigFilePath = Directory . GetFiles ( publishLocation , "*.runtimeconfig.json" ) . FirstOrDefault ( ) ;
124
+ string runtimeConfigFilePath = GetRuntimeConfigFilePath ( publishLocation ) ;
126
125
var runtimeConfigFileName = Path . GetFileName ( runtimeConfigFilePath ) ;
127
126
var executingAssembly = runtimeConfigFileName . Substring ( 0 , runtimeConfigFileName . Length - "runtimeconfig.json" . Length - 1 ) ;
128
127
129
128
string webCommandLine ;
130
- if ( IsSelfContainedPublish ( runtimeConfigFilePath ) )
129
+ if ( IsSelfContainedPublish ( runtimeConfigFilePath ) )
131
130
{
132
131
webCommandLine = $ "./{ executingAssembly } ";
133
132
}
@@ -136,7 +135,7 @@ public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand comman
136
135
webCommandLine = $ "dotnet exec ./{ executingAssembly } .dll";
137
136
}
138
137
139
- if ( string . Equals ( reverseProxy , EBConstants . PROXY_SERVER_NONE , StringComparison . InvariantCulture ) )
138
+ if ( string . Equals ( reverseProxy , EBConstants . PROXY_SERVER_NONE , StringComparison . InvariantCulture ) )
140
139
{
141
140
logger ? . WriteLine ( "... Proxy server disabled, configuring Kestrel to listen to traffic from all hosts" ) ;
142
141
var port = applicationPort . HasValue ? applicationPort . Value : EBConstants . DEFAULT_APPLICATION_PORT ;
@@ -175,5 +174,65 @@ public static string FindExistingValue(this List<ConfigurationOptionSetting> set
175
174
var setting = settings ? . FirstOrDefault ( x => string . Equals ( x . Namespace , ns , StringComparison . InvariantCulture ) && string . Equals ( x . OptionName , name , StringComparison . InvariantCulture ) ) ;
176
175
return setting ? . Value ;
177
176
}
177
+
178
+ private static string GetRuntimeConfigFilePath ( string publishLocation )
179
+ {
180
+ var runtimeConfigFiles = Directory . GetFiles ( publishLocation , "*.runtimeconfig.json" ) ;
181
+
182
+ // Handle case where application could have multiple runtimeconfig.json files in publish location.
183
+ if ( runtimeConfigFiles . Length > 0 )
184
+ {
185
+ foreach ( var file in runtimeConfigFiles )
186
+ {
187
+ var fileContent = File . ReadAllText ( file ) ;
188
+
189
+ JsonData root = JsonMapper . ToObject ( fileContent ) ;
190
+ JsonData runtimeOptions = root [ "runtimeOptions" ] as JsonData ;
191
+ if ( runtimeOptions == null )
192
+ {
193
+ continue ;
194
+ }
195
+
196
+ // runtimeOptions node can contain framework or frameworks (refer https://github.com/dotnet/sdk/blob/main/documentation/specs/runtime-configuration-file.md#runtimeoptions-section-runtimeconfigjson).
197
+ var frameworkNode = runtimeOptions [ "framework" ] ;
198
+ var frameworksNode = runtimeOptions [ "frameworks" ] ;
199
+
200
+ if ( IsAspNetFramework ( frameworkNode ) )
201
+ {
202
+ return file ;
203
+ }
204
+
205
+ if ( frameworksNode != null && frameworksNode . Count > 0 )
206
+ {
207
+ foreach ( var framework in frameworksNode )
208
+ {
209
+ var tempNode = framework as JsonData ;
210
+ if ( IsAspNetFramework ( tempNode ) )
211
+ {
212
+ return file ;
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }
218
+
219
+ return Directory . GetFiles ( publishLocation , "*.runtimeconfig.json" ) . FirstOrDefault ( ) ;
220
+ }
221
+
222
+ private static bool IsAspNetFramework ( JsonData frameworkNode )
223
+ {
224
+ if ( frameworkNode != null )
225
+ {
226
+ var name = frameworkNode [ "name" ] ;
227
+
228
+ if ( name != null )
229
+ {
230
+ string frameworkName = ( string ) name ;
231
+ return ! string . IsNullOrEmpty ( frameworkName ) && frameworkName . StartsWith ( "Microsoft.AspNetCore" ) ;
232
+ }
233
+ }
234
+
235
+ return false ;
236
+ }
178
237
}
179
238
}
0 commit comments