Skip to content

andygeorgi/az_batch_hellodocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Helloworld for Docker with Azure Batch

Software requirements

This project was tested with the following software packages/modules:

Software Version
azure-cli 2.20.0
2.21.0
Python 3.6
3.7
3.8
azure-batch 9.0.0
10.0.0
azure-common 1.1.25
1.1.26
azure-core 1.9.0
1.12.0
azure-storage-blob 12.5.0
12.8.0

Create and prepare a Batch Account

If you want to use the portal please refer to the official documentation on how to Create a Batch Account with the Azure portal and how to Authenticate Batch service solutions with Active Directory.

If you prefer a programmatic approach, you can follow the steps below:

#Set values for Azure resources
subscription="Microsoft Internal Subscription"
rg="rgbatchdemo"
region="westeurope"
storageAcc="sabatchdemo"
batchAcc="babatchdemo"
servicePrincipal="spbatchdemo"
#Azure login with MFA, opens in a new broswer window
az login
az account set --subscription "${subscription}"
az configure --defaults location="${region}"
# Create a resource group which will contain all resources of this helloworld example (output skipped ...)
az group create --name "${rg}"
# Create a storage account to be used by Azure Batch in the resource group created (output skipped ...)
az storage account create --resource-group "${rg}" --name "${storageAcc}" --sku Standard_LRS
# Create an Azure batch account in the specified resource group with the created storage account and note the accountEndpoint (output reduced)
az batch account create --resource-group "${rg}" --name "${batchAcc}" --storage-account "${storageAcc}"
    { 
      ...
      "accountEndpoint": "babatchdemo.westeurope.batch.azure.com",
      ...
    }
# Create an Azure service principal and note appID, password and tenant
az ad sp create-for-rbac --name "http://${servicePrincipal}" --role Contributor --years 1
    {
      "appId": "#####################################",
      "displayName": "spbatchdemo",
      "name": "http://spbatchdemo",
      "password": "#####################################",
      "tenant": "#####################################"
    }

Checkout and run the helloworld script

# Checkout and prepare Python venv
git clone https://github.com/andygeorgi/az_batch_hellodocker.git
cd az_batch_hellodocker
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip
pip3 install azure-batch azure-common azure-core azure-storage-blob
# Fill Batch account and service principal information which have been created previously and check if the other parameters fit the needs
# common/config.py
    TENANT_ID = ''
    BATCH_ACCOUNT_URL = ''
    APP_ID = ''
    PASSWORD = ''
# Run the script that launches a job on a newly created pool, and a task that launches a Docker container that runs the task
# When it finishes, it waits for any key to be pressed, then deletes the pool, job, and task
python3 CreatePool-DockerHub-Image.py
    Attempting to create pool: container-test-pool-20210324-150514
    Created pool: container-test-pool-20210324-150514
    waiting for all nodes in pool container-test-pool-20210324-150514 to reach one of: frozenset({<ComputeNodeState.start_task_failed: 'starttaskfailed'>, <ComputeNodeState.idle: 'idle'>, <ComputeNodeState.unusable: 'unusable'>})
    waiting for 1 nodes to reach desired state...
    waiting for 1 nodes to reach desired state...
    waiting for 1 nodes to reach desired state...
    pool created successfully and 1 nodes are up and ready for job execution
    Creating job [container-test-job-20210324-150755]...
    Creating task [container-test-task-20210324-150755]...
    ######################################################################################################
    Pool [container-test-pool-20210324-150514], job [container-test-job-20210324-150755] and task [container-test-task-20210324-150755] will be deleted...
    ######################################################################################################
    Press any key to continue...

Cleanup

# Delete the resource group and all contained resources
az group delete --resource-group "${rg}" --yes
# Delete the service principal and its role assignments
az ad sp delete --id http://${servicePrincipal}

About

Helloworld with Azure Batch and Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages