Deploying .NET Apps to Azure Container Apps with One Command, azd up by info.odysseyx@gmail.com September 6, 2024 written by info.odysseyx@gmail.com September 6, 2024 0 comment 7 views 7 In my previous blog post Containerizing .NET Apps and Feature AppWe covered how to containerize .NET apps and Azure Functions apps. Dockerfile. However, deploying these containerized apps is Azure Container App (ACA) That’s another story. After launch in May 2023, Azure Developer CLI(azd) It’s come a long way. azd Nowadays, it is also automatically generated. biceps Provides files to instantly provision and deploy applications to Azure. With this feature, all you need is: azd up Commands for provisioning and deployment. Throughout this post, we will explain how to provision and deploy a .NET app, including Azure Functions, to ACA with just one command. azd up. You can find sample code here. GitHub Repository. Prerequisites There are several prerequisites to effectively containerizing .NET apps. Running the app locally that Sample App Repository The following apps are already included: Let’s check if the app runs properly on your local machine. To run the app locally, open three terminal windows and run the following command in each terminal. # Terminal 1 - ASP.NET Core Web API dotnet run --project ./ApiApp # Terminal 2 - Azure Functions cd ./FuncApp dotnet clean && func start # Terminal 3 - Blazor app dotnet run --project ./WebApp Open your web browser and go to: https://localhost:5001 To see your Blazor app running, go to: https://localhost:5001/weather To view the imported weather data ApiApp And the greeting is as follows: FuncApp. Now let’s start using it. azd To provision and deploy these apps to ACA, do the following: Make sure you are already signed in to Azure. azd auth login command. azd init – reset To provision and deploy an app to ACA, you must initialize: azd Configure. Run the following command. azd init You will be prompted to reset the app. Use code in the current directory Options. azd It automatically detects three apps as shown below. In addition, it says that it uses Azure Container Apps. Confirm and continue initializing my app Options. The function app asks for the target port number. Enter 80. Finally, it asks you for the environment name. Enter whatever name you want. I just entered it. aca0906 now. Now we have created two directories and two files. .azure directory infra directory next-steps.md file azure.yaml file Below infra A Bicep file is automatically created in the directory. azd init. As a result of executing the command, azd initYou don’t have to create all the necessary Bicep files. Instead, the Bicep files are generated for you, which significantly reduces the infrastructure provisioning time. Now you’re ready to provision and deploy your app to ACA. Let’s get started. azd up – Provision and distribution Here’s what you need to do at this stage: azd up You will then be prompted to confirm where you want to provision your subscriptions and resources. Select the appropriate option and continue. All apps are containerized and deployed to ACA. Once the deployment is complete, you can see the output as below. Click on the web app URL and navigate to it. /weather page. But it shows error as below. This is because the apps don’t know where each other is, so you need to update the Bicep file so that the web app knows where the other app is. Biceps File Update – Service Search opening infra/main.bicep Update the file webApp will: module webApp './app/WebApp.bicep' = { name: 'WebApp' params: { ... // Add these two lines apiAppEndpoint: apiApp.outputs.uri funcAppEndpoint: funcApp.outputs.uri } scope: rg } Then, infra/app/WebApp.bicep Add the file and add both apiAppEndpoint and funcAppEndpoint Parameters: ... @secure() param appDefinition object // Add these two lines param apiAppEndpoint string param funcAppEndpoint string ... In the same file, change: env variable: // Before var env = map(filter(appSettingsArray, i => i.?secret == null), i => { name: i.name value: i.value }) // After var env = union(map(filter(appSettingsArray, i => i.?secret == null), i => { name: i.name value: i.value }), [ { name: 'API_ENDPOINT_URL' value: apiAppEndpoint } { name: 'FUNC_ENDPOINT_URL' value: funcAppEndpoint } ]) This change passes API and function app endpoints to the web app as environment variables, so the web app knows where the other app is located. After applying the changes, run: azd up Run the command again. This will update the ACA’s resources. Then go to the web app URL and /weather Page. You can see weather data and greetings fetched from API and function apps. So far, we’ve shown you how to provision and deploy a .NET app, including Azure Functions, to ACA with just one command. azd up. This is a very convenient way to deploy apps to Azure. However, you need to make a small adjustment to the auto-generated Bicep file so that the apps know each other. With this small adjustment, all .NET apps will be provisioned and deployed to ACA seamlessly. Another thing I want to mention here is when you use: .NET AspireThis type of service discovery is handled automatically. Learn more about deploying .NET apps to ACA. If you would like to learn more about deploying .NET apps to ACA, the following links may be helpful: This article was originally published on: Devkimchi. Source link Share 0 FacebookTwitterPinterestEmail info.odysseyx@gmail.com previous post (Preview) Dynamic watermarking available on Android and iOS with new date-time variable next post Copy Data to Azure SQL Database from Mainframe Db2 using Microsoft Fabric Data pipelines You may also like 7 Disturbing Tech Trends of 2024 December 19, 2024 AI on phones fails to impress Apple, Samsung users: Survey December 18, 2024 Standout technology products of 2024 December 16, 2024 Is Intel Equivalent to Tech Industry 2024 NY Giant? December 12, 2024 Google’s Willow chip marks breakthrough in quantum computing December 11, 2024 Job seekers are targeted in mobile phishing campaigns December 10, 2024 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.