Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspire: Discover exposed port from the result of dotnet publish #3073

Closed
ellismg opened this issue Dec 6, 2023 · 2 comments · Fixed by #3484
Closed

Aspire: Discover exposed port from the result of dotnet publish #3073

ellismg opened this issue Dec 6, 2023 · 2 comments · Fixed by #3484
Assignees
Milestone

Comments

@ellismg
Copy link
Member

ellismg commented Dec 6, 2023

We have the following TODO in the code, which is a corner we cut in our first preview of the aspire work:

// TODO(ellismg): We need to inspect the target container and determine this from the exposed ports (or ask
// MSBuild to tell us this value when it builds the container image). For now we just assume 8080.
//
// We can get this by running `dotnet publish` and using the `--getProperty:GeneratedContainerConfiguration`
// flag to get the generated docker configuration. That's a JSON object, from that we pluck off
// Config.ExposedPorts, which is an object that would look like:
//
// {
// "8080/tcp": {}
// }
//
// Note that the protocol type is apparently optional.
TargetPort: 8080,

This should hopefully be straightforward to fix. We need to adjust the PublishContainer method on the DotnetCli type so that we get this information back and the part the JSON object and return it up stack. We also need to update the code in the Deploy method of dotnetContainerAppTarget to then take that result and overwrite the TargetPort value in the context before we evaluate the template.

We also need to consider what we do in the infra synth case. I suspect we need to publish the container to a local temporary file (which we then delete) so we can get the port that should be exposed from the publish task. Let's chat about what that looks like after we've done the first part. We can always land the first part first and then add the infra synth support later.

@ellismg
Copy link
Member Author

ellismg commented Jan 3, 2024

Here's the output of the run when --getProperty:GeneratedContainerConfiguration:

{
  "config": {
    "ExposedPorts": {
      "8080/tcp": {}
    },
    "Labels": {
      "org.opencontainers.image.created": "2024-01-03T22:08:58.5987590Z",
      "org.opencontainers.artifact.created": "2024-01-03T22:08:58.5987590Z",
      "org.opencontainers.image.authors": "AspireStarter.Web",
      "org.opencontainers.image.version": "1.0.0",
      "org.opencontainers.image.base.name": "mcr.microsoft.com/dotnet/aspnet:8.0"
    },
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
      "APP_UID=1654",
      "ASPNETCORE_HTTP_PORTS=8080",
      "DOTNET_RUNNING_IN_CONTAINER=true",
      "DOTNET_VERSION=8.0.0",
      "ASPNET_VERSION=8.0.0"
    ],
    "WorkingDir": "/app",
    "Entrypoint": [
      "dotnet",
      "AspireStarter.Web.dll"
    ],
    "User": "1654"
  },
  "created": "2024-01-03T22:08:58.9778210Z",
  "rootfs": {
    "type": "layers",
    "diff_ids": [
      "sha256:7292cf786aa89399bca4e3edd105d3b2ee0683a46ef1f5ff436c0f9d1d49e765",
      "sha256:4b703ea23cb9b0cf3b6c8328d8e6afe078e5b058c5e62f45fa1ba93d1a9e0c5b",
      "sha256:93287e66966fa218cfac6e09ba36e3ccdb63336d636eae372c67440ce7a4ed54",
      "sha256:82cc5cf93bd215f3fc1c84d99d37c957eb1c9ec550312c438ad0a1164c6d4f78",
      "sha256:6e906a70a0663d193fd84fbc9ab0b8208e7c8f62545f993f300178f35cf0d162",
      "sha256:828e2dabde3f35d367b68bb50f3a75f5360feb4a972c5870adea8589120f5e4b",
      "sha256:36618edd221deb062bb073a5d8e22e2bd42dfd7500b7c2329569d75a8e7cf1ec"
    ]
  },
  "architecture": "amd64",
  "os": "linux",
  "history": [
    {
      "created": "2023-12-19T01:20:27.6491128Z",
      "created_by": "/bin/sh -c #(nop) ADD file:ac3cd70031d35e46d86b876934946ffc8756de4de065fbc926dce642dac07ff3 in / "
    },
    {
      "created": "2023-12-19T01:20:28.0096269Z",
      "created_by": "/bin/sh -c #(nop)  CMD [\"bash\"]",
      "empty_layer": true
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:09.7653922Z",
      "created_by": "ENV APP_UID=1654 ASPNETCORE_HTTP_PORTS=8080 DOTNET_RUNNING_IN_CONTAINER=true",
      "empty_layer": true
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:09.7653922Z",
      "created_by": "RUN /bin/sh -c apt-get update     && apt-get install -y --no-install-recommends         ca-certificates                 libc6         libgcc-s1         libicu72         libssl3         libstdc++6         tzdata         zlib1g     && rm -rf /var/lib/apt/lists/* # buildkit"
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:10.0824019Z",
      "created_by": "RUN /bin/sh -c groupadd         --gid=$APP_UID         app     && useradd -l         --uid=$APP_UID         --gid=$APP_UID         --create-home         app # buildkit"
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:12.6657510Z",
      "created_by": "ENV DOTNET_VERSION=8.0.0",
      "empty_layer": true
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:12.6657510Z",
      "created_by": "COPY /dotnet /usr/share/dotnet # buildkit"
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:12.8940272Z",
      "created_by": "RUN /bin/sh -c ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet # buildkit"
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:15.0392053Z",
      "created_by": "ENV ASPNET_VERSION=8.0.0",
      "empty_layer": true
    },
    {
      "comment": "buildkit.dockerfile.v0",
      "created": "2023-12-19T08:13:15.0392053Z",
      "created_by": "COPY /shared/Microsoft.AspNetCore.App /usr/share/dotnet/shared/Microsoft.AspNetCore.App # buildkit"
    },
    {
      "author": ".NET SDK",
      "created": "2024-01-03T22:08:58.9778150Z",
      "created_by": ".NET SDK Container Tooling, version 8.0.100-rtm.23551.6+e9d13cbe7e8c1d52ce276a8655f52a87e1017c46"
    }
  ]
}

@rajeshkamal5050
Copy link

rajeshkamal5050 commented Feb 26, 2024

cc @ellismg @hemarina Not a blocker for Aspire Preview 4. Moving it to next milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants