-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
109 lines (94 loc) · 3.08 KB
/
deploy.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#set up constants
$dirDepth = 4
$containerName = "public"
$baseStorageUri = 'https://%storageAccountName%.blob.core.windows.net/'+$containerName
$ttl = 3600
$defaultDoc = "index.html"
$staticFilePath = D:\home\site\repository\staticFiles
# automatically generate the proxies.json file
$rootFileList = Get-ChildItem -File $staticFilePath
$extList = Get-ChildItem -File -Recurse $staticFilePath | Select-Object Extension | Sort-Object Extension | Get-Unique -asString
$objProxiesJson = @{}
$proxiesList = @{}
# default root document
$proxiesList."defaultRoot" = @{
matchCondition = @{
route = "/"
}
backendUri = "$baseStorageUri/$defaultDoc"
}
# iterate thru the root filenames
foreach ($file in $rootFileList.Name.Where{$_ -ne '.keep'}) {
$proxiesList."root$file" = @{
matchCondition = @{
route = "/$file"
}
backendUri = "$baseStorageUri/$file"
}
}
# iterate thru directory depth and add file types
For ($i=1; $i -le $dirDepth; $i++)
{
$path = ""
For ($d=1; $d -le $i; $d++){
$path += "/{level$d}"
}
$path += "/"
# default document for each level
$proxiesList."defaultLevel$i" = @{
matchCondition = @{
route = "$path"
}
backendUri = "$baseStorageUri$path$defaultDoc"
}
# and the rest of the document types
foreach ($ext in $extList.Extension.Where{$_ -ne '.keep'}) {
$proxiesList."level$i$ext" = @{
matchCondition = @{
route = "$path{name}$ext"
}
backendUri = "$baseStorageUri$path{name}$ext"
}
}
}
$objProxiesJson = @{
'$schema' = "http://json.schemastore.org/proxies"
proxies = $proxiesList
}
convertto-json -InputObject $objProxiesJson -Depth 5| Out-File d:\home\site\wwwroot\proxies.json
#copy the host.json, proxies.json and keepalive function into the right locations
Copy-Item functionSrc\* -Force -Destination d:\home\site\wwwroot -Recurse
# Connection string associated with the blob storage.
$blobStorage = $env:AzureWebJobsStorage
# Then we extract the name and key below
$accountKey = ""
$accountName = ""
$array = $blobStorage.Split(';')
foreach($element in $array)
{
if($element.Contains('AccountName')) {
$accountName = $element.Replace("AccountName=", "")
}
if($element.Contains('AccountKey')) {
$accountKey = $element.Replace("AccountKey=", "")
}
}
# Use AzCopy to deploy blob storage as long as we have an Account Key for the storage account
if($accountKey -ne "")
{
.\tools\AzCopy\AzCopy.exe /Source:$staticFilePath /Dest:https://$accountName.blob.core.windows.net/public /DestKey:$accountKey /SetContentType /S /Y
$ProgressPreference="SilentlyContinue"
$StorageContext = New-AzureStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
Set-AzureStorageContainerAcl -Context $StorageContext -Container "public" -Permission Blob
#set TTL
$blobs = Get-AzureStorageBlob -Container "public" -Context $StorageContext
foreach ($blob in $blobs)
{
$blob.ICloudBlob.Properties.CacheControl = "max-age=$ttl"
$blob.ICloudBlob.SetProperties()
}
}
else
{
Write-Host "Unable to find Storage Account Key"
}