forked from OrchardCMS/Orchard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.ps1
107 lines (86 loc) · 3.21 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
#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-7
Set-StrictMode -Version Latest
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7#erroractionpreference
$ErrorActionPreference = "Stop"
Import-Module -Name .\DeploymentUtility
"Verify if Node.js installed"
if (-not (Get-Command -Name node -ErrorAction Ignore)) {
throw "Missing node.js executable, please install node.js." +
"If already installed, make sure it can be reached from the current Environment."
}
# Setup
$ARTIFACTS = "$PSScriptRoot\..\artifacts"
if (-not $Env:DEPLOYMENT_SOURCE) {
$Env:DEPLOYMENT_SOURCE = $PSScriptRoot
}
if (-not $Env:DEPLOYMENT_TARGET) {
$Env:DEPLOYMENT_TARGET = "$ARTIFACTS\wwwroot"
}
if (-not $Env:NEXT_MANIFEST_PATH) {
$Env:NEXT_MANIFEST_PATH = "$ARTIFACTS\manifest"
if (-not $Env:PREVIOUS_MANIFEST_PATH) {
$Env:PREVIOUS_MANIFEST_PATH = "$ARTIFACTS\manifest"
}
}
if (-not $Env:KUDU_SYNC_CMD) {
"Installing Kudu Sync"
Invoke-ExternalCommand -ScriptBlock { & npm install kudusync -g --silent }
# Locally just running "kuduSync" would also work
$Env:KUDU_SYNC_CMD = "$Env:AppData\npm\kuduSync.cmd"
}
# Log Environment variables
$EnvironmentNameToWriteValue = @(
"DEPLOYMENT_SOURCE"
"DEPLOYMENT_TARGET"
"NEXT_MANIFEST_PATH"
"PREVIOUS_MANIFEST_PATH"
"KUDU_SYNC_CMD"
"WEBSITE_NODE_DEFAULT_VERSION"
"SCM_REPOSITORY_PATH"
"Path"
"SOLUTION_PATH"
"PROJECT_PATH"
"MSBUILD_PATH"
)
Write-EnviromentValue -EnvironmentName $EnvironmentNameToWriteValue
"Current node version: $(& node --version)"
"Current npm version: $(& npm --version)"
"Current MSBUILD version: $(& $Env:MSBUILD_PATH -version)"
###########################################################
# Deployment
###########################################################
"Handling .NET Web Application deployment."
"Restore NuGet packages"
"Current nuget version: $(nuget help | Select -First 1)"
Invoke-ExternalCommand -ScriptBlock {
& nuget restore "$Env:SOLUTION_PATH" -MSBuildPath "$(Split-Path -Path $Env:MSBUILD_PATH)"
}
"Build .NET project to the temp directory"
$preCompiledDir = "$Env:DEPLOYMENT_SOURCE\build\Precompiled"
"Building with MSBUILD to '$preCompiledDir'"
Invoke-ExternalCommand -ScriptBlock {
# https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019
& "$Env:MSBUILD_PATH" `
"$Env:PROJECT_PATH" `
/t:Precompiled `
/verbosity:minimal `
/maxcpucount `
/nologo `
$Env:SCM_BUILD_ARGS
# Set SCM_BUILD_ARGS App Services Apps Settings to string you want to append to the msbuild command line.
}
"Kudu syncing"
Invoke-ExternalCommand -ScriptBlock {
& "$Env:KUDU_SYNC_CMD" `
-v 50 `
-f "$preCompiledDir" `
-t "$Env:DEPLOYMENT_TARGET" `
-n "$Env:NEXT_MANIFEST_PATH" `
-p "$Env:PREVIOUS_MANIFEST_PATH" `
-i ".git;.hg;.deployment;deploy.cmd;deploy.ps1;node_modules;"
}
if ($Env:POST_DEPLOYMENT_ACTION) {
"Post deployment stub"
Invoke-ExternalCommand -ScriptBlock { & $Env:POST_DEPLOYMENT_ACTION }
}
"Deployment successfully"