-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
98 lines (73 loc) · 2.82 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
$credentialPath = "credentials.json"
$dockerUsername = ""
$branch = ""
$loginStatus = docker login | findstr "Login Succeeded"
if ($loginStatus -ne "Login Succeeded") {
$branch = Read-Host "Enter the branch name"
}
if (Test-Path -Path $credentialPath) {
$credentials = Get-Content -Path $credentialPath -Raw | ConvertFrom-Json
if ($credentials.Branch) {
Write-Output "Deploying the app, please wait..."
caprover deploy -h "$($credentials.Host)" -p "$($credentials.Password)" --appName "$($credentials.AppName)" --branch "$($credentials.Branch)"
return;
}
Write-Output "Preparing the image..."
docker build -t $($credentials.ImgName) .
$buildStatus = $LASTEXITCODE;
if($buildStatus -ne 0) {
Write-Output "Failed to build the image"
return;
}
docker push $($credentials.ImgName)
Write-Output "Deploying the app, please wait..."
caprover deploy -h "$($credentials.Host)" -p "$($credentials.Password)" -i "$($credentials.ImgName)" --appName "$($credentials.AppName)"
}
else {
Write-Output "Preparing the image..."
if ($branch -ne "") {
$uri = Read-Host "Enter your caprover host"
$hashedPwd = Read-Host "Enter your caprover password" -AsSecureString
$appName = Read-Host "Enter your app name"
$plainPwd = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($hashedPwd)
)
caprover deploy -h "$uri" -p "$plainPwd" --appName "$appName" --branch "$branch"
$fileContents = @{
Host = $uri
Password = $plainPwd
AppName = $appName
Branch = $branch
}
$data = $fileContents | ConvertTo-Json -Depth 10
Set-Content -Path $credentialPath -Value $data -Encoding UTF8
return;
}
if ($loginStatus -eq "Login Succeeded") {
$dockerUsername = Read-Host "Enter your docker username"
}
$uri = Read-Host "Enter your caprover host"
$hashedPwd = Read-Host "Enter your caprover password" -AsSecureString
$appName = Read-Host "Enter your app name"
$imgName = Read-Host "Enter your docker image name (without docker username)"
docker build -t "$dockerUsername/$imgName" .
$buildStatus = $LASTEXITCODE;
if($buildStatus -ne 0) {
Write-Output "Failed to build the image"
return;
}
docker push "$dockerUsername/$imgName"
Write-Output "Deploying the app, please wait..."
$plainPwd = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($hashedPwd)
)
caprover deploy -h "$uri" -p "$plainPwd" -i "$dockerUsername/$imgName" --appName "$appName"
$fileContents = @{
Host = $uri
Password = $plainPwd
AppName = $appName
ImgName = "$dockerUsername/$imgName"
}
$data = $fileContents | ConvertTo-Json -Depth 10
Set-Content -Path $credentialPath -Value $data -Encoding UTF8
}