dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.93k stars 480 forks source link

localhost mapping #2811

Open biqas opened 8 months ago

biqas commented 8 months ago

Hello,

I have finally tried aspire, was hard to setup in my case because I am developing on an Apple Silicon (M1) and using Parallels Windows ARM for Visual Studio and Linux (Fedora) for Podman.

And The problem I have is I have setup on mac in etc/host the DNS for Fedora Linux so I can access in the Windows VM the Podman containers via DNS. On command line everything is fine, and the environment works fine.

MAC etc/hosts file:
10.211.66.55     fedora.podman

I have not found any possibility to map in Aspire localhost to fedora.podman for resource like Postgres (which is running as a container in fedora Linux as a Podman container) or any other resource.

What i try to do is something like this:

var builder = DistributedApplication.CreateBuilder(args);

// Secrets
var postgresPassword = builder.Configuration["postgres.password"];

// Resources
var postgres = builder.AddPostgres("postgres", password: postgresPassword)
    .WithImageTag("16.2");

var dbA = postgres.AddDatabase("db-a", "db.a");
var dbB = postgres.AddDatabase("Db-b", "db.b");

// Apps
builder.AddProject<Projects.SOME_PROJECT>("some-project")
    .WithReference(dbA)
    .WithReference(dbB);

builder.Build().Run();

this results in that the connection string is like this: Server=localhost;Port=5432;Database=db.a;User ID=XXX;Password='XXX'

I need to override for this resource to not use localhost but instead fedora.podman.

Is this missing or not supported?

davidfowl commented 8 months ago

This isn't possible today. The only feature we have today around localhost mapping is when the containers need to access resources on the host, we have a setting that replaces localhost with host.docker.internal (which is configurable).

This is similar but because your container host is running remotely. We'd need another setting for host -> container host.

davidfowl commented 8 months ago

Tangentially related to https://github.com/dotnet/aspire/issues/2639

biqas commented 8 months ago

Would it make sense then to introduce a broader concept here, which can be also leveraged by other future tools.

The concept would be to put resources into groups or so called "containers" (not docker containers or K8s). and a group or "container" can have associations to localhost, remote machines, Docker, Podman K8s or things like that. In future may be web assembly containers. This could also help to generate out manifests to support multi cloud deployments or not?

In my case i have already a small multi machine setup ;)

davidfowl commented 8 months ago

Sounds great for the future, the only problem is that it would be in the far future 😅 as this is not the 90% case (AFAIK). Having given this more thought, by default when you add endpoints to containers thy go through our proxy. Even if the container is on a remote host the proxy is local.

cc @karolz-ms for ideas on short term and long term solutions

biqas commented 8 months ago

@davidfowl I have already tried those things:

appconfig: "AppHost": { "ContainerHostName": "bits.fedora" }

using this package: <PackageReference Include="Aspire.Hosting" Version="8.0.0-preview.5.24161.15" />

and it does not work the proxy somehow is not routing properly, i guess.

karolz-ms commented 8 months ago

@biqas can you tell me what is shown in the ports section of an inspected container when you run podman container inspect from your Windows VM on some container with mapped ports?

I am thinking this may be as simple as a bug in the Aspire orchestrator in the sense that it assumes containers will always be exposed via one of the loopback interfaces when configuring proxies.