-
Notifications
You must be signed in to change notification settings - Fork 0
/
artemide.go
99 lines (83 loc) · 2.76 KB
/
artemide.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
package main
import (
"os"
"strconv"
evbus "github.com/asaskevich/EventBus"
. "github.com/mattn/go-getopt"
log "github.com/spf13/jwalterweatherman"
config "github.com/mudler/artemide/pkg/config"
"github.com/mudler/artemide/pkg/context"
plugin "github.com/mudler/artemide/plugin"
_ "github.com/mudler/artemide/plugin/recipe/docker"
_ "github.com/mudler/artemide/plugin/recipe/script"
)
func main() {
if os.Getenv("DEBUG") == strconv.Itoa(1) {
log.SetStdoutThreshold(log.LevelDebug)
} else {
log.SetStdoutThreshold(log.LevelInfo)
}
log.INFO.Println("== Artemide - the docker building system ==")
log.INFO.Println("Engines starting")
var c int
var configurationFile string
var unpackImage string
var context *context.Context
var outputDir string
bus := evbus.New()
OptErr = 0
for {
if c = Getopt("o:u:c:h"); c == EOF {
break
}
switch c {
case 'u':
unpackImage = OptArg
case 'o':
outputDir = OptArg
case 'c':
configurationFile = OptArg
case 'h':
println("usage: " + os.Args[0] + " [-c config.toml -h]")
println("to just extract a docker image: " + os.Args[0] + " -u docker/image -o /my/uncompressed_rootfs")
os.Exit(1)
}
}
// Register hooks and recipes to the eventbus
for i := range plugin.Hooks {
log.DEBUG.Println("Registering", i, "hook to eventbus")
plugin.Hooks[i].Register(bus, context)
}
for i := range plugin.Recipes {
log.DEBUG.Println("Registering", i, "recipe to eventbus")
plugin.Recipes[i].Register(bus, context)
}
// Starting the bus show!
bus.Publish("artemide:start") // Emitting artemide:start event thru Recipes and Hooks.
// unpack mode.
if unpackImage != "" && outputDir != "" {
// Unpack mode, just unpack the image and exits.
log.INFO.Println("Unpack mode. Unpacking", unpackImage, "to", outputDir)
bus.Publish("artemide:source:docker", unpackImage, outputDir)
os.Exit(0)
}
// Halting if no configuration file is supplied
if configurationFile == "" {
log.ERROR.Fatalln("I can't work without a configuration file")
}
configuration, _ := config.LoadConfig(configurationFile)
log.DEBUG.Printf("%v\n", configuration)
//bus.Publish("artemide:source:"+configuration.Source.Type, configuration.Source.Image)
for artifactName, artifact := range configuration.Artifacts {
log.DEBUG.Printf("Artifact: %s \n", artifactName)
for recipeName, recipe := range artifact.Recipe {
log.DEBUG.Printf("Signaling -> Recipe %s <- to bus\n", recipeName)
bus.Publish("artemide:artifact:recipe:" + recipeName)
for eventsName, event := range recipe {
log.DEBUG.Printf("Signaling -> Event %s : (%s.%s)\n", eventsName, event.Name, event.Action)
//bus.Publish("artemide:artifact:recipe:"+recipeName+":event:"+event.Name, event.Action)
}
}
}
//bus.Publish("artemide:recipe:type", recipe_type)
}