Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Objective

You have a working Python docker web application and the source code is managed in a Git repository.  The goal of the tutorial is to automate the build and publish of a docker image to Azure Web App. This automation will include:

...

We will walk through each of the FlexDeploy features that will be created/configured to accomplish this goal and have the Python docker web application deployed in a very short amount of time.

Checklist

Checklist

Description

Azure Tenant Id

Azure Tenant Id for the company

Azure Subscription Id

Azure Subscription where the Web App exists

Azure Client ID

Client ID to connect to desired Azure Subscription

Azure Client Key

Password for the Client ID

Azure Client ID permission

The Client ID must have relevant access in the target Web App to deploy code

Azure Web App

The Web App with relevant runtime should already be created

Azure Resource Group

The Resource Group containing the Web App

Azure CLI installation

Azure CLI needs to be installed on the Target m/c where the plugin operation shall run

Azure CLI in class path

Azure CLI should be added to the classpath in target m/c. Else the path can also be set under FlexDeploy environment level property

Docker Registry Address

Target Azure Container Registry URL

Docker Registry User

Azure Client ID to push/pull images against Azure Container Registry

Docker Registry Token/Password

Password for the above Client ID

Docker Registry User permission

The Client ID must have relevant access to push/pull images from Azure Container Registry

Configure cloud account

First, an Azureaccount needs to be configured under Topology. FlexDeploy will connect to the right Azure Subscription with provided details and do the deployment.

...

  1. Client Key is a password field and hence needs to be kept hidden. To update the same click on the pencil icon as shown below

  2. next update the Client Key value under Secret Text. This is to make sure no one else can retrieve the password

...

Configure container account

Next, a DockerRegistry account needs to be configured under Topology. FlexDeploy will connect to the right Container Registry with provided details and push the docker image.

...

  1. Docker Registry Token/Password is a password field and hence needs to be kept hidden. To update the same click on the pencil icon as shown below

  2. next update the Client Key value under Secret Text. This is to make sure no one else can retrieve the password

...

Git repository structure

The Git repository should contain the codebase. A dockerfile should exist within the codebase with steps defined to create the docker image. Alongside it can also contain any Application Setting and Connection String-related attributes in respective files(any naming convention allowed). These files are not mandatory, however, in case someone has any Application Setting and Connection String property to update this is recommended option. Please review the Application Setting and Connection String property update for a detailed explanation.

The Sample Git repository structure is given below.

...

Build and Deploy Workflows

Navigate to the Workflows tab and create a build and a deploy workflow using the +”(Click to create new Workflow) (blue star) button as highlighted below.

...

  1. navigate to the Workflows Tab

  2. Select the “+” button from the left-hand pane to create a new workflow with type as Deploy.

...

The Workflow Group and Subgroup define the folder hierarchy. Once both workflows are created it should look like the below. No constraint on workflow or folder naming convention.

...

The steps of the workflow execution can be configured through the Workflow Definition section.

...

  1. create a new workflow with type as Deploy.

...

Build Workflow

Below given is a sample build workflow to build and push the docker image and create an artifact from the Application Setting and Connection String file.

...

The plugin operation by default would look for Dokerfile Dockerfile under TEMP directory. In case the same exist in some other folder, relative path has to be specified from TEMP directory.

...

Note: the deployWebApp operation(Azure plugin) will search for the Application Setting and Connection String file name provided as part of Project properties. Irrespective of folder structure it will find the file. In case more than one file exists with the same name, flow shall the workflow will fail.

Deploy Workflow

Below given is a sample deployment workflow to deploy the archive to Azure Web App.

...

First, navigate to the Workflow Definition tab and click on open the Create/View Inputs button as shown below Inputs popup.

...

Create two input variables, one each for Application Setting and Connection String as shown below.

...

The input arguments are then mapped to the input properties of the deployWebApp operation as shown below. The plugin will take the input values and process them accordingly.

...

The deployWebApp operation returns four output variables. To capture them and use them for further processing/evaluation, one can create four variables and map them against the output parameters of deployWebApp operation. Return As Output drop down option should be set as Yeschecked.

  1. First, navigate to the Workflow Definition tab and click on open the X2 Variables buttonpopup

  2. Next use Create option to add four output variables.

