-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (42 loc) · 1.17 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
package main
import (
"encoding/json"
"os"
task "github.com/jprelph/oci-build-task"
"github.com/sirupsen/logrus"
"github.com/u-root/u-root/pkg/termios"
)
func main() {
var req task.Request
err := json.NewDecoder(os.Stdin).Decode(&req)
failIf("read request", err)
wd, err := os.Getwd()
failIf("get root path", err)
// limit max columns; Concourse sets a super high value and buildctl happily
// fills the whole screen with whitespace
ws, err := termios.GetWinSize(os.Stdout.Fd())
if err == nil {
ws.Col = 100
err = termios.SetWinSize(os.Stdout.Fd(), ws)
if err != nil {
logrus.Warn("failed to set window size:", err)
}
}
buildkitd, err := task.SpawnBuildkitd()
failIf("start buildkitd", err)
res, err := task.Build(buildkitd, wd, req)
failIf("build", err)
err = buildkitd.Cleanup()
failIf("cleanup buildkitd", err)
responseFile, err := os.Create(req.ResponsePath)
failIf("open response path", err)
err = json.NewEncoder(responseFile).Encode(res)
failIf("write response", err)
err = responseFile.Close()
failIf("close response file", err)
}
func failIf(msg string, err error) {
if err != nil {
logrus.Fatalln("failed to", msg+":", err)
}
}