-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathdeploy.vsh
More file actions
executable file
·47 lines (38 loc) · 1.52 KB
/
Copy pathdeploy.vsh
File metadata and controls
executable file
·47 lines (38 loc) · 1.52 KB
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
#!/usr/bin/env -S v run
import os
import term
const server = 'gitly'
const remote_path = '/var/www/gitly'
const local_binary = 'gitly_linux'
// Shared SSH connection so the key passphrase is only asked once.
const control_path = os.join_path(os.temp_dir(), 'gitly_deploy_cm.sock')
const ssh_opts = '-o ControlMaster=auto -o ControlPath=${control_path} -o ControlPersist=5m'
fn main() {
if !os.exists(local_binary) {
eprintln(term.red('${local_binary} not found. Build it first with:'))
eprintln(' ~/code/v3/v -os linux -d use_openssl -cc clang -gc none -prealloc -cflags "-O2" -o ${local_binary} .')
exit(1)
}
// Open a single master connection up front (prompts for the passphrase once).
// Every rsync/ssh below reuses it via the control socket.
println('Opening shared SSH connection...')
exec_safe('ssh ${ssh_opts} -fN ${server}')
defer {
os.system('ssh ${ssh_opts} -O exit ${server} 2>/dev/null')
}
println('Step 1: Syncing binary, static/ and translations/...')
rsync := 'rsync -avz -e "ssh ${ssh_opts}"'
exec_safe('${rsync} ${local_binary} ${server}:${remote_path}/gitly')
exec_safe('${rsync} static/ ${server}:${remote_path}/static/')
exec_safe('${rsync} translations/ ${server}:${remote_path}/translations/')
println('\nStep 2: Restarting gitly...')
exec_safe('ssh ${ssh_opts} ${server} "sudo systemctl restart gitly"')
println(term.green('\nDeployment successful!'))
}
fn exec_safe(cmd string) {
println('>>> ${cmd}')
if os.system(cmd) != 0 {
eprintln(term.red('\n Error executing command.'))
exit(1)
}
}