DockerBuildArg values are ignored when building docker images
Greven145 opened this issue Β· comments
Greven145 commented
π₯ Bug Description
Build arguments for a container resource on a manifest are not passed to the docker build command
π Steps to Reproduce the Bug
- Add an NPM (or similar) app to the Aspire app host
- Specify that the NPM app should be published as a dockerfile
- Add a build argument for the container
- Generate a manifest with Aspirate
- Validate that the manifest includes the build arg
- Run the aspirate build command specifying the manifest
π§― Possible Solution
It appears that only the environment variables are being passed as build args to the docker builder command, so I suspect that build args from the manifest need to be passed as well
Bug.AppHost\Program.cs
var builder = DistributedApplication.CreateBuilder(args);
var weatherApi = builder.AddProject<Projects.AspireJavaScript_MinimalApi>("weatherapi")
.WithExternalHttpEndpoints();
builder.AddNpmApp("angular", "../AspireJavaScript.Angular")
.WithReference(weatherApi)
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile([new("SOMEARGUMENT","foo")]);
builder.Build().Run();
Bug.AppHost\manifest.json
{
"resources": {
"weatherapi": {
"type": "project.v0",
"path": "../AspireJavaScript.MinimalApi/AspireJavaScript.MinimalApi.csproj",
"env": {
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
"ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true"
},
"bindings": {
"http": {
"scheme": "http",
"protocol": "tcp",
"transport": "http",
"external": true
},
"https": {
"scheme": "https",
"protocol": "tcp",
"transport": "http",
"external": true
}
}
},
"angular": {
"type": "dockerfile.v0",
"path": "../AspireJavaScript.Angular/Dockerfile",
"context": "../AspireJavaScript.Angular",
"buildArgs": {
"SOMEARGUMENT": "foo"
},
"env": {
"NODE_ENV": "development",
"services__weatherapi__http__0": "{weatherapi.bindings.http.url}",
"services__weatherapi__https__0": "{weatherapi.bindings.https.url}",
"PORT": "{angular.bindings.http.targetPort}"
},
"bindings": {
"http": {
"scheme": "http",
"protocol": "tcp",
"transport": "http",
"targetPort": 8000,
"external": true
}
}
}
}
}
Aspirate Output:
> aspirate generate --non-interactive --image-pull-policy Always --skip-build --disable-secrets --include-dashboard
_ _ ___
/ \ ___ _ __ (_) _ __ ( _ )
/ _ \ / __| | '_ \ | | | '__| / _ \
/ ___ \ \__ \ | |_) | | | | | | (_) |
/_/ \_\ |___/ | .__/ |_| |_| \___/
|_|
Handle deployments of a .NET Aspire AppHost
<snip>
π Execution Completed π
> aspirate build -m .\manifest.json
_ _ ___
/ \ ___ _ __ (_) _ __ ( _ )
/ _ \ / __| | '_ \ | | | '__| / _ \
/ ___ \ \__ \ | |_) | | | | | | (_) |
/_/ \_\ |___/ | .__/ |_| |_| \___/
|_|
Handle deployments of a .NET Aspire AppHost
<snip>
ββ Handling Dockerfiles ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Building all dockerfile resources, and pushing containers
(β) Done: Setting container details for Dockerfile angular
Building and push completed for all selected dockerfile components.
Building all dockerfile resources, and pushing containers:
Executing: docker build --tag "angular:latest" --build-arg NODE_ENV="development" --build-arg
services__weatherapi__http__0="{weatherapi.bindings.http.url}" --build-arg
services__weatherapi__https__0="{weatherapi.bindings.https.url}" --build-arg
PORT="{angular.bindings.http.targetPort}" --file "P:\Code\aspirate-bug\AspireJavaScript.Angular\Dockerfile"
../AspireJavaScript.Angular
David Sekula commented
Fixed in 0.6.2-preview π
Greven145 commented
That's amazing, thank you for all your hard work!