<commit_before><commit_msg>Azure guide for Quarkus Native applications in Docker containers (#3199)<commit_after>////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc
////
= Quarkus - Deploying to Microsoft Azure Cloud

include::./attributes.adoc[]

This guide covers:

* Update Quarkus HTTP Port
* Install the Azure CLI
* Create an Azure Registry Service instance and upload the Docker image
* Deploy the Docker image to Azure Container Instances
* Deploy the Docker image to Azure Kubernetes Service
* Deploy the Docker image to Azure App Service for Linux Containers

== Prerequisites

For this guide you need:

* roughly 2 hours for all modalities
* having access to an Azure subscription. https://azure.microsoft.com/free/?WT.mc_id=opensource-quarkus-brborges[Get a free one here]

This guide will take as input a native application developed in the link:building-native-image-guide.html[building native image guide].

Make sure you have the getting-started application at hand, or clone the Git repository: `git clone {quickstarts-clone-url}, or download an {quickstarts-archive-url}[archive]. The solution is located in the `getting-started` directory.

== 1. Change Quarkus HTTP Port

If you correctly followed the link:building-native-image-guide.html[building native image guide], you should have a local container image named `quarkus-quickstart/getting-started`. 

While Quarkus by default runs on port 8080, most Azure services expect web applications to be running on port 80. Before we continue, go back to your quickstart code and open the file `src/main/docker/Dockerfile.native`.

Change the last two commands in the `Dockerfile.native` file and make it read like this:

[source,docker]
----
EXPOSE 80
CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Dquarkus.http.port=80"]
----

Now you can rebuild the docker image:

    docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .

To test, run it by exposing port 80 into port 8080 in your host:

    docker run -i --rm -p 8080:80 quarkus-quickstart/getting-started

Your container image is now ready to run on Azure. Remember, the Quarkus application is mapped to run on port 80.

== 1. Install the Azure CLI

To ease the user experience throughout this guide, it is better to have the Azure CLI installed and authenticated.

Visit the https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest?WT.mc_id=opensource-quarkus-brborges[Azure CLI] installation page for instructions specific to your operating system.

Once installed, ensure you are authenticated:

`$ az login`

== 1. Create an Azure Container Registry instance

It is possible to deploy images hosted on Docker Hub, but this location by default leaves images accessible to anyone. To better protect your container images, this guide shows how to host your images on a private instance of the Azure Container Registry service.

First, create an Azure Resource Group:

    az group create --name <resource-group-name> --location eastus

Then you can create the ACR:

    az acr create --resource-group <resource-group-name> --name <registry-name> --sku Basic --admin-enabled true

Finally, authenticate your local Docker installation with this container registry by running:

    az acr login --name <registry-name>

== 1. Upload Container Image on Azure

If you've followed the build native image guide, you should have a local container image named `quarkus-quickstart/getting-started`.

To upload this image to your ACR, you must tag and push the image under the ACR login server. To find the login server of the Azure Container Registry, run this command:

    az acr show -n <registry-name> --query loginServer

To upload, now do:

    docker tag quarkus-quickstart/getting-started <acr-login-server>/quarkus-quickstart/getting-started

    docker push <acr-login-server>/quarkus-quickstart/getting-started

At this point, you should have your Quarkus container image on your Azure Container Registry. To verify, run the following command:

    az acr repository list -n <registry-name>

== 1. Deploy to Azure Container Instances

The simplest way to start this container in the cloud is with the Azure Container Instances service. It simply creates a container on Azure infrastructure. 

There are different approaches for using ACI. Check the documentation for details. The quickest way to get a container up and running goes as it follows:

First step is to find the username and password for the admin, so that ACI can authenticate into ACR and pull the Docker image:

    az acr credential show --name <registry-name>

Now create the Docker instance on ACI pointing to your image on ACR:

    az container create \
        --name quarkus-hello \
        --resource-group <resource-group> \
        --image <acr-login-server>/quarkus-quickstart/getting-started \
        --registry-login-server <acr-login-server> \
        --registry-username <acr-username> \
        --registry-password <<PASSWORD>> \
        --dns-name-label quarkus-hello-<random-number> \
        --query ipAddress.fqdn

The command above, if run successfuly, will give you the address of your container in the Cloud. Access your Quarkus application in the address displayed as output.

For more information and details on ACR authentication and the use of service principals, follow this guide below and remember the Azure Container Registry `loginServer` and the image name of your Quarkus application now hosted on the ACR.

https://docs.microsoft.com/en-us/azure/container-instances/container-instances-using-azure-container-registry?WT.mc_id=opensource-quarkus-brborges[Deploy to Azure Container Instances from Azure Container Registry]

Keep in mind that this service does not provide scalability. A container instance is unique and does not scale.

== 1. Deploy to Azure Kubernetes Service

You can also deploy the container image as a microservice in a Kubernetes cluster on Azure. To do that, follow this tutorial:

https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-deploy-cluster?WT.mc_id=opensource-quarkus-brborges[Tutorial: Deploy an Azure Kubernetes Service (AKS) cluster]

Once deployed, the application will be running on whatever port is used to expose the service. By default, Quarkus apps run on port 8080 internally.

== 1. Deploy to Azure App Service on Linux Containers

This service provides scalability out of the box for web applications. If more instances are required, it will provide a load-balancing automatically, plus monitoring, metrics, logging and so on.

To deploy your Quarkus Native container image to this service, follow this tutorial:

https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image?WT.mc_id=opensource-quarkus-brborges[Tutorial: Build a custom image and run in App Service from a private registry]

{'fraction_non_alphanumeric': 0.06924177396280401, 'fraction_numerical': 0.006294706723891273, 'mean_word_length': 4.163220088626293, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6430175', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1797, 'n_words': 866}