forked from NuGet/NuGetGallery
/
Package.ps1
159 lines (138 loc) · 7.34 KB
/
Package.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
param(
$azureStorageAccessKey = $env:NUGET_GALLERY_AZURE_STORAGE_ACCESS_KEY,
$azureStorageAccountName = $env:NUGET_GALLERY_AZURE_STORAGE_ACCOUNT_NAME,
$azureStorageBlobUrl = $env:NUGET_GALLERY_AZURE_STORAGE_BLOB_URL,
$remoteDesktopAccountExpiration = $env:NUGET_GALLERY_REMOTE_DESKTOP_ACCOUNT_EXPIRATION,
$remoteDesktopCertificateThumbprint = $env:NUGET_GALLERY_REMOTE_DESKTOP_CERTIFICATE_THUMBPRINT,
$remoteDesktopEnctyptedPassword = $env:NUGET_GALLERY_REMOTE_DESKTOP_ENCRYPTED_PASSWORD,
$remoteDesktopUsername = $env:NUGET_GALLERY_REMOTE_DESKTOP_USERNAME,
$sqlAzureConnectionString = $env:NUGET_GALLERY_SQL_AZURE_CONNECTION_STRING,
$sslCertificateThumbprint = $env:NUGET_GALLERY_SSL_CERTIFICATE_THUMBPRINT,
$validationKey = $env:NUGET_GALLERY_VALIDATION_KEY,
$decryptionKey = $env:NUGET_GALLERY_DECRYPTION_KEY,
$commitSha,
$commitBranch
)
#Import Common Stuff
$ScriptRoot = (Split-Path -parent $MyInvocation.MyCommand.Definition)
. $ScriptRoot\_Common.ps1
#Validate Sutff
require-param -value $azureStorageAccessKey -paramName "azureStorageAccessKey"
require-param -value $azureStorageAccountName -paramName "azureStorageAccountName"
require-param -value $azureStorageBlobUrl -paramName "azureStorageBlobUrl"
require-param -value $remoteDesktopAccountExpiration -paramName "remoteDesktopAccountExpiration"
require-param -value $remoteDesktopCertificateThumbprint -paramName "remoteDesktopCertificateThumbprint"
require-param -value $remoteDesktopEnctyptedPassword -paramName "remoteDesktopEnctyptedPassword"
require-param -value $remoteDesktopUsername -paramName "remoteDesktopUsername"
require-param -value $sqlAzureConnectionString -paramName "sqlAzureConnectionString"
require-param -value $sslCertificateThumbprint -paramName "sslCertificateThumbprint"
#Helper Functions
function set-certificatethumbprint {
param($path, $name, $value)
$xml = [xml](get-content $path)
$certificate = $xml.serviceconfiguration.role.Certificates.Certificate | where { $_.name -eq $name }
$certificate.thumbprint = "$value"
$resolvedPath = resolve-path($path)
$xml.save($resolvedPath)
}
function set-configurationsetting {
param($path, $name, $value)
$xml = [xml](get-content $path)
$setting = $xml.serviceconfiguration.role.configurationsettings.setting | where { $_.name -eq $name }
$setting.value = "$value"
$resolvedPath = resolve-path($path)
$xml.save($resolvedPath)
}
function set-connectionstring {
param($path, $name, $value)
$settings = [xml](get-content $path)
$setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name }
$setting.connectionString = "$value"
$setting.providerName = "System.Data.SqlClient"
$resolvedPath = resolve-path($path)
$settings.save($resolvedPath)
}
function set-appsetting {
param($path, $name, $value)
$settings = [xml](get-content $path)
$setting = $settings.configuration.appSettings.selectsinglenode("add[@key='" + $name + "']")
$setting.value = $value.toString()
$resolvedPath = resolve-path($path)
$settings.save($resolvedPath)
}
function set-releasemode {
param($path)
$xml = [xml](get-content $path)
$compilation = $xml.configuration."system.web".compilation
$compilation.debug = "false"
$resolvedPath = resolve-path($path)
$xml.save($resolvedPath)
}
function set-machinekey {
param($path)
if($validationKey -AND $decryptionKey){
$xml = [xml](get-content $path)
$machinekey = $xml.CreateElement("machineKey")
$machinekey.setattribute("validation", "HMACSHA256")
$machinekey.setattribute("validationKey", $validationKey)
$machinekey.setattribute("decryption", "AES")
$machinekey.setattribute("decryptionKey", $decryptionKey)
$xml.configuration."system.web".AppendChild($machineKey)
$resolvedPath = resolve-path($path)
$xml.save($resolvedPath)
}
}
#Do Work Brah
$scriptPath = split-path $MyInvocation.MyCommand.Path
$rootPath = resolve-path(join-path $scriptPath "..")
$csdefFile = join-path $scriptPath "NuGetGallery.csdef"
$websitePath = join-path $rootPath "Website"
$webConfigPath = join-path $websitePath "Web.config"
$webConfigBakPath = join-path $scriptPath "Web.config.bak"
$rolePropertiesPath = join-path $scriptPath "NuGetGallery.RoleProperties.txt"
$cscfgPath = join-path $scriptPath "NuGetGallery.cscfg"
$cscfgBakPath = join-path $scriptPath "NuGetGallery.cscfg.bak"
$cspkgFolder = join-path $rootPath "_AzurePackage"
$cspkgFile = join-path $cspkgFolder "NuGetGallery.cspkg"
$gitPath = join-path (programfiles-dir) "Git\bin\git.exe"
$compressionCmdScriptsPath = join-path $scriptPath "EnableDynamicHttpCompression.cmd"
$binPath = join-path $websitePath "bin"
$compressionCmdBinPath = join-path $binPath "EnableDynamicHttpCompression.cmd"
if ($commitSha -eq $null) {
$commitSha = (& "$gitPath" rev-parse HEAD)
}
if ($commitBranch -eq $null) {
$commitBranch = (& "$gitPath" name-rev --name-only HEAD)
}
if ((test-path $cspkgFolder) -eq $false) {
mkdir $cspkgFolder | out-null
}
cp $webConfigPath $webConfigBakPath
cp $cscfgPath $cscfgBakPath
set-configurationsetting -path $cscfgPath -name "AzureStorageAccessKey" -value $azureStorageAccessKey
set-configurationsetting -path $cscfgPath -name "AzureStorageAccountName" -value $azureStorageAccountName
set-configurationsetting -path $cscfgPath -name "AzureStorageBlobUrl" -value $azureStorageBlobUrl
set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" -value $remoteDesktopAccountExpiration
set-certificatethumbprint -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" -value $remoteDesktopCertificateThumbprint
set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" -value $remoteDesktopEnctyptedPassword
set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" -value $remoteDesktopUsername
set-connectionstring -path $webConfigPath -name "NuGetGallery" -value $sqlAzureConnectionString
set-certificatethumbprint -path $cscfgPath -name "nuget.org" -value $sslCertificateThumbprint
set-releasemode $webConfigPath
set-machinekey $webConfigPath
#Release Tag stuff
print-message("Setting the release tags")
set-appsetting -path $webConfigPath -name "Gallery:ReleaseName" -value "NuGet 1.6 'Hershey'"
set-appsetting -path $webConfigPath -name "Gallery:ReleaseTime" -value (Get-Date -format "dd/MM/yyyy HH:mm:ss")
set-appsetting -path $webConfigPath -name "Gallery:ReleaseSha" -value $commitSha
set-appsetting -path $webConfigPath -name "Gallery:ReleaseBranch" -value $commitBranch
cp $compressionCmdScriptsPath $compressionCmdBinPath
& 'C:\Program Files\Windows Azure SDK\v1.6\bin\cspack.exe' "$csdefFile" /out:"$cspkgFile" /role:"Website;$websitePath" /sites:"Website;Web;$websitePath" /rolePropertiesFile:"Website;$rolePropertiesPath"
if ($lastexitcode -ne 0) { exit 1 }
cp $cscfgPath $cspkgFolder
cp $webConfigBakPath $webConfigPath
cp $cscfgBakPath $cscfgPath
rm $compressionCmdBinPath
print-success("Azure package and configuration dropped to $cspkgFolder.")
write-host ""
Exit 0