forked from solo-io/gloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_images.go
104 lines (92 loc) · 2.42 KB
/
build_images.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
100
101
102
103
104
package helpers
import (
"fmt"
"hash/crc32"
"os"
"os/exec"
"path/filepath"
"github.com/onsi/ginkgo"
"github.com/solo-io/gloo/pkg/log"
)
var imageTagStatic = ""
func ImageTag() string {
if imageTagStatic != "" {
return imageTagStatic
}
tag := os.Getenv("TEST_IMAGE_TAG")
if tag == "" {
if host, err := os.Hostname(); err == nil {
tag = hash(host)
} else {
tag = RandString(4)
}
}
imageTagStatic = "testing-" + tag
return imageTagStatic
}
func hash(h string) string {
crc32q := crc32.MakeTable(0xD5828281)
return fmt.Sprintf("%08x", crc32.Checksum([]byte(h), crc32q))
}
// builds and pushes all docker containers needed for test
func BuildPushContainers(push, debug bool) error {
if os.Getenv("SKIP_BUILD") == "1" {
return nil
}
imageTag := ImageTag()
os.Setenv("IMAGE_TAG", imageTag)
// make the gloo containers
for _, component := range []string{"control-plane", "function-discovery", "kube-ingress-controller", "upstream-discovery"} {
arg := component
arg += "-docker"
if push {
arg += "-push"
}
if debug {
arg += "-debug"
}
cmd := exec.Command("make", arg)
cmd.Dir = GlooSoloDirectory()
cmd.Stdout = ginkgo.GinkgoWriter
cmd.Stderr = ginkgo.GinkgoWriter
if err := cmd.Run(); err != nil {
return err
}
}
for _, path := range []string{
filepath.Join(GlooSoloDirectory(), "hack", "auditor"),
filepath.Join(KubeE2eDirectory(), "containers", "helloservice"),
filepath.Join(KubeE2eDirectory(), "containers", "testrunner"),
filepath.Join(KubeE2eDirectory(), "containers", "event-emitter"),
filepath.Join(KubeE2eDirectory(), "containers", "upstream-for-events"),
filepath.Join(KubeE2eDirectory(), "containers", "grpc-test-service"),
} {
dockerOrg := os.Getenv("DOCKER_ORG")
if dockerOrg == "" {
dockerOrg = "soloio"
}
fullImage := dockerOrg + "/" + filepath.Base(path) + ":" + ImageTag()
log.Debugf("TEST: building fullImage %v", fullImage)
cmd := exec.Command("make", "docker")
cmd.Dir = path
cmd.Stdout = ginkgo.GinkgoWriter
cmd.Stderr = ginkgo.GinkgoWriter
if err := cmd.Run(); err != nil {
return err
}
if push {
cmd = exec.Command("docker", "push", fullImage)
cmd.Stdout = ginkgo.GinkgoWriter
cmd.Stderr = ginkgo.GinkgoWriter
if err := cmd.Run(); err != nil {
return err
}
}
cmd = exec.Command("make", "clean")
cmd.Dir = path
cmd.Stdout = ginkgo.GinkgoWriter
cmd.Stderr = ginkgo.GinkgoWriter
cmd.Run()
}
return nil
}