Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithBindMount methods failing when running in integration tests because paths aren't resolved relative to AppHost project #3323

Closed
DamianEdwards opened this issue Apr 1, 2024 · 0 comments · Fixed by #3467
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@DamianEdwards
Copy link
Member

AppHost projects using the WithBindMount method to mount a host directory in a container can fail when running in the context of an integration test because the source path passed to WithBindMount isn't being resolved relative to the AppHost project.

Workaround is to explicitly resolve bind mount paths to full paths in the AppHost, e.g.:

var builder = DistributedApplication.CreateBuilder(args);

var grafana = builder.AddContainer("grafana", "grafana/grafana")
                     .WithBindMount(GetFullPath("../grafana/config"), "/etc/grafana", isReadOnly: true)
                     .WithBindMount(GetFullPath("../grafana/dashboards"), "/var/lib/grafana/dashboards", isReadOnly: true)
                     .WithEndpoint(targetPort: 3000, name: "grafana-http", scheme: "http");

builder.AddProject<Projects.MetricsApp>("app")
       .WithEnvironment("GRAFANA_URL", grafana.GetEndpoint("grafana-http"));

builder.AddContainer("prometheus", "prom/prometheus")
       .WithBindMount(GetFullPath("../prometheus"), "/etc/prometheus", isReadOnly: true)
       .WithEndpoint(/* This port is fixed as it's referenced from the Grafana config */ port: 9090, targetPort: 9090);

using var app = builder.Build();

await app.RunAsync();

static string GetFullPath(string relativePath) =>
    Path.GetFullPath(Path.Combine(Projects.MetricsApp_AppHost.ProjectPath, relativePath));

@davidfowl mentioned he had a fix for this at one point but that it didn't quite get in. We should fix this for preview.6

@DamianEdwards DamianEdwards added bug area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication labels Apr 1, 2024
@DamianEdwards DamianEdwards added this to the preview 6 (Apr) milestone Apr 1, 2024
@davidfowl davidfowl self-assigned this Apr 6, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants