Skip to content

Commit bf2f57f

Browse files
committed
Added better resume support, exact line number for errors, updated default machine size
1 parent 0ab4825 commit bf2f57f

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ Create a new resource, search for the prebuilt image noted above. You do not ne
8080
I suggest auto-shutdown to make sure you don't leave it running.
8181

8282
#### Azure Auto Create Scripts
83-
If you have an azure account already created you can use the az_create.ps1 script to automatically setup the VM for you. It will create everything under a new "CEFTest" resource group to make cleanup at the end easy. You can adjust the settings at the top if desired but really the only important options you pass as options to it. It will setup the VM and enable remote powershell to make the process very easy. Just launch powershell (or type powershell into the run box in windows). If the first time using powershell with azure you will need to install the tools for azure: ```Install-Module -Name AzureRM -Scope CurrentUser```. Next change to the folder with all the CefSharpDockerfiles (cd c:\downloads\CefSharpDockerfiles for example).
83+
If you have an azure account already created you can use the az_create.ps1 script to automatically setup the VM for you. It will create a Standard_F32s_v2 VM by default but this is 32 cpu's. New Azure accounts need to file a support request to increase CPU quota beyond 10. These are often approved within minutes but if you don't want to do so you can edit az_create.ps1 and change the size to something like a Standard_F8s_v2. It will take longer to build but your cost will be roughly the same total cost.
84+
85+
It will create everything under a new "CEFTest" resource group to make cleanup at the end easy. You can adjust the settings at the top if desired but really the only important options you pass as options to it. It will setup the VM and enable remote powershell to make the process very easy. Just launch powershell (or type powershell into the run box in windows). If the first time using powershell with azure you will need to install the tools for azure: ```Install-Module -Name AzureRM -Scope CurrentUser```. Next change to the folder with all the CefSharpDockerfiles (cd c:\downloads\CefSharpDockerfiles for example).
8486

8587
Login with your azure credentials first:
8688
```Connect-AzureRmAccount```

az_create.ps1

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
[CmdletBinding()]
22
Param(
33
[Parameter(Mandatory=$true)]
4-
[String] $admin_creds,
4+
[PSCredential] $admin_creds,
55
[String] $shutdown_email
66
)
77
Set-StrictMode -version latest
88
$ErrorActionPreference = "Stop";
9-
109
$VAULT_NAME = "CEFVault"
1110
$RESOURCE_GROUP = "CEFTest"
1211
$LOCATION="West US 2"
13-
$MACHINE_SIZE="Standard_F2s_v2"
12+
$MACHINE_SIZE="Standard_F32s_v2"
1413
$SECRET_NAME="CEFPSCertSecret"
1514
$CERT_PASS="dummy"
1615
$SHUTDOWN_TIME="23:30";
1716
$SHUTDOWN_TIMEZONE="Pacific Standard Time";
17+
Function WriteException($exp){
18+
write-host "Caught an exception:" -ForegroundColor Yellow -NoNewline
19+
write-host " $($exp.Exception.Message)" -ForegroundColor Red
20+
write-host "`tException Type: $($exp.Exception.GetType().FullName)"
21+
$stack = $exp.ScriptStackTrace;
22+
$stack = $stack.replace("`n","`n`t")
23+
write-host "`tStack Trace: $stack"
24+
}
25+
26+
try{
27+
28+
1829
$CERT_PASS_SEC=ConvertTo-SecureString -AsPlainText -Force $CERT_PASS
1930
$cred = $admin_creds
2031
#Connect-AzureRmAccount
@@ -29,41 +40,52 @@ if(!$resourceGroup)
2940
$LOCATION = Read-Host "resourceGroupLocation";
3041
}
3142
Write-Host "Creating resource group '$RESOURCE_GROUP' in location '$LOCATION'";
32-
New-AzureRmResourceGroup -Name $RESOURCE_GROUP -Location $LOCATION
43+
New-AzureRmResourceGroup -Name $RESOURCE_GROUP -Location $LOCATION | Out-Null;
3344
}
3445
else{
3546
Write-Host "Using existing resource group '$RESOURCE_GROUP'";
3647
}
3748

