-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (54 loc) · 1.54 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
package main
import (
"encoding/json"
"github.com/gclawes/oci-injector-hook/internal/config"
"github.com/gclawes/oci-injector-hook/internal/runtime"
specs "github.com/opencontainers/runtime-spec/specs-go"
log "github.com/sirupsen/logrus"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
"io/ioutil"
"log/syslog"
"os"
"path/filepath"
)
func init() {
debug, ok := os.LookupEnv("DEBUG")
if ok && debug == "true" {
log.SetLevel(log.DebugLevel)
}
hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
if err != nil {
log.Fatal("Unable to connect to local syslog daemon")
} else {
log.AddHook(hook)
}
}
func main() {
state, err := config.GetState(os.Stdin)
if err != nil {
log.Fatal(err)
}
log.Debugf("state=%+v", state)
configs := config.GetConfigs()
for _, config := range configs {
configJson, err := ioutil.ReadFile(filepath.Join(state.Bundle, "config.json"))
if err != nil {
log.Fatal(err)
}
var containerConfig specs.Spec
err = json.Unmarshal(configJson, &containerConfig)
if err != nil {
log.Fatal(err)
}
log.Debug("containerConfig.Process.Env=%s", containerConfig.Process.Env)
if config.ActivationFlagPresent(containerConfig.Process.Env) {
runtime.SetupDevices(config, &containerConfig)
runtime.CreateDirectories(config, &containerConfig)
runtime.CopyBinaries(config, &containerConfig)
runtime.CopyLibraries(config, &containerConfig)
runtime.CopyMisc(config, &containerConfig)
} else {
log.Infof("activation flag %s not present!", config.ActivationFlag)
}
}
}