This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor.go
62 lines (56 loc) · 1.4 KB
/
executor.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
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func fullDeploy() {
command1 := fmt.Sprintf("docker-compose -f docker-compose.production.yml pull")
command2 := fmt.Sprintf("docker-compose -f docker-compose.production.yml down")
command3 := fmt.Sprintf("docker-compose -f docker-compose.production.yml up -d")
cmd := exec.Command("/bin/sh", "-c", command1, "&&", command2, "&&", command3)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Printf("Got error: %s\n", err.Error())
}
}
func halfDeploy() {
command1 := fmt.Sprintf("docker-compose -f docker-compose.production.yml pull")
command2 := fmt.Sprintf("docker-compose -f docker-compose.production.yml up -d")
cmd := exec.Command("/bin/sh", "-c", command1, "&&", command2)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Printf("Got error: %s\n", err.Error())
}
}
func executor(input string) {
input = strings.TrimSpace(input)
switch input {
case "":
return
case "quit":
os.Exit(0)
return
case "exit":
os.Exit(0)
return
case "full-deploy":
fullDeploy()
case "half-deploy":
halfDeploy()
default:
cmd := exec.Command("/bin/sh", "-c", input)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Printf("Got error: %s\n", err.Error())
}
}
return
}