ProjectResource.BuildProjectImage does not respect ContainerBuildOptionsCallbackContext.LocalImageName
- 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
If container image to be built has both a `ContainerFilesDestinationAnnotation` and `ContainerBuildOptionsCallbackAnnotation` that overwrites local image name, building container fails because `BuildProjectImage` expects that local image name is the name of the project resource.
### Expected Behavior
`BuildProjectImage` respects the local image name and modifies the image according to its `LocalImageName`.
### Steps To Reproduce
https://github.com/Lexy2/aspire-localimagename-withfiles
Run `aspire do build --pipeline-log-level debug --log-level Debug`
### Exceptions (if any)
17:17:57 (build-app-unique-tag-572752) i [INF] Building image for app-unique-tag-572752 completed
17:17:57 (build-app-unique-tag-572752) i [DBG] Tagging image app-unique-tag-572752 as app-unique-tag-572752:temp-a934e7cdc3b6473c9438cbb937f4a5e8
17:17:57 (build-app-unique-tag-572752) i [DBG] Running Docker with arguments: tag "app-unique-tag-572752" "app-unique-tag-572752:temp-a934e7cdc3b6473c9438cbb937f4a5e8"
17:17:57 (build-app-unique-tag-572752) i [DBG] docker (stderr): Error response from daemon: No such image: app-unique-tag-572752:latest
17:17:57 (build-app-unique-tag-572752) ✗ [ERR] Docker tag for app-unique-tag-572752 -> app-unique-tag-572752:temp-a934e7cdc3b6473c9438cbb937f4a5e8 failed with exit code 1.
17:17:57 (build-app-unique-tag-572752) ✗ [ERR] Step 'build-app-unique-tag-572752' failed.
17:17:57 (build-app-unique-tag-572752) ✗ Docker tag failed with exit code 1.
17:17:57 (build-app-unique-tag-572752) ✗ Error response from daemon: No such image: app-unique-tag-572752:latest
17:17:57 (pipeline-execution) ✗ [ERR] Docker tag failed with exit code 1.
17:17:57 (pipeline-execution) ✗ Error response from daemon: No such image: app-unique-tag-572752:latest
### Aspire doctor output
```
Aspire Environment Check
========================
Aspire
✅ Aspire CLI version 13.5.0-preview.1.26363.3 (channel: daily)
✅ Developer Control Plane (DCP) connection health checks succeeded
AppHost
✅ AppHost version 13.4.6 (aspire-localimagename-withfiles.AppHost\aspire-localimagename-withfiles.AppHost.csproj)
.NET SDK
✅ .NET 10.0.302 installed (x64)
Container Runtime
⚠️ Docker client version 27.4.1 is below minimum required 28.0.0 ← active
Upgrade Docker to version 28.0.0 or later from: https://www.docker.com/products/docker-desktop
See: https://aka.ms/aspire/containers
Environment
✅ Operating system: Windows 10.0.26200.0
✅ HTTPS development certificate is trusted
Development Tools
✅ Aspire extension for VS Code is installed
Summary: 7 passed, 1 warnings, 0 failed
For detailed prerequisites: https://aka.ms/aspire-prerequisites
Aspire CLI Installations
========================
╭───────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────────────┬─────────┬───────────┬─────────────╮
│ Path │ Version │ Channel │ Route │ PATH status │
├───────────────────────────────────────────────────────────┼───────────────────────────────────────────────────────────────────┼─────────┼───────────┼─────────────┤
│ C:\Users\lexy.zhitenev\.dotnet\tools\aspire.exe (current) │ 13.5.0-preview.1.26363.3+faa8a7a5e9f87fa149fb5ea57372dfe9dd848c5a │ daily │ (unknown) │ active │
╰───────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────┴─────────┴───────────┴─────────────╯
```
### Anything else?
If I don't override local image name the build fails with a different error:
```
17:08:55 (build-webfrontend) i [INF] Building image for webfrontend completed
17:08:55 (build-webfrontend) i [DBG] Tagging image webfrontend as webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:55 (build-webfrontend) i [DBG] Running Docker with arguments: tag "webfrontend" "webfrontend:temp-aef3acda207f4d21a6005511ea5029c3"
17:08:55 (build-webfrontend) i [INF] Docker tag for webfrontend -> webfrontend:temp-aef3acda207f4d21a6005511ea5029c3 succeeded.
17:08:55 (build-webfrontend) i [DBG] Getting ContainerWorkingDirectory for project D:\src\repos\aspire-localimagename-withfiles\aspire-localimagename-withfiles.Web\aspire-localimagename-withfiles.Web.csproj
17:08:55 (build-webfrontend) i [DBG] dotnet msbuild returned empty ContainerWorkingDirectory for project D:\src\repos\aspire-localimagename-withfiles\aspire-localimagename-withfiles.Web\aspire-localimagename-withfiles.Web.csproj.
Using default /app
17:08:55 (build-webfrontend) i [DBG] Adding COPY --from=frontend_stage /app/dist /app/wwwroot
17:08:55 (build-webfrontend) i [DBG] Allocated temporary file: C:\Users\lexy.zhitenev\AppData\Local\Temp\aspirecslw544l.yer\Dockerfile
17:08:56 (build-webfrontend) i [DBG] Generated temporary Dockerfile at C:\Users\lexy.zhitenev\AppData\Local\Temp\aspirecslw544l.yer\Dockerfile
17:08:56 (build-webfrontend) i [DBG] Running Docker with arguments: buildx version
17:08:56 (build-webfrontend) i [DBG] docker (stdout): github.com/docker/buildx v0.25.0 faaea65da4ba0e58a13cd9cadcb950c51cf3b3c9
17:08:56 (build-webfrontend) i [DBG] Docker buildx is available.
17:08:56 (build-webfrontend) i [DBG] Running Docker with arguments: buildx build --file "C:\Users\lexy.zhitenev\AppData\Local\Temp\aspirecslw544l.yer\Dockerfile" --tag "webfrontend" --platform "linux/amd64"
"D:\src\repos\aspire-localimagename-withfiles\aspire-localimagename-withfiles.Web"
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #0 building with "default" instance using docker driver
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #1 [internal] load build definition from Dockerfile
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #1 transferring dockerfile: 272B done
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #1 DONE 0.0s
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #2 [internal] load metadata for docker.io/library/webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #2 DONE 0.0s
17:08:56 (build-webfrontend) i [DBG] docker (stderr): #3 [internal] load metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581
17:08:57 (build-webfrontend) i [DBG] docker (stderr): #3 ...
17:08:57 (build-webfrontend) i [DBG] docker (stderr): #4 [auth] library/frontend:pull token for registry-1.docker.io
17:08:57 (build-webfrontend) i [DBG] docker (stderr): #4 DONE 0.0s
17:08:57 (build-webfrontend) i [DBG] docker (stderr): #3 [internal] load metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581
17:08:57 (build-webfrontend) i [DBG] docker (stderr): #3 ERROR: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
17:08:58 (build-webfrontend) i [DBG] docker (stderr): ------
17:08:58 (build-webfrontend) i [DBG] docker (stderr): > [internal] load metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581:
17:08:58 (build-webfrontend) i [DBG] docker (stderr): ------
17:08:58 (build-webfrontend) i [DBG] docker (stderr): Dockerfile:3
17:08:58 (build-webfrontend) i [DBG] docker (stderr): --------------------
17:08:58 (build-webfrontend) i [DBG] docker (stderr): 1 | ARG FRONTEND_IMAGENAME=frontend:6a7360b3669d7d001d094f9b040b48344edfe581
17:08:58 (build-webfrontend) i [DBG] docker (stderr): 2 |
17:08:58 (build-webfrontend) i [DBG] docker (stderr): 3 | >>> FROM ${FRONTEND_IMAGENAME} AS frontend_stage
17:08:58 (build-webfrontend) i [DBG] docker (stderr): 4 |
17:08:58 (build-webfrontend) i [DBG] docker (stderr): 5 | FROM webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:58 (build-webfrontend) i [DBG] docker (stderr): --------------------
17:08:58 (build-webfrontend) i [DBG] docker (stderr): ERROR: failed to build: failed to solve: frontend:6a7360b3669d7d001d094f9b040b48344edfe581: failed to resolve source metadata for
docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
17:08:58 (build-webfrontend) ✗ [ERR] Docker build for webfrontend failed with exit code 1.
17:08:58 (build-webfrontend) i [DBG] Failed build - temporary Dockerfile left at C:\Users\lexy.zhitenev\AppData\Local\Temp\aspirecslw544l.yer\Dockerfile for debugging
17:08:58 (build-webfrontend) i [DBG] Removing temporary image webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:58 (build-webfrontend) i [DBG] Running Docker with arguments: rmi "webfrontend:temp-aef3acda207f4d21a6005511ea5029c3"
17:08:58 (build-webfrontend) i [DBG] docker (stdout): Untagged: webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:58 (build-webfrontend) i [INF] Docker rmi for webfrontend:temp-aef3acda207f4d21a6005511ea5029c3 succeeded.
17:08:58 (build-webfrontend) ✗ [ERR] Step 'build-webfrontend' failed.
17:08:58 (build-webfrontend) ✗ Docker build failed with exit code 1.
17:08:58 (build-webfrontend) ✗ #0 building with "default" instance using docker driver
17:08:58 (build-webfrontend) ✗ #1 [internal] load build definition from Dockerfile
17:08:58 (build-webfrontend) ✗ #1 transferring dockerfile: 272B done
17:08:58 (build-webfrontend) ✗ #1 DONE 0.0s
17:08:58 (build-webfrontend) ✗ #2 [internal] load metadata for docker.io/library/webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:58 (build-webfrontend) ✗ #2 DONE 0.0s
17:08:58 (build-webfrontend) ✗ #3 [internal] load metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581
17:08:58 (build-webfrontend) ✗ #3 ...
17:08:58 (build-webfrontend) ✗ #4 [auth] library/frontend:pull token for registry-1.docker.io
17:08:58 (build-webfrontend) ✗ #4 DONE 0.0s
17:08:58 (build-webfrontend) ✗ #3 [internal] load metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581
17:08:58 (build-webfrontend) ✗ #3 ERROR: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
17:08:58 (build-webfrontend) ✗ ------
17:08:58 (build-webfrontend) ✗ > [internal] load metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581:
17:08:58 (build-webfrontend) ✗ ------
17:08:58 (build-webfrontend) ✗ Dockerfile:3
17:08:58 (build-webfrontend) ✗ --------------------
17:08:58 (build-webfrontend) ✗ 1 | ARG FRONTEND_IMAGENAME=frontend:6a7360b3669d7d001d094f9b040b48344edfe581
17:08:58 (build-webfrontend) ✗ 2 |
17:08:58 (build-webfrontend) ✗ 3 | >>> FROM ${FRONTEND_IMAGENAME} AS frontend_stage
17:08:58 (build-webfrontend) ✗ 4 |
17:08:58 (build-webfrontend) ✗ 5 | FROM webfrontend:temp-aef3acda207f4d21a6005511ea5029c3
17:08:58 (build-webfrontend) ✗ --------------------
17:08:58 (build-webfrontend) ✗ ERROR: failed to build: failed to solve: frontend:6a7360b3669d7d001d094f9b040b48344edfe581: failed to resolve source metadata for docker.io/library/frontend:6a7360b3669d7d001d094f9b040b48344edfe581:
pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
```
Contributor guide
Research direction
Start at the BuildProjectImage entry point and trace how ContainerFilesDestinationAnnotation and ContainerBuildOptionsCallbackAnnotation provide the LocalImageName. Reproduce the failure with the linked sample using `aspire do build --pipeline-log-level debug --log-level Debug`; done means the generated Docker operations use the overridden local image name and the build completes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, docker
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100