prom3theu5 / aspirational-manifests

Handle deployments of .NET Aspire AppHost Projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DockerBuildArg values are ignored when building docker images

Greven145 opened this issue Β· comments

πŸ”₯ Bug Description

Build arguments for a container resource on a manifest are not passed to the docker build command

πŸ” Steps to Reproduce the Bug

  1. Add an NPM (or similar) app to the Aspire app host
  2. Specify that the NPM app should be published as a dockerfile
  3. Add a build argument for the container
  4. Generate a manifest with Aspirate
  5. Validate that the manifest includes the build arg
  6. 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

Fixed in 0.6.2-preview πŸ˜„

That's amazing, thank you for all your hard work!