Deploying JBoss AS/Wildfly on CentOS using Bicep

9 mins read

Learn how to deploy a node of WildFly on CentOS in Azure using Infrastructure-As-Code.

đŸ’ȘDeploying JBoss AS/Wildfly on CentOS using Bicep

This article will review how you can leverage Infrastructure-As-Code with Azure Bicep to deploy Wildfly on a CentOS virtual machine.

What is Wildfly?

WildFly, formerly known as JBoss AS, or simply JBoss, is an application server authored by JBoss. WildFly is an open-source, robust, modular, and lightweight application server that helps you build amazing applications.

WildFly provides a Java web application, an extension to the JVM with a complete runtime environment that will create the connection of the database on one end to the web client on the other.

It is Jakarta EE 8 Full Platform and Web Profile compatible. You can check the official website here:

WildFly

What is the difference between JBoss and WildFly?

JBoss AS/WildFly is the name for the community project that you can test. This community project will eventually become JBoss EAP. “WildFly” is just the new name for “AS”, which stood for Application Server.

The solution will consist of the following components:

CentOS 8 Virtual MachineVirtual NetworkWildFly 18.0.1.FinalSample Java application named JBoss-EAP on Azure deployed on WildFlyStorage Account

Pre-requisites:

An active Azure SubscriptionAzure Bicep installedAzure PowerShell installedA resource group in your Azure subscriptionA WildFly Username and password to access the WildFly Admin Console.

đŸ‘šâ€đŸ’»Our solution will include the following files:

📄main.bicep: This is our main Bicep template📄main.parameters.json: This file contains the parameters passed on during deployment time📁scripts: This folder will contain two scripts(wildfly-setup.sh and JBoss-EAP_on_Azure.war) that you should store/upload in a storage account.

You can grab the files from this repo:

azinsider/application-workloads/wildfly at main · daveRendon/azinsider

Before we start working on the Bicep template, it is important to create a resource group and a storage account. We will create a container in the storage account called ‘scripts’ and upload those two scripts(wildfly-setup.sh and JBoss-EAP_on_Azure.war).

Then, ensure you provide access to the storage account. Setup the Shared access signature as shown in the image below:

As shown in the above image, you can configure the access by going to your storage account, selecting the Shared access signature option. Then specify the start and expiry date/time. Lastly, ensure you choose HTTPS only and generate the SAS and connection string.

The connection string will be the artifactsLocation parameter. The SAS token will be the artifactsLocationSASToken parameter.

Not let’s start working on our Bicep template.

1. Azure Bicep template — parameters.

Now let’s work on the parameters. We will define the following:

@description(‘Linux VM user account name’)
param adminUsername string@allowed([
‘password’
‘sshPublicKey’
])
@description(‘Type of authentication to use on the Virtual Machine’)
param authenticationType string = ‘password’@description(‘Password or SSH key for the Virtual Machine’)
@secure()
param adminPasswordOrSSHKey string@description(‘User name for WildFly Manager’)
param wildflyUserName string@minLength(12)
@description(‘Password for WildFly Manager’)
@secure()
param wildflyPassword string@description(‘The base URI where artifacts required by this template are located.’)
param artifactsLocation string@description(‘The sasToken required to access _artifactsLocation.’)
@secure()
param artifactsLocationSasToken string@description(‘Location for all resources’)
param location string = resourceGroup().location@description(‘The size of the Virtual Machine’)
param vmSize string = ‘Standard_D2s_v3’

Note we reference the artifactsLocation and the SAS Token. We will execute the scripts as a custom extension.

Now let’s define the variables.

2. Azure Bicep template — variables.

We will define the following variables:

var singlequote = ”’
var imagePublisher = ‘OpenLogic’
var imageOffer = ‘CentOS’
var imageSKU = ‘8.0’
var nicName_var = ‘centos-vm-nic’
var addressPrefix = ‘10.0.0.0/16’
var subnetName = ‘centosvm-subnet’
var subnetPrefix = ‘10.0.0.0/24’
var vmName_var = ‘centos-vm’
var virtualNetworkName_var = ‘centosvm-vnet’
var bootStorageAccountName_var = ‘bootstrg${uniqueString(resourceGroup().id)}’
var storageAccountType = ‘Standard_LRS’
var linuxConfiguration = {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: ‘/home/${adminUsername}/.ssh/authorized_keys’
keyData: adminPasswordOrSSHKey
}
]
}
}
var subnetRef = resourceId(‘Microsoft.Network/virtualNetworks/subnets’, virtualNetworkName_var, subnetName)
var scriptFolder = ‘scripts’
var fileToBeDownloaded = ‘JBoss-EAP_on_Azure.war’
var scriptArgs = ‘-a ${uri(artifactsLocation, ‘.’)} -t “${artifactsLocationSasToken}” -p ${scriptFolder} -f ${fileToBeDownloaded}’

Note we use the variable ‘scriptArgs’ to reference the artifacts and include the reference the ‘JBoss-EAP_on_Azure.war’ file.

Next, let’s define the resources.

3. Azure Bicep template — resources.

The code below shows the resource definition:

