-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainers.go
More file actions
116 lines (103 loc) · 2.51 KB
/
Copy pathcontainers.go
File metadata and controls
116 lines (103 loc) · 2.51 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"log"
"net"
"os/exec"
)
func isPortAvailable(port int) bool {
address := fmt.Sprintf(":%d", port)
listener, err := net.Listen("tcp", address)
if err != nil {
return false
}
listener.Close()
return true
}
func findAvailablePort(startPort int) int {
for port := startPort; port <= 65535; port++ {
if isPortAvailable(port) {
return port
}
}
return -1 // No available port found
}
// startPostgres starts the postgres instance that orca needs.
func startPostgres(networkName string) {
exists := checkStartContainer(pgContainerName)
if !exists {
// create or start a volume
volumeName := checkCreateVolume(pgContainerName)
// run container with volume mounted
args := []string{
"run",
"-d",
"-p", "0:5432",
"--name",
pgContainerName,
"--network",
networkName,
"-e",
"POSTGRES_USER=orca",
"-e",
"POSTGRES_PASSWORD=orca",
"-e",
"POSTGRES_DB=orca",
"-v",
volumeName + ":/var/lib/postgresql",
"postgres",
}
runCmd := exec.Command("docker", args...)
// stream container creation logs
streamCommandOutput(runCmd, "PostgreSQL Store:")
}
}
func startRedis(networkName string) {
exists := checkStartContainer(redisContainerName)
if !exists {
// create or start a volume
volumeName := checkCreateVolume(redisContainerName)
// run container with volume mounted
args := []string{
"run",
"--name", redisContainerName,
"--network", networkName,
"-p", "0:6379",
"-d",
"-v", volumeName + ":/data",
"redis",
"redis-server", "--appendonly", "yes",
}
runCmd := exec.Command("docker", args...)
// stream container creation logs
streamCommandOutput(runCmd, "Redis Cache:")
}
}
func startOrca(networkName string) {
exists := checkStartContainer(orcaContainerName)
if !exists {
preferredPort := 33670
availablePort := findAvailablePort(preferredPort)
if availablePort == -1 {
log.Fatal("No available ports found")
}
portMapping := fmt.Sprintf("%d:3335", availablePort)
args := []string{
"run",
"-d",
"--name",
orcaContainerName,
"--network",
networkName,
"--add-host", "host.docker.internal:host-gateway",
"-p", portMapping,
"-e", fmt.Sprintf("ORCA_CONNECTION_STRING=postgresql://orca:orca@%s:5432/orca?sslmode=disable", pgContainerName),
"-e", "ORCA_PORT=3335",
"-e", "ORCA_LOG_LEVEL=DEBUG",
fmt.Sprintf("ghcr.io/orca-telemetry/core:%v", orcaImageVersion),
"-migrate",
}
runCmd := exec.Command("docker", args...)
streamCommandOutput(runCmd, "Orca-Core:")
}
}