microsoft / microsoft/aspire

SQL Persistent lifetime not respected

Open
#9,377 5 comments 1 reaction 0 assignees View on GitHub
area-integrations
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

### Describe the bug

I am not sure if this is actually by design or not, but in case, it probably just need more clarification.
My goal is to setup a persistent SQL container, using a volume and setting the container lifetime.

Based on the docs, it looks like that all that is needed is something like this:

```csharp
db = builder.AddSqlServer("sql")
.WithDataVolume("my-sql-volume", isReadOnly: false)
.WithLifetime(ContainerLifetime.Persistent)
.AddDatabase("sql-db", databaseName: "my-db");
```

However, if done this way, Aspire will regenerate a random password at each host execution. Given that we're persisting the data volume, a new password will of course cause an auth fail for the `sa` user during sql container bootstrap.

The fix is to add a parameter:

```csharp
var sqlPassword = builder.AddParameter("sql-password", secret: true);
db = builder.AddSqlServer("sql", password: sqlPassword)
.WithDataVolume("my-sql-volume", isReadOnly: false)
.WithLifetime(ContainerLifetime.Persistent)
.AddDatabase("sql-db", databaseName: "my-db");
```

Now, when running locally. user secrets are not automatically added to the builder, which will cause the SQL container to fail.

I had to manually add a call to `builder.Configuration.AddUserSecrets()` to make it work.

Is this expected? If yes, it should probably be added to docs/samples

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

_No response_

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.