-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_deploy.go
69 lines (58 loc) · 1.49 KB
/
cmd_deploy.go
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
// Copyright 2015 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
// deploy the latest version of the go-hep.org web site.
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)
const (
ssh = "/usr/bin/ssh"
server = "[email protected]"
service = "go-hep.service"
remoteDir = "/srv/go-hep.org"
)
func main() {
run("go", "generate")
run("go", "build", "-tags", "netgo", "-v", "-o", "go-hep-serve", ".")
run("hugo")
run("scp", "-r", "./public", server+":"+remoteDir+"/.")
srv := remote{server}
srv.run("systemctl", "stop", service)
run("scp", "./go-hep-serve", server+":"+remoteDir+"/.")
srv.run("setcap", "cap_net_bind_service=+ep", remoteDir+"/go-hep-serve")
srv.run("cd " + remoteDir + " && git pull")
srv.run("systemctl", "restart", service)
os.Remove("go-hep-serve")
}
func run(cmd string, args ...string) {
c := exec.Command(cmd, args...)
fmt.Printf("+ %s\n", strings.Join(c.Args, " "))
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
log.Fatal(err)
}
}
type remote struct {
server string
}
func (r *remote) run(cmd string, args ...string) {
rargs := []string{r.server, "--", cmd}
rargs = append(rargs, args...)
c := exec.Command(ssh, rargs...)
fmt.Printf("+ %s\n", strings.Join(c.Args, " "))
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
log.Fatal(err)
}
}