I have an existing ASP.NET Core Web App running as a docker container and would like to provide it as a Edge Module running on Azure IoT Edge. From the docs i know i can run Azure Functions, Stream Analytics and Custom modules (which from my understanding are just console applications integrating with the Azure IoT Edge Runtime).
What is the best way to turn my ASP.NET Core Web App into an Edge Module and interact with Edge Hub?
Would the best approach be to use a custom module as a template, move my ASP.NET Core project over to fit the file structure and edit the dockerfiles to run my main ASP.NET Core Assembly?
Thank you for any advise!
Update: I was following the approach stated above. I created a custom edge module and tried to convert it to the simplest possible ASP.NET Core Web App using the following steps:
- Add package reference
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
Add Startup class
public class Startup {
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.Run(async r => await r.Response.Body.WriteAsync(Encoding.UTF8.GetBytes("seas"))); loggerFactory.AddConsole(); } }
Add this method to Program.cs:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup();
Replace content of Main with
CreateWebHostBuilder(args).Build().Run();
I can start the container as part of Azure IoT Edge but the container constantly keeps restarting, so i assume, my approach was not really right. Unfortunately i also can't get access to the console of the container because it's restarting every few seconds...
output of sudo docker ps ...
4b23cdad5bc5 localhost:5000/simpleweb:0.0.1-amd64
"dotnet SimpleWeb.dll" 5 minutes ago Restarting (150) 58 seconds ago
...
PS: I am using iot edge dev container for testing following this quickstart: https://github.com/Azure/iotedgedev/wiki/quickstart-with-iot-edge-dev-container