-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
47 lines (39 loc) · 1.15 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
// Package dinit provides a simple mechanism to prepare containers for action without
// a server listening to port 8080. This enables Direktiv to use standard containers from
// e.g. DockerHub.
package dinit
import (
"io"
"io/fs"
"os"
)
// RunApplication runs if the Direktiv binary starts up as `init`. This happens when a action
// uses the special command `/usr/share/direktiv/direktiv-cmd` in the configuration. It copies
// the direktiv-cmd binary to a shared location of the function container and the container is
// able to use this as a server to execute commands.
func RunApplication() {
perm := 0o755
// copies the command server to the shared directory in kubernetes
err := os.MkdirAll("/usr/share/direktiv", fs.FileMode(perm))
if err != nil {
panic(err)
}
source, err := os.Open("/bin/direktiv-cmd")
if err != nil {
panic(err)
}
destination, err := os.Create("/usr/share/direktiv/direktiv-cmd")
if err != nil {
panic(err)
}
_, err = io.Copy(destination, source)
if err != nil {
panic(err)
}
err = os.Chmod("/usr/share/direktiv/direktiv-cmd", fs.FileMode(perm))
if err != nil {
panic(err)
}
destination.Close()
source.Close()
}