| 1 | #!/usr/bin/env -S v run |
| 2 | |
| 3 | import os |
| 4 | import term |
| 5 | |
| 6 | const server = 'gitly' |
| 7 | const remote_path = '/var/www/gitly' |
| 8 | const local_binary = 'gitly_linux' |
| 9 | |
| 10 | fn main() { |
| 11 | if !os.exists(local_binary) { |
| 12 | eprintln(term.red('${local_binary} not found. Build it first with:')) |
| 13 | eprintln(' ~/code/v3/v -os linux -d use_openssl -cc clang -gc none -prealloc -cflags "-O2" -o ${local_binary} .') |
| 14 | exit(1) |
| 15 | } |
| 16 | |
| 17 | println('Step 1: Syncing binary, static/ and translations/...') |
| 18 | rsync := 'rsync -avz' |
| 19 | exec_safe('${rsync} ${local_binary} ${server}:${remote_path}/gitly') |
| 20 | exec_safe('${rsync} static/ ${server}:${remote_path}/static/') |
| 21 | exec_safe('${rsync} translations/ ${server}:${remote_path}/translations/') |
| 22 | |
| 23 | println('\nStep 2: Restarting gitly...') |
| 24 | exec_safe('ssh ${server} "sudo systemctl restart gitly"') |
| 25 | |
| 26 | println(term.green('\nDeployment successful!')) |
| 27 | } |
| 28 | |
| 29 | fn exec_safe(cmd string) { |
| 30 | println('>>> ${cmd}') |
| 31 | if os.system(cmd) != 0 { |
| 32 | eprintln(term.red('\n Error executing command.')) |
| 33 | exit(1) |
| 34 | } |
| 35 | } |
| 36 | |