microsoft / microsoft/aspire

Make `WithBindMount` idempotent

Open
#11,981 0 comments 1 reaction 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

If you try to add an identical bind mount multiple times, aspire gets very unhappy. This can be very easy to do if you try adding bind mounts in `BeforeResoruceStart()` as they'll work fine when you start your app host, but fail if you try to restart the app.

```cs
builder.AddContainer("nginx", "nginx")
.WithBindMount("/", "/mnt/whatever", isReadOnly: true)
.WithBindMount("/", "/mnt/whatever", isReadOnly: true);
```

> Error response from daemon: Duplicate mount point: /mnt/whatever

### Describe the solution you'd like

I'd

1. Aspire should fail fast as soon as the duplicate mount is added
2. If `WithBindMount` tries to add a mount with configuration exactly matchign an existing one, it should no-op
3. DCP should de-duplicate mounts when it tries to start the container.

Note, this assumes the two bind mounts are duplicate. If someone tries to add two conflicting bind mounts, I'm inclined to say you should error immediately, rather than going for last wins.

```cs
builder.AddContainer("nginx", "nginx")
.WithBindMount(".", "/mnt/whatever", isReadOnly: true)
.WithBindMount(./somethingelse/", "/mnt/whatever", isReadOnly: true);
```

### Additional context

Whilst the above example of creating duplicate bind mounts immediately after each other is a bit contrived, you can hit this in the real world if you have layers of extension method, which unintentionally fight with each other.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.