...

Map the variables against the output of the deployWebApp plugin operation to capture the responses.

...

Project configuration

Navigate to the Project tab and create a Project with a logical name(PythonDockerAzureWebApp in this case)

...

Configure the Build and Deploy workflow that has been created in previous steps as shown below

...

Anchor
Source_Control
Source_Control
Source Control

Configure the Source SCM repository under Source Control as shown below.

...

  1. To configure Project specific Source Control one first need to navigate to the Project Configuration tab.

  2. Next, expand the SOURCE CONTROL option from the left-hand pane.

  3. Select SOURCES for configuring the Source Repository

  4. Select the appropriate Source Control Type

  5. Configure Source Repository. For detailed steps of Source Control configuration please refer to Configure Source Control in FlexDeploy

Project Properties

To configure Project specific settings one can navigate to Configuration Properties as shown below.

...

  1. To configure Project specific settings one can navigate to the Project Configuration tab as shown above.

  2. Next, select the PROPERTIES option from the left-hand pane.

  3. To deploy a web application to Azure Web App, the first two mandatory properties are the Web App Name and Resource Group Name. These need to be configured under Project properties.

  4. Under Project properties, one also needs to provide the Application Setting/Connection String file names(if applicable).

  5. Docker Image Name and Docker Image Tag are essential to build the docker image.

Anchor
Application_Setting
Application_Setting
Application Setting and Connection String property

These Application Setting/Connection String properties are non-mandatory and can be directly provided as plugin Input as well. Or even may not be passed at all. However this is the recommended way and the files should exist in working directory(TEMP) during execution(folder hierarchy is not required, the plugin will search the file based on the file name).--

...

There could also be scenarios where someone only need to update the Application Setting or Connection String without actually deploying the code. In that case one can use upsertWebAppApplicationSetting or upsertWebAppConnectionString operations respectively. The workflow execution will be exactly same only the code archive creation /Docker image update step will not be required. Build workflow generated artifact should only container AppSetting.json or ConnString.json. These values can also be passed as input as already mentioned in detail in above section.

Target Properties

Select Topology from the menu and then select Topology Overview from the left menu. You will see a table that has Instances as the rows and Environments as the columns with colored circles representing the Environment Instance. Color coding represents:

...

Selecting the GREEN circle for DEV will display the configurable properties/Endpoint and allows for the configuration of

Properties

Mandatory field

Description

Slot Name

 

Target slot for deployment

Target slot to swap

Optional

In case slot swap is required

Azure Cloud Account

 

An azure account with relevant details

The absolute path of Azure CLI

Optional

Not required if Azure CLI already added to workflow execution m/c classpath

Docker Server

Optional

Docker server address. Required if Docker Unix Socket is not set.

Docker Server Port

Optional

The port to connect to on the Docker server.

Docker Unix Socket

Optional

The socket the Docker daemon listens on

The default value is [/var/run/docker.sock]

Registry Account

Docker Registry account with relevant details

GIT Path

Optional

Path to the Git executable. Required only if git is not on class path.

Below given are the env-specific values which need to be updated.

...

The Azure Could and Docker Registry account needs to be set here from the drop-down. It will show all Cloud/Container Accounts configured under Topology, which we have already mentioned earlier.

...

Anchor
Deploytoslot
Deploytoslot
Deploy to slot

Azure Web App default slot is production. However, one can configure multiple slots and deploy web application on those slots inside Web App. Web App Slot Name is a mandatory field, where the code needs to deploy.

...

executeWebAppSlotSwap operation can be used to perform the slot swap.

Post deployment debugging

Post deployment success it can take 1-2 mins to download the image from Docker Registry and start the container by Azure Web App.

...

In case of successful execution, we can find below msg stating the container is up and running.

...

Build Execution

For detailed steps on how to initiate Build Azure Web App, review artifacts, and ultimately deploy to Azure Web App please refer to Build and deploy execution through FlexDeploy

...