forked from dillonhafer/budgetal-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.go
74 lines (55 loc) · 2.28 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
package grifts
import (
"fmt"
"time"
"github.com/fatih/color"
"github.com/gobuffalo/envy"
"github.com/markbates/grift/grift"
)
var deployEnv = envy.Get("to", "production")
var envFile = fmt.Sprintf(".env.%s", deployEnv)
var _ = envy.Load(envFile)
var server = envy.Get("server", "")
var deployDir = envy.Get("deploy_dir", "")
var localAvatars = envy.Get("LOCAL_AVATARS", "no") == "yes"
func timeTrack(s time.Time) {
start := s.Round(time.Second)
end := time.Now().Round(time.Second)
elapsed := end.Sub(start)
FormatLog(color.BlueString(fmt.Sprintf("✨ Done in %s", elapsed)))
}
var _ = grift.Desc("release", "Build/Deploy the backend")
var _ = grift.Set("release", func(c *grift.Context) error {
defer timeTrack(time.Now())
fmt.Println("Starting full deploy as", server)
Comment("Compiling new binary")
QuietCommand("buffalo", "bill", "--ldflags=-s -w", "-o", "bin/budgetal")
FormatLog("Built bin/budgetal")
Comment("Clean heroku dir")
Command("rm", "-rf", "budgetal-production")
Comment("Get latest heroku deploy")
Command("heroku", "git:clone", "-a", "budgetal-production")
Comment("Copy latest bin to git repo")
Command("cp", "bin/budgetal", "budgetal-production/bin/budgetal")
Comment("Commit new version")
QuietCommandInDir("budgetal-production", "git", "add", ".")
QuietCommandInDir("budgetal-production", "git", "commit", "-m", "New version")
QuietCommandInDir("budgetal-production", "git", "checkout", "--orphan", "new-version")
// Add all files and commit them
QuietCommandInDir("budgetal-production", "git", "add", "-A")
QuietCommandInDir("budgetal-production", "git", "commit", "-m", "New version")
// Deletes the master branch
QuietCommandInDir("budgetal-production", "git", "branch", "-D", "master")
// Rename the current branch to master
QuietCommandInDir("budgetal-production", "git", "branch", "-m", "master")
// Remove the old files
QuietCommandInDir("budgetal-production", "git", "gc", "--aggressive", "--prune=all")
// Force push master branch to heroku
Comment("Push to heroku")
QuietCommandInDir("budgetal-production", "git", "push", "-f", "heroku", "master")
Comment("Run migrations")
QuietCommandInDir("budgetal-production", "heroku", "run", "'bin/./budgetal migrate'")
Comment("Cleaning up")
Command("rm", "-rf", "budgetal-production")
return nil
})