Home NewsX Deploying .NET Apps to Azure Container Apps with One Command, azd up

Deploying .NET Apps to Azure Container Apps with One Command, azd up

by info.odysseyx@gmail.com
0 comment 7 views


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.

All apps are running

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.

Use code from current directory

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.

Confirm and continue

The function app asks for the target port number. Enter 80.

Enter the target port number

Finally, it asks you for the environment name. Enter whatever name you want. I just entered it. aca0906 now.

Enter the environment name

Now we have created two directories and two files.

  • .azure directory
  • infra directory
  • next-steps.md file
  • azure.yaml file

Created directories and files

Below infra A Bicep file is automatically created in the directory. azd init.

Biceps file created

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.

Select a subscription and location for resource provisioning

All apps are containerized and deployed to ACA. Once the deployment is complete, you can see the output as below.

Distribution complete

Click on the web app URL and navigate to it. /weather page. But it shows error as below.

Web App Error

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.

All apps are running


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

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX