Add Support for Postgres v18 and DataVolume
- 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.
Last week, version 18 of Postgres was released, and with it, exciting new features.
When trying to integrate the specific new version with Aspire (e.g. via `.WithImageTag("18.0-alpine")`)
Issues occur when trying to persist the database via `WithDataVolume`.
The specific error is the following:
> Failed to start Container {"Container": "/app-db-a5f7ed39", "Reconciliation": 9, "ContainerID": "6abfc32df9b3", "ContainerName": "app-db-a5f7ed39", "error": "status of container 'app-db-a5f7ed39' is 'created' (was expecting 'running'), error: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting \"/var/lib/docker/volumes/apphost-a5f7ed3973-app-db-data/_data\" to rootfs at \"/var/lib/postgresql/data\": change mount propagation through procfd: open o_path procfd: open /var/lib/docker/overlay2/565bae96a29896f38a93152422eb700cb397ae3e46172720b7ed0b37fc8e3ea7/merged/var/lib/postgresql/data: no such file or directory: unknown\ndocker command 'StartContainers' returned with non-zero exit code 1\nnot all requested objects were returned\nonly 0 out of 1 containers were successfully started"}
AFAIK this happens because the new Postgres folder structure and storing database data under a version specific `/var/lib/postgresql/18/docker` (notice the new */18/docker* part of the path). (See https://github.com/docker-library/postgres/pull/1259, https://hub.docker.com/_/postgres/#pgdata)
A current workaround for now is simply extending the resource builder with a version-specific volume mapping:
```
public static class Postgres18BuilderExtensions
{
public static IResourceBuilder WithDataVolumeForV18(
this IResourceBuilder builder, string? name = null, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
return builder.WithVolume(name ?? VolumeNameGenerator.Generate(builder, "data"),
"/var/lib/postgresql/18/docker", isReadOnly);
}
}
```
Moving on, it will be required to either override the default `WithDataVolume` with a specific version or let Aspire infer the version from the image tag used.
### Describe the solution you'd like
Postgres 18+ should support `.WithDataVolume()` as previous versions did.
The correct data volume shall be used with Postgres versions 18+.
With the new version, the path should be "/var/lib/postgresql/18/docker".
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.