Dcp doesn't allow me to expose HTTP endpoints on flask applications
I'm trying to integrate a Flask application with the following code:
builder
.AddExecutable(
"flask-service",
".venv/scripts/flask.exe",
"../../apps/flask-service",
args: ["--app","main","run"]
)
.WithHttpEndpoint(targetPort: 5000);
The Dcp component fails to expose the HTTP endpoint because it's missing something, but I can't figure out what exactly. The output of the host application looks like this:
info: Aspire.Hosting.DistributedApplication[0]
Aspire version: 8.0.0-preview.7.24251.11+4952a6e837599afd6bc710bd6c010a2eacd65763
info: Aspire.Hosting.DistributedApplication[0]
Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
Application host directory is: E:\wmeints\aspire-python\sample\host\FizzyLogic.Aspire.Python.AppHost
info: Aspire.Hosting.DistributedApplication[0]
Now listening on: http://localhost:15063
info: Aspire.Hosting.DistributedApplication[0]
Login to the dashboard at http://localhost:15063/login?t=1bb745193cc80ea9a4442946eb2eb283
info: Aspire.Hosting.DistributedApplication[0]
Distributed application started. Press Ctrl+C to shut down.
fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
could not create Endpoint object {"ServiceName": "flask-service", "Workload": "/flask-service", "error": "service-producer annotation is invalid: missing information about the port to expose the service"}
fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
could not create Endpoint object {"Executable": {"name":"flask-service"}, "Reconciliation": 9, "ServiceName": "flask-service", "Workload": "/flask-service", "error": "service-producer annotation is invalid: missing information about the port to expose the service"}
I found this issue https://github.com/dotnet/aspire/issues/3477 but that doesn't fix my problem. The assumption in the code that was changed for that issue is that we're all running ASP.NET Core, but that's not true ;-)
Fun fact: When I add the HTTP port like this:
builder
.AddExecutable(
"flask-service",
".venv/scripts/flask.exe",
"../../apps/flask-service",
args: ["--app","main","run"]
)
.WithHttpEndpoint(targetPort: 5000, env: "HTTP_PORT");
It works flawlessly.
This sounds familiar. @davidfowl didn't we have a bug with endpoints when only specifying a target port?
Yea this is by design but the errors are not great in the current release. They are a little better in the post GA builds. You either need to use env or you need to mark this endpoint as not proxied
I also noticed that in some cases proxying doesn't work. Django for example doesn't respond when I proxy. So I resorted to asking the user to provide the port when adding a Django project.
It should, maybe that's a different issue? Can you show the configuration and a video/gif of what happens?
I can make a repro sample for the behavior and post a new issue for that. I'll link that one here.
Please find the link to the issue with Django here: https://github.com/dotnet/aspire/issues/4158