microsoft / azure-container-apps

Roadmap and issues for Azure Container Apps
MIT License
356 stars 27 forks source link

I need to define/know the URL of container app before its created #1063

Open harouny opened 5 months ago

harouny commented 5 months ago
  1. I'm hosting a nextjs app in an Azure Container App.
  2. I have a need to use the default azurecontainerapps.io provided domain name to access the app instead of custom domains.
  3. Azure container app is created via a Bicep module (including environment variables for the container).
  4. I need to define an environment variable NEXTAUTH_URL which should match the host name the app uses. (more info)
  5. I'm using single revision mode and defining a custom revision prefix.

The problem is: Application URL is something like this: https://<defined app name>.jollyriver-592af9d6.<defined region>.azurecontainerapps.io

Where jollyriver-592af9d6 is a generated string not defined by me, so I can't know it beforehand to set the environment variable NEXTAUTH_URL as part of provisioning the whole container app.

Question What is jollyriver-592af9d6 and why it is needed?

Feature request Can we control that string, for example pass it through when the Container App or Container App Environment is created?

anthonychu commented 4 months ago

You can get the default domain in Bicep from properties.defaultDomain in the environment. See this example: https://github.com/Azure/aca-landing-zone-accelerator/blob/f46047fa2e136621f7e8a13fd5e50b05274000ab/scenarios/aca-internal/bicep/modules/06-front-door/deploy.front-door.bicep#L81

You can also use the CONTAINER_APP_HOSTNAME environment variable to get this value for the current app. There's also CONTAINER_APP_ENV_DNS_SUFFIX if you just need the suffix without the app name. However, it doesn't look like NextAuth.js is able to read the value from a variable that's not named NEXTAUTH_URL.

Each Container Apps environment has a unique generated default domain. One reason it's needed is to prevent subdomain takeovers.

justbert commented 3 months ago

I'm in the same boat. Container Apps seems to be built on Kubernetes, does it also allow variable expansion?

This would allow for NEXTAUTH_URL=$(CONTAINER_APP_HOSTNAME).

justbert commented 3 months ago

I'm in the same boat. Container Apps seems to be built on Kubernetes, does it also allow variable expansion?

This would allow for NEXTAUTH_URL=$(CONTAINER_APP_HOSTNAME).

I did a quick test and the above did work.