resource bootStorageAccountName ‘Microsoft.Storage/storageAccounts@2021-02-01’ = {
name: bootStorageAccountName_var
location: location
sku: {
name: storageAccountType
}
kind: ‘Storage’
tags: {
QuickstartName: ‘WildFly 18 on CentOS 8 (stand-alone VM)’
}
}resource virtualNetworkName ‘Microsoft.Network/virtualNetworks@2019-11-01’ = {
name: virtualNetworkName_var
location: location
tags: {
QuickstartName: ‘WildFly 18 on CentOS 8 (stand-alone VM)’
}
properties: {
addressSpace: {
addressPrefixes: [
addressPrefix
]
}
subnets: [
{
name: subnetName
properties: {
addressPrefix: subnetPrefix
}
}
]
}
}resource nicName ‘Microsoft.Network/networkInterfaces@2019-11-01’ = {
name: nicName_var
location: location
tags: {
QuickstartName: ‘WildFly 18 on CentOS 8 (stand-alone VM)’
}
properties: {
ipConfigurations: [
{
name: ‘ipconfig1’
properties: {
privateIPAllocationMethod: ‘Dynamic’
subnet: {
id: subnetRef
}
}
}
]
}
dependsOn: [
virtualNetworkName
]
}resource vmName ‘Microsoft.Compute/virtualMachines@2019-12-01’ = {
name: vmName_var
location: location
tags: {
QuickstartName: ‘WildFly 18 on CentOS 8 (stand-alone VM)’
}
properties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: vmName_var
adminUsername: adminUsername
adminPassword: adminPasswordOrSSHKey
linuxConfiguration: ((authenticationType == ‘password’) ? json(‘null’) : linuxConfiguration)
}
storageProfile: {
imageReference: {
publisher: imagePublisher
offer: imageOffer
sku: imageSKU
version: ‘latest’
}
osDisk: {
name: ‘${vmName_var}_OSDisk’
caching: ‘ReadWrite’
createOption: ‘FromImage’
}
}
networkProfile: {
networkInterfaces: [
{
id: nicName.id
}
]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: reference(bootStorageAccountName_var, ‘2021-02-01’).primaryEndpoints.blob
}
}
}
dependsOn: [
bootStorageAccountName
]
}resource vmName_wildfly_setup ‘Microsoft.Compute/virtualMachines/extensions@2019-12-01’ = {
parent: vmName
name: ‘wildfly-setup’
location: location
properties: {
publisher: ‘Microsoft.Azure.Extensions’
type: ‘CustomScript’
typeHandlerVersion: ‘2.1’
autoUpgradeMinorVersion: true
settings: {
fileUris: [
uri(artifactsLocation, ‘scripts/wildfly-setup.sh${artifactsLocationSasToken}’)
]
}
protectedSettings: {
commandToExecute: ‘sh wildfly-setup.sh ${scriptArgs} ${wildflyUserName} ${singlequote}${wildflyPassword}${singlequote}’
}
}
}output vm_Private_IP_Address string = nicName.properties.ipConfigurations[0].properties.privateIPAddress
output appURL string = ‘http://${nicName.properties.ipConfigurations[0].properties.privateIPAddress}:8080/JBoss-EAP_on_Azure/’
output adminConsole string = ‘http://${nicName.properties.ipConfigurations[0].properties.privateIPAddress}:9990′

Note we use the ‘Microsoft.Compute/virtualMachines/extensions’ resource type and reference the script with the command to be executed.

Lastly, we will include a few outputs as shown below:

output vm_Private_IP_Address string = nicName.properties.ipConfigurations[0].properties.privateIPAddress
output appURL string = ‘http://${nicName.properties.ipConfigurations[0].properties.privateIPAddress}:8080/JBoss-EAP_on_Azure/’
output adminConsole string = ‘http://${nicName.properties.ipConfigurations[0].properties.privateIPAddress}:9990′

Here’s the complete Bicep template:

https://medium.com/media/4c4ff14a9e5994232727a777d9043c7c/href

You can find the complete solution here:

azinsider/application-workloads/wildfly at main · daveRendon/azinsider

Deploying JBoss AS/Wildfly on CentOS using Bicep

We will use the command below to deploy our Bicep template:

$date = Get-Date -Format “MM-dd-yyyy”
$deploymentName = “AzInsiderDeployment”+”$date”New-AzResourceGroupDeployment -Name $deploymentName -ResourceGroupName wildfly -TemplateFile .main.bicep -TemplateParameterFile .main.parameters.json -c

In the above command, we use the flag -c to have a preview of the deployment.

The image below shows the preview of the deployment.

Deploying JBoss / Wildfly using Bicep

Now we will proceed to execute the deployment. The figure below shows the output from the deployment.

Deployment output

We can also go to the Azure Portal and verify the deployment:

JBoss / Wildfly deployment

You can select the deployment name and check on the details of this deployment:

JBoss / Wildfly deployment details

👉 Join the AzInsider email list here.

-Dave R.

đŸ’ȘDeploying JBoss AS/Wildfly on CentOS using Bicep was originally published in CodeX on Medium, where people are continuing the conversation by highlighting and responding to this story.

Leave a Reply

Your email address will not be published.

Follow Us