microsoft / microsoft/aspire

Docker compose publisher doesn't take into account overridden image name for ProjectResource when generating .env file

Open
#9,711 6 comments 0 reactions 0 assignees View on GitHub
area-deployment docker-compose
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

```
builder.AddDockerComposeEnvironment("app");

builder.AddProject("foo")
.PublishAsDockerFile(c => c
.WithDockerfile(...)
.WithImage("bar"));
```
Then do `aspire publish -o docker-compose-artifacts `

When published, docker image `bar:latests` is built, however `.env` file generated for docker-compose would have `FOO_IMAGE=foo:latest`.

### Expected Behavior

Expected behavior is to have `FOO_IMAGE=bar:latest` in .env file as default value. If `.WithImage()` specifies registry and/or tag, it can be included in .env file too.

The impact is not a big deal, as .env file can be altered later to fill in real image name.
However it would be nice if it was filled in there so no additional step needed.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

Aspire.Hosting.Docker 9.3.0-preview.1.25265.20

Looks like the desired behavior could be achieved by simple change here:
```diff
b/src/Aspire.Hosting.Docker/DockerComposeServiceExtensions.cs
internal static string AsContainerImagePlaceholder(this DockerComposeServiceReso
return dockerComposeService.Parent.AddEnvironmentVariable(
imageEnvName,
description: $"Container image name for {resourceInstance.Name}",
- defaultValue: $"{resourceInstance.Name}:latest",
+ defaultValue: resourceInstance.TryGetContainerImageName(out var imageName) ? imageName : $"{resourceInstance.Name}:latest",
source: new ContainerImageReference(resourceInstance)
);
}
```

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.