Deploying to Azure App Service for Web Developers

Author

Reads 719

Computer server in data center room
Credit: pexels.com, Computer server in data center room

Deploying to Azure App Service is a straightforward process that can be completed in a few simple steps.

You can deploy your web application to Azure App Service using the Azure portal, Visual Studio, or Azure DevOps.

To get started, you'll need to create an Azure App Service plan, which determines the resources your app will use.

Azure App Service supports multiple frameworks, including .NET, Node.js, and Python, making it a versatile choice for web developers.

Prerequisites

Before you start deploying to Azure App Service, you'll need to create an App Service app, or use an app that you already created for another tutorial.

If you don't have an Azure subscription, you'll need to create an Azure free account before beginning this process.

You'll need to use an ARM template to deploy to Azure App Service, and these templates only support deployments from remotely hosted packages.

Create a Web

To create a web in Azure App Service, you'll want to set up a new resource group. This is where you'll manage all your resources, including your web app.

Modern data center corridor with server racks and computer equipment. Ideal for technology and IT concepts.
Credit: pexels.com, Modern data center corridor with server racks and computer equipment. Ideal for technology and IT concepts.

You can create a resource group using the Azure portal, PowerShell, or the Azure CLI. For example, you can use the Azure portal to create a resource group in a matter of minutes.

In the Azure portal, navigate to the "Resource groups" page, click "New", and fill in the required details, such as name, location, and tags.

Node

When you're working with Node, you'll notice that Kudu executes the build steps for your application by default. This includes running npm install.

If you're using a build service like Azure DevOps, you can skip the Kudu build altogether. To disable it, simply create an app setting called SCM_DO_BUILD_DURING_DEPLOYMENT and set its value to false.

This setting will prevent Kudu from running the build steps, saving you time and resources.

Create a Web

Creating a web involves setting up a network of interconnected nodes or pages.

A website is typically composed of multiple pages, with each page serving a specific purpose or function.

Computer server in data center room
Credit: pexels.com, Computer server in data center room

The first step in creating a web is to define its purpose and scope.

This will help determine the number of pages and the type of content needed.

A well-structured web will have a clear hierarchy of pages, with related content grouped together.

For example, a personal blog might have separate pages for about me, contact, and blog posts.

The choice of web framework or content management system (CMS) will also impact the structure of the web.

Some popular CMS options include WordPress and Joomla, each with their own strengths and weaknesses.

Using Docker with Web

You can use Docker with Web Apps for containers, and the latest preview Docker images are available on the Docker Hub at https://hub.docker.com/_/microsoft-dotnet.

These images can be used as a base image, and you can deploy to Web Apps for Containers normally.

To automate your container deployment, you can use GitHub Actions, which can build and tag the container with the commit ID, push it to a container registry, and update the specified web app with the new image tag.

You can find the workflow file for GitHub Actions in the relevant documentation.

Source

Credit: youtube.com, Intro to Web Source with SQL in Oracle APEX

To create a web, you need to start with a source. This can be a repository hosted by version control software like GitHub, BitBucket, or Azure Repos, which is ideal for production apps.

For development and test scenarios, you can use a project on your local machine as the deployment source. Creating a pipeline is easy in the DevOps portal, just visit the Pipelines tab for your project and select "New Pipeline".

Upload and Publish

To upload and publish your application to Azure App Service, you'll need to create a ZIP file. This can be done using either Azure CLI or an HTTP client like cURL. You can use the az webapp deploy command to upload and deploy a zip file to Azure.

You'll need to obtain the deployment username and password for your App Service, which can be found in the Azure portal. Specifically, go to the Deployment center, select the FTPS credentials tab, and look for the Username and Password under the Application scope heading. For zip file deployments, only use the part of the username after the \ character that starts with a $.

Credit: youtube.com, Create & deploy app services

Here are the available query parameters when using the Kudu publish API to upload and publish your application:

Files usually take between 10 and 30 seconds to upload to Azure, depending on your network bandwidth.

Publish the

Publishing your app is a crucial step in getting it live on Azure. You can use the az webapp deploy command to deploy your app.

To deploy a zip file, you can use either Azure CLI or an HTTP client like cURL. You'll need the deployment username and password for your App Service, which can be obtained from the Azure portal.

The az webapp deploy command can be used to upload and deploy a zip file to Azure. You can also use cURL to upload your ZIP file to Azure, but you'll need the deployment username and password for your App Service.

Here are some options for deploying individual files:

  • Deploy a startup script, library, or static file to your web app using the az webapp deploy command with the --type parameter.
  • Use the Kudu publish API to deploy files and customize the deployment process.
  • Deploy a library file using the cURL tool and specify the URL of a ZIP file hosted in an Azure Storage account.

