-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.go
105 lines (93 loc) · 2.47 KB
/
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
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
99
100
101
102
103
104
105
package main
import (
"log"
"os"
"path/filepath"
"github.com/pkg/errors"
)
func deploy() error {
for _, server := range servers {
log.Printf("uploading artifacts server=%s arch=%s\n",
server.name, server.arch)
err := runcmd("rsync",
"--archive",
"--progress",
"--filter", "+ *"+server.arch+".tar.xz",
"--filter", "- *",
"--checksum",
"--delete",
artifactDir()+"/",
server.user+"@"+server.name+":/opt/artifacts/",
)
if err != nil {
return errors.Wrapf(err, "failed to upload artifacts server=%s", server.name)
}
etcDir := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "badgerodon", "infrastructure", "prod", "etc")
log.Printf("updating config server=%s arch=%s\n",
server.name, server.arch)
err = runcmd("rsync",
"--archive",
"--progress",
"--checksum",
etcDir+"/",
server.user+"@"+server.name+":/etc/",
)
if err != nil {
return errors.Wrapf(err, "failed to upload config server=%s", server)
}
scriptDir := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "badgerodon", "infrastructure", "scripts")
log.Printf("uploading scripts server=%s arch=%s\n",
server.name, server.arch)
err = runcmd("rsync",
"--archive",
"--progress",
"--checksum",
scriptDir+"/",
server.user+"@"+server.name+":/tmp/",
)
if err != nil {
return errors.Wrapf(err, "failed to upload scripts server=%s", server)
}
for _, appName := range server.applications {
app := applications[appName]
log.Printf("installing server=%s arch=%s app=%s\n",
server.name, server.arch, app.name)
err = runcmd("ssh",
server.user+"@"+server.name,
"chmod +x /tmp/install-app.bash && env "+
"APP="+app.name+" "+
"VERSION="+app.version+" "+
"ARCH="+server.arch+" "+
"/tmp/install-app.bash",
)
if err != nil {
return errors.Wrapf(err, "failed to install server=%s arch=%s app=%s",
server.name, server.arch, app.name)
}
}
}
return nil
}
/*
# CONFIG
echo -e "[DEPLOY] updating config $COL_GREY"
rsync \
--archive \
--progress \
--recursive \
--checksum \
./prod/etc/ \
[email protected]:/etc/
ssh [email protected] "systemctl daemon-reload"
echo -e "$COL_RESET"
# SCRIPTS
echo -e "[DEPLOY] installing $COL_GREY"
rsync \
--archive \
--progress \
--checksum \
./scripts/ \
[email protected]:/tmp
ssh [email protected] "chmod +x /tmp/install-app.bash && env APP=caddy ARCH=arm64 /tmp/install-app.bash"
echo -e "$COL_RESET"
*/