/
DeployBatchComponents.ps1
58 lines (46 loc) · 2.51 KB
/
DeployBatchComponents.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Many components under an Azure Batch account can't be provisioned via an ARM template
# yet. For this reason we use this PowerShell script after running the ARM template
### Replace the following variable values with yours
# Resource group name where the batch account is deployed
$rg = "PythonBatch-4"
# Name of the batch account as specified when running the ARM template
$batchAccount = "vplbatch4"
# Name of the storage account as specified when running the ARM template
$storageAccount = "vplbatchsto4"
### Those variable values do not need to be changed
$pythonAppID = "PythonScript"
$pythonAppVersion = "1.0"
$setupAppID = "PythonSetup"
$setupAppVersion = "1.0"
# Create a folder to copy resources locally
mkdir tmp-resources
# Copy resources locally
Invoke-WebRequest -Uri `
"https://github.com/vplauzon/batch/raw/master/PythonBatch/PythonBatchDeploy/Resources/sample.py" `
-OutFile tmp-resources/sample.py
Invoke-WebRequest -Uri `
"https://github.com/vplauzon/batch/raw/master/PythonBatch/PythonBatchDeploy/Resources/setup-python.sh" `
-OutFile tmp-resources/setup-python.sh
# Build an archive for each resource separately
Compress-Archive -Path "tmp-resources\sample.py" -DestinationPath "tmp-resources/sample.zip" `
-CompressionLevel Optimal
Compress-Archive -Path "tmp-resources\setup-python.sh" -DestinationPath "tmp-resources/setup-python.zip" `
-CompressionLevel Optimal
### Configure Batch account
# Create 2 batch applications
New-AzureRmBatchApplication -ResourceGroupName $rg -AccountName $batchAccount -ApplicationId $pythonAppID
New-AzureRmBatchApplication -ResourceGroupName $rg -AccountName $batchAccount -ApplicationId $setupAppID
# Upload 2 batch application packages
New-AzureRmBatchApplicationPackage -ResourceGroupName $rg -AccountName $batchAccount `
-ApplicationVersion $pythonAppVersion -ApplicationId $pythonAppID -Format zip -FilePath `
"tmp-resources/sample.zip"
New-AzureRmBatchApplicationPackage -ResourceGroupName $rg -AccountName $batchAccount `
-ApplicationVersion $setupAppVersion -ApplicationId $setupAppID -Format zip -FilePath `
"tmp-resources/setup-python.zip"
# Set default version of the applications
Set-AzureRmBatchApplication -ResourceGroupName $rg -AccountName $batchAccount -ApplicationId $pythonAppID `
-DefaultVersion $pythonAppVersion
Set-AzureRmBatchApplication -ResourceGroupName $rg -AccountName $batchAccount -ApplicationId $setupAppID `
-DefaultVersion $setupAppVersion
### Clean temporary folder
rmdir tmp-resources -Force -Recurse