When publishing your app, make sure to set the Platform to 64 Bit in the App Service's Configuration > General settings if you're using a 64-bit .NET Core SDK to build a 64-bit app.

Build and Publish

Credit: youtube.com, Build & Publish Your Own Go Package

Building and publishing your app is a crucial step in getting it live on Azure. You can start with a default template that includes a single step to build your app in release mode whenever a change is checked into the master branch.

To publish your website, you'll need to use the .NET Core CLI task. You can specify the build configuration you want, like Release, by overriding the arguments. The YAML for your publish step should include the -o argument to specify the output location, especially if your website includes static assets like zip files.

The Kudu publish API allows you to specify parameters from the CLI command as URL query parameters. You can authenticate with the API using token authentication or basic authentication with your app's deployment credentials.

Here are the available query parameters for the Kudu publish API:

To ensure your app is published correctly, make sure to use a 64-bit .NET Core SDK to build a 64-bit app and set the Platform to 64 Bit in the App Service's Configuration > General settings.

Configure and Automate

Credit: youtube.com, How To Deploy Your Application To Azure Using GitHub Actions | CI/CD Pipeline

To configure and automate your Azure App Service deployment, you need to enable build automation and configure the startup script. You can do this by setting the SCM_DO_BUILD_DURING_DEPLOYMENT app setting to true, either in the Azure portal or using the Azure CLI command az webapp config appsettings set.

For apps based on web frameworks like FastAPI, you need to configure a custom startup command for App Service to run your app. This involves using the az webapp config set command to configure the startup command, then restarting the web app.

To use other automation providers like CircleCI or Travis CI, you need to use the Azure CLI to update the deployment slots with new image tags in the final step. This involves generating a Service Principal using the az ad sp create-for-rbac command, then using az login --service-principal to sign in and az webapp config container set to set the container name, tag, registry URL, and registry password.

.NET

Credit: youtube.com, .NET Configuration In Depth | .NET Conf 2023

The .NET configuration is a crucial part of automating your deployment process. You can disable the Kudu build by creating an app setting named SCM_DO_BUILD_DURING_DEPLOYMENT with a value of false.

To deploy an ASP.NET Core app that uses a .NET Core preview, you'll need to follow one of several approaches. These include specifying the .NET Core SDK Version using Azure Pipelines, deploying a self-contained preview app, using Docker with Web Apps for containers, or installing the preview site extension.

The default template for build and publish steps includes a single step that calls dotnet build in release mode. However, you may need to override the arguments to specify the build configuration you want, such as Release.

To deploy the app framework-dependent, you'll need to follow these steps. First, right-click the project in Solution Explorer and select Publish. Then, in the Publish dialog, select Azure > Next, and select the Azure service.

Credit: youtube.com, .NET for Infrastructure Automation

Here are the key steps to install the preview site extension:

1. From the Azure Portal, navigate to the App Service.

2. Select the web app.

3. Type "ex" in the search box to filter for "Extensions" or scroll down the list of management tools.

4. Select Extensions.

5. Select Add.

6. Select the ASP.NET Core {X.Y} ({x64|x86}) Runtime extension from the list, where {X.Y} is the ASP.NET Core preview version and {x64|x86} specifies the platform.

7. Select OK to accept the legal terms.

8. Select OK to install the extension.

You can verify the installation by running the following command in the Azure Kudu PowerShell command window: Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.{PLATFORM}\

Configure Startup Script

App Service automatically detects the presence of a Flask app, so no additional configuration is needed for this quickstart. For Django apps, App Service also detects their presence without needing extra setup.

To configure a startup script for App Service, you need to specify a custom startup command for FastAPI apps. This command starts Gunicorn with 2 Uvicorn worker processes: gunicorn -w 2 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 main:app.

Credit: youtube.com, My PowerShell Scripts - Systems Administration #powershell #script #sysadmin

To configure the startup command, use the az webapp config set command, or use the Azure portal to configure the startup command. Once you've configured the startup command, restart the web app.

Here's a step-by-step guide to configuring the startup command:

1. Configure the startup command in Azure App Service.

2. Navigate to the page for the App Service instance in the Azure portal.

3. Next, restart the web app.

By following these steps, you can configure a custom startup script for your FastAPI app and ensure it runs correctly in App Service.

Reliable Web Patterns

Creating a reliable web app is crucial for any business, and the good news is that it's achievable with the right approach. You can create a modern, reliable, performant, testable, cost-efficient, and scalable ASP.NET Core app.