38-
Write-Host "Creating key vault to store remote powershell certificate in"
39-
New-AzureRmKeyVault -VaultName $VAULT_NAME -ResourceGroupName $RESOURCE_GROUP -Location $LOCATION -EnabledForDeployment -EnabledForTemplateDeployment | Out-Null
40-
$vault = Get-AzureRmKeyVault -VaultName $VAULT_NAME
49+
50+
$vault = Get-AzureRmKeyVault -VaultName $VAULT_NAME -ErrorAction SilentlyContinue
51+
if (! $vault){
52+
Write-Host "Creating key vault to store remote powershell certificate in"
53+
New-AzureRmKeyVault -VaultName $VAULT_NAME -ResourceGroupName $RESOURCE_GROUP -Location $LOCATION -EnabledForDeployment -EnabledForTemplateDeployment | Out-Null
54+
$vault = Get-AzureRmKeyVault -VaultName $VAULT_NAME
55+
}else{
56+
Write-Host "Vault already exists not re-creating"
57+
}
4158
$certificateName = "CEFRemoteCert"
42-
Write-Host "Creating remote PS certificate"
43-
$thumbprint = (New-SelfSignedCertificate -DnsName $certificateName -CertStoreLocation Cert:\CurrentUser\My -KeySpec KeyExchange).Thumbprint
44-
$cert = (Get-ChildItem -Path cert:\CurrentUser\My\$thumbprint)
45-
$fileName = ".\$certificateName.pfx"
59+
$secretURL = (Get-AzureKeyVaultSecret -VaultName $VAULT_NAME -Name $SECRET_NAME -ErrorAction SilentlyContinue)
60+
if (! $secretURL){
61+
Write-Host "Creating remote PS certificate"
62+
$thumbprint = (New-SelfSignedCertificate -DnsName $certificateName -CertStoreLocation Cert:\CurrentUser\My -KeySpec KeyExchange).Thumbprint
63+
$cert = (Get-ChildItem -Path cert:\CurrentUser\My\$thumbprint)
64+
$fileName = ".\$certificateName.pfx"
4665

47-
Export-PfxCertificate -Cert $cert -FilePath $fileName -Password $CERT_PASS_SEC
48-
$fileContentBytes = Get-Content $fileName -Encoding Byte
49-
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
66+
Export-PfxCertificate -Cert $cert -FilePath $fileName -Password $CERT_PASS_SEC
67+
$fileContentBytes = Get-Content $fileName -Encoding Byte
68+
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
5069

51-
$jsonObject = @"
52-
{
53-
"data": "$filecontentencoded",
54-
"dataType" :"pfx",
55-
"password": "$CERT_PASS"
56-
}
70+
$jsonObject = @"
71+
{
72+
"data": "$filecontentencoded",
73+
"dataType" :"pfx",
74+
"password": "$CERT_PASS"
75+
}
5776
"@
5877

59-
$jsonObjectBytes = [System.Text.Encoding]::UTF8.GetBytes($jsonObject)
60-
$jsonEncoded = [System.Convert]::ToBase64String($jsonObjectBytes)
61-
62-
$secret = ConvertTo-SecureString -String $jsonEncoded -AsPlainText -Force
63-
Write-Host "Going to store certificate in vault"
64-
Set-AzureKeyVaultSecret -VaultName $VAULT_NAME -Name $SECRET_NAME -SecretValue $secret | Out-Null
65-
$secretURL = (Get-AzureKeyVaultSecret -VaultName $VAULT_NAME -Name $SECRET_NAME).Id
78+
$jsonObjectBytes = [System.Text.Encoding]::UTF8.GetBytes($jsonObject)
79+
$jsonEncoded = [System.Convert]::ToBase64String($jsonObjectBytes)
6680

81+
$secret = ConvertTo-SecureString -String $jsonEncoded -AsPlainText -Force
82+
Write-Host "Going to store certificate in vault"
83+
Set-AzureKeyVaultSecret -VaultName $VAULT_NAME -Name $SECRET_NAME -SecretValue $secret | Out-Null
84+
$secretURL = (Get-AzureKeyVaultSecret -VaultName $VAULT_NAME -Name $SECRET_NAME).Id
85+
}else{
86+
Write-Host "Secure storage for cert already exists reusing"
87+
$secretURL = $secretURL.Id;
88+
}
6789

6890
$json = Get-Content 'AzureTemplateParams.json' | Out-String | ConvertFrom-Json
6991

@@ -101,7 +123,11 @@ if($resourceProviders.length) {
101123

102124
# Start the deployment
103125
Write-Host "Starting deployment...";
104-
New-AzureRmResourceGroupDeployment -ResourceGroupName $RESOURCE_GROUP -TemplateParameterObject $hashtable -TemplateFile 'AzureTemplateFile.json';
126+
New-AzureRmResourceGroupDeployment -ResourceGroupName $RESOURCE_GROUP -TemplateParameterObject $hashtable -TemplateFile 'AzureTemplateFile.json' | Out-Null;
105127
$vm = Get-AzureRmVM -Name "CefTestVM" -ResourceGroupName $RESOURCE_GROUP
106128
$ip =Get-AzureRmPublicIpAddress -Name "CefTestVM-ip" -ResourceGroupName $RESOURCE_GROUP
107-
Write-Host "Public IP: " $ip.IpAddress
129+
Write-Host "Public IP: " $ip.IpAddress
130+
131+
}catch{
132+
WriteException $_;
133+
}

0 commit comments

Comments
 (0)