-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·56 lines (51 loc) · 1.24 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
package main
import (
"bytes"
"fmt"
"os"
"os/exec"
)
func wipeOutputDirectory() error {
dir, err := os.Open("/out")
if err != nil {
return err
}
defer dir.Close()
names, err := dir.Readdirnames(-1)
if err != nil {
return err
}
for _, name := range names {
err = os.RemoveAll("/out"+name)
if err != nil {
return err
}
}
return nil
}
func main() {
err := wipeOutputDirectory()
if err != nil {
fmt.Fprintf(os.Stderr, "Could not delete the contents of the output directory. Is it mounted read/write? %s\n", err.Error())
os.Exit(1)
}
env := os.Getenv("SANIC_ENV")
if env == "" {
fmt.Fprintf(os.Stderr, "SANIC_ENV was not set?\n")
os.Exit(1)
}
if _, err = os.Open("/in/overlays/"+env+"/kustomization.yaml"); err != nil {
fmt.Fprintf(os.Stderr, "Could not read the kustomization file for environment %s. Expected at deploy/in/overlays/%s/kustomization.yaml to exist.", env, env)
os.Exit(1)
}
cmd := exec.Command("/app/kustomize", "build", "/in/overlays/"+env, "--output", "/out")
out := bytes.Buffer{}
cmd.Stderr = &out
cmd.Stdout = &out
err = cmd.Run()
if err != nil {
fmt.Fprint(os.Stderr, out.String())
fmt.Fprintf(os.Stderr, "Could not run templater for environment %s: %s\n", env, err.Error())
os.Exit(1)
}
}