-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.ps1
80 lines (63 loc) · 1.51 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
$env:GOOS = 'linux'
$env:GOARCH = 'amd64'
$target = 'peltoloc'
$bin = 'linux_amd64'
$bint = 'vellamo'
$bintdev = 'vellamo_dev'
$confdir = 'config'
$confdev = 'config.dev.json'
$binp = ".\out\$bin"
$confp = ".\$confdir\$conf"
$confpdev = "$confdir/$confdev"
$tgtp = "/opt/vellamo"
$bintgp = "$tgtp/$bint"
$bintgpdev = "$tgtp/$bintdev"
# Wrapper to debug print / actually execute commands
# function Exec {
# $ArgsJ = $Args -Join ' '
# Write-Output $ArgsJ
# }
function Exec {
$ArgsJ = $Args -Join ' '
Invoke-Expression $ArgsJ
}
# Determine if dev mode
$devMode = $false
if ($Args.Count -gt 0) {
$devMode = $Args[0].ToLower() -eq "dev"
}
if ($devMode) {
go build -ldflags="-X 'main.DEBUGS=true' -X 'main.CONFIGS=${confpdev}'" -o $binp .
} else {
go build -o $binp .
}
if ($LastExitCode -ne 0) {
Write-Output "ERROR: Build failed."
exit $LastExitCode
}
Exec scp -r .\$confdir ${target}:"$tgtp/$confdir"
if ($LastExitCode -ne 0) {
Write-Output "ERROR: Failed to copy configs over SCP."
exit $LastExitCode
}
if ($devMode) {
Exec scp $binp ${target}:"$bintgpdev"
} else {
Exec scp $binp ${target}:"$bintgp"
}
if ($LastExitCode -ne 0) {
Write-Output "ERROR: Failed to copy binary over SCP."
exit $LastExitCode
}
if ($devMode) {
Exec ssh ${target} -C "chmod 0750 $bintgpdev"
} else {
Exec ssh ${target} -C "chmod 0750 $bintgp"
}
if ($LastExitCode -ne 0) {
Write-Output "ERROR: Failed to chmod binary."
exit $LastExitCode
}
# Execute on remote
# UPDATE: (RE)LAUNCHED BY INOTIFYWAIT SCRIPT
#Exec ssh ${target} -tC "$bintgp"