appsettings.json copied, passed or published to Azure App Service configuration? - asp.net-core-3.1

I have been trying to understand the appsettings.json method of use for some time now as I am building an ASP.NET Core 3.1 API that is to be published to Azure.
When I'm publishing the project to my web app my settings don't seem to get copied to the App Service configurations list in the Azure App Service resource.
Is this how it is supposed to work or am I missing something here?
I've read about appconfigurationbuilder and such, but as I understand it it's for telling the application which appsettings.json file to use depending on what environment is defined in the environment variable (ASPNETCORE_ENVIRONMENT) for example.
Though having a bunch of Key Vault references in my config, this doesn't work as my references of type:
#Microsoft.Keyvault(SecretUri=[KEY VAULT SECRET URL])
Can't fetch the secret from keyvault by only being the the appsettings.env.json file and not being copied to the app service configurations where they connect to keyvault through identity principal.
What am I missing or have I misunderstood the whole thing with appsettings.json?
So short recap: what I'm trying to do is understand if app settings can work like this:
appSettings.Env.json --> publish project to Azure app service --> settings are set automatically in app service configuration.

As mentioned in the comment, the app settings will not be copied to the azure app service when published, you need to specify the values in it manually.
Follow this doc - https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0#azure-app-service

Related

Service Fabric .NET Framework services and ApplicationInsights.config endpoints for Azure gov

I have a service fabric application that hosts api’s with app insights enabled. The api services are .Net framework 4.8 webapi projects and they are native fabric stateless and stateful services. I don’t use the app insights service fabric specific packages, but do have the standard app insights for webapi packages. I have always been in Azure commercial and logs have worked just fine there.
Now that we are in azure gov, the only way to point a .Net Framework app to the gov app insights endpoints is by modifying the ApplicationInsights.config file.
So I’ve modified the file as per msdn, verified it is deployed with the fabric deploy package and its there next to the rest of the dlls on the vms. Yet my services still won’t log to azure gov app insight instances. Nothing is coming through. We set the instrumentation key programmatically, not in applicationinsights.config, could that be an issue? I noticed some of the msdn examples showed instrumentationkey being included in the config file, but would think that is optional.
Had anyone had experience pointing .net 4.8 fabric services to gov app insights?
When using a government cloud, you need to use a connection string instead of an instrumentation key.
Important
Sovereign clouds, such as Azure Government, require the use of the
Application Insights connection string
(APPLICATIONINSIGHTS_CONNECTION_STRING) instead of the instrumentation
key. To learn more, see the APPLICATIONINSIGHTS_CONNECTION_STRING
reference.
More info here and here.
This ended up being an issue with my gov configuration file. The MSDN document wasn't very clear on where the new config sections go. It made it look like they are all nested under the top level node of the config file. Turns out the TelementyChannel override has to go inside the default TelemenySinks node. I contacted microsoft on github about clarifying this in their docs.
Link to the unclear documentation
https://learn.microsoft.com/en-us/azure/azure-monitor/app/custom-endpoints?tabs=net
Link to github issue to get it fixed
https://github.com/MicrosoftDocs/azure-docs/issues/80066

How do I verify my cf app configuration items