To get started, you can refer to The Reliable Web App Pattern for .NET, which offers guidance on creating such an app from scratch or refactoring an existing one. This pattern is a great resource to have in your toolkit.

Credit: youtube.com, Everything You NEED to Know About WEB APP Architecture

By following this pattern, you can ensure your app meets the necessary criteria for reliability, performance, and scalability. This will give you peace of mind and save you time and resources in the long run.

The Reliable Web App Pattern for .NET also includes resources such as YouTube videos and articles that can help you along the way.

Deployment Options

Deploying to Azure App Service offers several options for getting your application up and running. You can deploy to Azure with Git, which enables version control, package restore, MSBuild, and more.

Azure App Service supports several deployment mechanisms, including Kudu endpoints, FTP, and WebDeploy. Kudu handles continuous deployments and provides HTTP endpoints for deployment, such as zipdeploy.

You can use deployment tools like Azure Pipelines, Jenkins, and editor plugins to automate the deployment process. These tools use one of the supported deployment mechanisms, such as Kudu endpoints or FTP and WebDeploy.

Here are the supported deployment mechanisms:

  • Kudu endpoints: Kudu handles continuous deployments and provides HTTP endpoints for deployment, such as zipdeploy.
  • FTP and WebDeploy: These mechanisms don't go through Kudu and allow you to upload files via FTP or WebDeploy.

Next Steps

Credit: youtube.com, The BEST way to host Next.js websites

If you're ready to take your deployment to the next level, consider trying Azure with Git. Git-based deployment to Azure enables version control, package restore, MSBuild, and more.

Azure with Git offers a more advanced deployment scenario that can handle complex projects with ease. It's perfect for teams that need to collaborate on code and keep track of changes.

With Git-based deployment, you can automate the build process and make sure your code is always up-to-date. This means fewer errors and less time spent on debugging.

Azure with Git also supports continuous integration and continuous deployment (CI/CD) pipelines, which can help you streamline your workflow and get your app to market faster.

Mechanism

The deployment mechanism is the action used to put your built application into the /home/site/wwwroot directory of your web app. This directory is a mounted storage location shared by all instances of your web app.

There are two main deployment mechanisms supported by App Service: Kudu endpoints and FTP/WebDeploy. Kudu is an open-source developer productivity tool that handles continuous deployments and provides HTTP endpoints for deployment.

Credit: youtube.com, Deployment options for OSGi applications in the cloudedge

You can use FTP or WebDeploy to upload files via your site or user credentials. These mechanisms don't go through Kudu, so you'll need to use a different approach for deployment.

Here are the supported deployment mechanisms:

  • Kudu endpoints: Handles continuous deployments and provides HTTP endpoints for deployment.
  • FTP and WebDeploy: Upload files via your site or user credentials.

Deployment tools like Azure Pipelines, Jenkins, and editor plugins use one of these deployment mechanisms to automate the process.

Platform

The platform architecture of an App Services app is set in the app's settings in the Azure Portal for apps that are hosted on an A-series compute (Basic) or higher hosting tier.

Confirm that the app's publish settings match the setting in the app's service configuration in the Azure Portal. This is important to ensure a smooth deployment.

ASP.NET Core apps can be published framework-dependent because the runtimes for 64-bit (x64) and 32-bit (x86) apps are present on Azure App Service.

The .NET Core SDK available on App Service is 32-bit, but you can deploy 64-bit apps built locally using the Kudu console or the publish process in Visual Studio.

For apps with native dependencies, runtimes for 32-bit (x86) apps are present on Azure App Service, and the .NET Core SDK available on App Service is also 32-bit.

Frequently Asked Questions

How to deploy an application on an Azure App Service?

To deploy an application on Azure App Service, start by creating an App Service Plan in the Azure portal and then deploy your application from Visual Studio Code. Follow these 4 simple steps to get your application up and running on Azure App Service.

What are the two components of deploying an Azure App Service application?

When deploying an Azure App Service application, you'll need to package the code and configuration. This is the core of the deployment process, but keep in mind that additional setup may be required for a fully functional application.

What is the deployment center in the Azure web app?

The Azure App Service Deployment Center is a centralized hub for managing application deployments, providing a seamless experience and supporting log analysis for troubleshooting. It's a one-stop-shop for deploying and monitoring your web apps with ease.

Oscar Hettinger

Writer

Oscar Hettinger is a skilled writer with a passion for crafting informative and engaging content. With a keen eye for detail, he has established himself as a go-to expert in the tech industry, covering topics such as cloud storage and productivity tools. His work has been featured in various online publications, where he has shared his insights on Google Drive subtitle management and other related topics.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.