-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdocker-pipeline.go
67 lines (53 loc) · 1.15 KB
/
docker-pipeline.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
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"github.com/docker/engine-api/client"
)
func main() {
pwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
var f = flag.String("file", "docker-pipeline.yml", "docker-pipeline yaml file")
var project = flag.String("project", filepath.Base(pwd), "name of current project")
flag.Parse()
source, err := ioutil.ReadFile(*f)
if err != nil {
log.Fatal(err)
}
stages, err := Parse(source)
if err != nil {
log.Fatal(err)
}
pipeline := Pipeline{stages, *project}
docker, err := client.NewEnvClient()
if err != nil {
log.Fatal(err)
}
action := flag.Arg(0)
if action == "" {
action = "run"
}
switch action {
case "run":
for _, s := range pipeline.Stages() {
err = runStage(docker, &s, &pipeline)
if err != nil {
log.Fatal(err)
}
}
default:
log.Fatal("Unsupported action " + action)
}
}
func runStage(docker *client.Client, s *Stage, p *Pipeline) error {
fmt.Printf("-----------------------------------------\n")
fmt.Printf(" Stage: %s\n", s.Name)
fmt.Printf("-----------------------------------------\n")
return s.Exec.Run(docker, p, s)
}