I'm just starting to play with the IBM cloud offering. I've built a simple flask app and am trying to deployt it via a toolchain. When I run my toolchain the app deploys successfully, however I can't access the url.
I am looking at the deployment logs and have a couple of questions.
First, I see this:
2020-12-24T15:00:39.66+0000 [APP/PROC/WEB/0] OUT * Environment: production
But the environment I thought I was deploying to was dev. How do I change the environment I expect the toolchain to deploy to?
I'm assuming that the url that shows up in the log output should be accessible, but it isn't.
My manifest has random-route: true defined. How do I check that the url in the logs is available and pointing to my deployed cf app??
Thanks for any help and Happy Holidays!
Have you checked the app using the cloud console ui at https://cloud.ibm.com There should be a link to the app url.
It is possible to differentiate between def and prod via environment variables. I believe you can pass environment variables via the manifest file. You can sent via ibmcloud cf set-env and then ibmcloud cf restage.
So the reason my app was failing was I was missing a couple of items/components
First, from the code I needed these lines in my python.
port = int(os.getenv('PORT', 5000))
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=port)
The cloud foundry deployment maps the external facing url to your app.
In order to do that it needs to know what port to use and that first snippet sets it to the port defined as an environment variable (IBM Cloud defines this) or port 5000 if the variable is not set.
The second snippet is the standard script special variable evaluation and execution control mechanism.
I didn't have this or the app.run call.
adding these allowed me to get the app running by pushing it from my machine locally. Now that i have it deploying successfully, I'll start working on getting it to deploy via a toolchain.
I figured all of this out by reviewing this tutorial I found on github and comparing what they were doing and what I was doing.
https://github.com/IBM-Cloud/get-started-python
Lastly, to see how the app has been mapped go the cloud foundry section of the ui and select the app. From there you can look at the logs and they show how the app maps in the url resource access history. That being said, fundamentally this wasn't going to help me solve my problem as it was related to my source code, not the actual route mapping.
Seems your toolchain has environment variable set which you can change by setting the following:
ibmcloud cf env-set flask_app Environment development
It can also be set via mainfest.yml file as shown below:
env:
env_name: development
URL is given on the UI that you may refer. Other way to check the URL is to look for the route so you may use
ibmcloud cf app flask_app
If you see any issues in accessing the app using route so it means there is some problem with the app causing this to happen.

Appservice deployment issue

Hi iam deploying my war file using azure appservice from azuredevops. deployment is getting completed successfully but when i hit the url Microsoft azure welcome page is displayed instead of application. can you please suggest a work around
In Azure Web Apps, the default document is the web page that is displayed at the root URL for a website. The first matching file in the list is used. Refer File structure on azure to know more about the files and directories on Azure Web App.
You may check whether the deployed files are available or not using Kudu Console.
Also, make sure that your startup file (For ex: index.htm) is added to the default documents section as mentioned above. You can delete the remaining files if not required and see if that works.
For details , you can refer to this case.

Azure Arm template - app setting missing after appservice resource successfully provisioned

I am currently provisioning a new resource group using Azure Arm template and Powershell
New-AzureRmResourceGroupDeployment
The resource group template defines all the resources.
A couple of different app service resources are provisioned as part of this resource group. Each app service resource has app settings.
The resource group gets provisioned sucessfully including its app service but from time to time, the app settings are missing on the newly provisioned app service. I am required to teardown and re-create the resource group and it works fine.
When the custom app settings are missing then, in the portal, there is only one app setting visible: WEBSITE_NODE_DEFAULT_VERSION
Any pointers for how I can troubleshoot this so the environment provisioning process is consistent?
Are you using the -DeploymentDebugLogLevel parameter in the PowerShell command you are using for the deployment? There are different values for that parameter that control how much debugging information you get. I have used it in the past to help troubleshoot IaaS deployments using ARM templates. More information is here: https://azure.microsoft.com/en-us/blog/debugging-arm-template-deployments/
Does the app have slots? If yes, are the appsettings tied to specific slots? When we perform a swap slot, then the appsettings can disappear, if the settings are slot specific. Also, are you performing an Incremental upgrade or Complete? As Tom commented, sharing the template will help in understanding whats going on.

What happens to a CF manifest after a successful deployment?

I am currently tinkering with Cloud Foundry. I understand the basic principles of the tool but can't find what cf push actually does to a manifest file.
Does it read the file just once or is it stored as a static file with the application?
Also, is it possible to retrieve a manifest from a deployed app?
The cf push command reads the manifest file and uses the attribute values (instances, memory, disk etc) for the current deployment. The manifest helps to automate the app deployment. It can also be used for deploying multiple applications at once. As stated here: https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html, when you deploy an application for the first time, Cloud Foundry reads the variables described in the environment block of the manifest, and adds them to the environment of the container where the application is deployed. When your app is running, your environment variables can change depending on your setting. For example, if you have an auto-scaler, it could have increased/decreased your no. of instances/memory/disk (environment variables). If that is the case, when you stop and then restart an application, its environment variables persist.
The manifest file is read only when the "cf push" command is executed. As stated in the Cloud Foundry Documentation (https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#exclude), the manifest file is just read and not actually stored as a file, hence it could not be accessed for a deployed app. However, if the purpose for accessing your manifest is to read your current environment setting, it can be accessed through the Cloud Foundry API's Get App Summary (or) Get detailed stats for a STARTED App: https://apidocs.cloudfoundry.org/234/