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

[Issue] Azure Container Apps for .NET apps should have the default targetPort of 8080, instead of 80 #4583

Closed
1 task done
justinyoo opened this issue Nov 22, 2024 · 2 comments

Comments

@justinyoo
Copy link

justinyoo commented Nov 22, 2024

Output from azd version
Run azd version and copy and paste the output here:

azd version 1.11.0 (commit 5b92e0687e1fa96dfc8292f4b900c0c58610b6a5)

Describe the bug
Description of issue you're seeing...

  • When I run azd init for a .NET app, it automatically generates Bicep files.

  • The auto-generated bicep file, resources.bicep has invalid target port number of 80.
    👉 .NET apps should have the target port of 8080. (Reference)

    module eshopliteStore 'br/public:avm/res/app/container-app:0.8.0' = {
      name: 'xxxxx'
      params: {
        name: 'xxxxx'
        ingressTargetPort: 80
        ...
        containers: [
          {
            ...
            env: union([
              ...
              {
                name: 'PORT'
                value: '80'
              }
            ],
    ...
  • It's because the following code sets the default port number to 80 except for Java apps.

    if _, err := os.Stat(filepath.Join(svc.RelativePath, "Dockerfile")); errors.Is(err, os.ErrNotExist) {
    // default builder always specifies port 80
    props.Port = 80
    if svc.Language == project.ServiceLanguageJava {
    props.Port = 8080
    }
    }

    It should also be applied to .NET apps like:

    if ( svc.Language == project.ServiceLanguageJava || svc.Language == project.ServiceLanguageDotNet ) {
        props.Port = 8080 
    } 

To Reproduce
Steps to reproduce the behavior...

  1. Create an ASP.NET app or Blazor app
  2. Run azd init
  3. Check the auto-generated bicep file, resources.bicep whether the ingressTargetPort value is 80 or not
  4. Check the auto-generated bicep file, resources.bicep whether the env.PORT value is 80 or not

Expected behavior
A clear and concise description of what you expected to happen.

Both ingressTargetPort and env.PORT values should be 8080.

Environment
Information on your environment:
* Language name and version: .NET 9
* IDE and version : VS Code (Dev Container)

@weikanglim
Copy link
Contributor

@justinyoo Just wondering... did the container app fail to run?

The default port of 80 is coming from the azd builder for Dockerless build -- feel free to modify it to suit your needs.

		// Always default to port 80 for consistency across languages
		environ = append(environ, "ORYX_RUNTIME_PORT=80")

That being said, we have #4573 to switch over to native dotnet builds, which this feedback is very much applicable -- we'll make the change as part of this.

ellismg added a commit to ellismg/azure-dev that referenced this issue Nov 22, 2024
The `dotnet` tool has native support for producing (and pushing) a
container image. This does not require a local docker daemon and in
general "does the right thing" and is the prefered way for .NET
customers to produce container
images. https://learn.microsoft.com/dotnet/core/docker/publish-as-container
gives a good overview of how this support works and we've been using
it to build and push container images for Aspire apps.

This change updates things such that we can use this support when
building a non Aspire based .NET app. If a `Dockerfile` exists, we
respect it, but otherwise instead of trying to use Oryx to produce a
container image, we will use `dotnet publish`.

In addition, we now use 8080 as the default port of a `dotnet` based
application (with no Dockerfile) as that's the default port used by
the standard ASP.NET base image.

A new recorded test was added - it builds on top of the existing
`containerapp` sample, and the test aranges to remove the `Dockerfile`
file from the template before running `up`.

Fixes Azure#2632
Fixes Azure#4583
@justinyoo
Copy link
Author

@ellismg That's good to know. Thanks!

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

No branches or pull requests

2 participants