Hello everyone,
I've been looking for few days many tutorials to try to find my solution but i just can't get it.
Overview :
Im building an Asp.net Core (3.1) app which i've set up for running on docker. My goal is to deploy it to heroku.
Problem :
I can make it work on local to try with a docker container run but when i deploy it to heroku (the image was created without troubles) i get the error screen message:
"Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command"
Setup
Heroku :
- dyno in use : **api** /bin/sh -c ASPNETCORE_URLS\=http://\*:\$PORT\ dotnet\
- build pack : https://github.com/jincod/dotnetcore-buildpack
Code
Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.100 AS build
WORKDIR /src
COPY *.sln .
COPY Ecomm.UnitTests/*.csproj Ecomm.UnitTests/
COPY Ecomm.Api/*.csproj Ecomm.Api/
RUN dotnet restore
COPY . .
# testing
FROM build AS testing
WORKDIR /src/Ecomm.Api
RUN dotnet build
WORKDIR /src/Ecomm.UnitTests
RUN dotnet test
# publish
FROM build AS publish
WORKDIR /src/Ecomm.Api
RUN dotnet publish -c Release -o /src/publish
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /src
COPY --from=publish /src/publish .
# heroku uses the following
CMD ASPNETCORE_URLS=http://*:$PORT dotnet Ecomm.Api.dll
Program.cs (default script)
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
Startup.cs (default script)
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Launchsettings.json
"Ecomm.Api": {"commandName": "Project","launchBrowser": true,"launchUrl": "/weatherforecast","applicationUrl": "https://localhost:5001;http://localhost:5000","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Production"
}
}
Comparaison between running a container locally and deploy to heroku
Local interface
Heroku interface :
methods used to push on Heroku container register:
docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
heroku container:push api -a $HEROKU_APP_NAME --recursive
heroku container:release api -a $HEROKU_APP_NAME
Errors logs in heroku :
2020-01-18T14:53:32.255720+00:00 heroku[api.1]: State changed from crashed to starting
2020-01-18T14:53:35.853732+00:00 heroku[api.1]: Starting process with command `/bin/sh -c ASPNETCORE_URLS\=http://\*:\59573\ dotnet\ Ecomm.Api.dll`
2020-01-18T14:53:36.494742+00:00 heroku[api.1]: State changed from starting to up
2020-01-18T14:53:37.754733+00:00 app[api.1]: Hosting environment: Production
2020-01-18T14:53:37.754802+00:00 app[api.1]: Content root path: /src
2020-01-18T14:53:37.754925+00:00 app[api.1]: Now listening on: http://[::]:59573
2020-01-18T14:53:37.754946+00:00 app[api.1]: Application started. Press Ctrl+C to shut down.
2020-01-18T14:53:39.762409+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=dariorega-ecomm-api.herokuapp.com request_id=7538ce41-5d5e-4081-b214-eb1e50fdcc6c fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
2020-01-18T14:53:40.075446+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=dariorega-ecomm-api.herokuapp.com request_id=4f1ff94a-eb45-4301-9c3a-74ece82abe84 fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
2020-01-18T14:53:51.155230+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/api" host=dariorega-ecomm-api.herokuapp.com request_id=1cc3eeac-1ce5-4a67-82e0-ee680beecc90 fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
2020-01-18T14:53:51.440188+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=dariorega-ecomm-api.herokuapp.com request_id=caa51bcd-a153-444b-88b5-c024d1b2ae84 fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
2020-01-18T14:53:56.045125+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/weatherforecast" host=dariorega-ecomm-api.herokuapp.com request_id=bcdc8195-9da6-4258-a48b-4614d885302a fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
2020-01-18T14:53:56.292724+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=dariorega-ecomm-api.herokuapp.com request_id=2329aa44-bdb0-43e3-bbbf-58bd87a09f8c fwd="188.155.40.41" dyno= connect= service= status=503 bytes= protocol=https
Logs i get in local container :
after running a docker container run with that same dockerfile :
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /src
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect
Conclusion
I've tried many things in the docker file or to edit the program.cs defining useUrl methods but i still can't make it work. I don't know if somethings is related beceause of the http /https process since the https: isnt setup/working and heroku use https.
Or i should define an url somehwere, well, any help welcome !
Thanks in advance for your time taken reading this