-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
74 lines (65 loc) · 2.01 KB
/
main.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 main
import (
"context"
_ "embed"
"fmt"
"github.com/gigurra/flycd/cmd/convert"
"github.com/gigurra/flycd/cmd/deploy"
"github.com/gigurra/flycd/cmd/install"
"github.com/gigurra/flycd/cmd/monitor"
"github.com/gigurra/flycd/cmd/repos"
"github.com/gigurra/flycd/pkg/domain"
"github.com/gigurra/flycd/pkg/ext/fly_client"
"github.com/spf13/cobra"
"os"
"os/exec"
)
const Version = "v0.0.47"
var rootCmd = &cobra.Command{
Use: "flycd",
Short: "flycd deployment of fly apps entirely from code, without manual fly.io cli commands... I hope :D",
Long: `Complete documentation is available at https://github.com/gigurra/flycd`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
err := cmd.Usage()
if err != nil {
fmt.Printf("error displaying usage: %v\n", err)
}
os.Exit(1) // Exit with code 1
}
},
}
func main() {
fmt.Printf("Starting FlyCD %s...\n", Version)
// Check that required applications are installed
// At some point we should just use a go library instead,
// and maybe even embed fly.io cli into our app :P
// (Alternatively we could integrate directly with fly.io API)
requiredApps := []string{"fly", "git", "ssh"}
for _, app := range requiredApps {
_, err := exec.LookPath(app)
if err != nil {
fmt.Printf("Error: required app '%s' not found in PATH\n", app)
os.Exit(1)
}
}
// Create di-ish separable components
appCtx := context.Background() // TODO: make cancellable later on signals
flyClient := fly_client.NewFlyClient()
deployService := domain.NewDeployService(flyClient)
webhookService := domain.NewWebHookService(deployService)
// prepare cli
rootCmd.AddCommand(
deploy.Cmd(appCtx, deployService),
monitor.Cmd(appCtx, flyClient, deployService, webhookService),
install.Cmd(appCtx, PackagedFileSystem, flyClient, deployService),
convert.Cmd(appCtx),
repos.Cmd(appCtx),
)
// run cli
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("FlyCD %s exiting normally, bye!\n", Version)
}