-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.52 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
57
58
59
// Package main is a binary for creating a test ClickHouse container.
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"github.com/DIMO-Network/model-garage/pkg/clickhouseinfra"
"github.com/DIMO-Network/model-garage/pkg/migrations"
)
func main() {
err := run(context.Background())
if err != nil {
log.Fatal(err)
}
}
func run(ctx context.Context) error {
// Create flags for clickhouse user, password, and port
user := flag.String("user", "default", "ClickHouse user")
password := flag.String("password", "default", "ClickHouse password")
migrate := flag.Bool("migrate", true, "Run migrations")
flag.Parse()
chcontainer, err := clickhouseinfra.CreateClickHouseContainer(ctx, *user, *password)
if err != nil {
return fmt.Errorf("failed to create clickhouse container: %w", err)
}
defer chcontainer.Terminate(ctx)
if *migrate {
db, err := chcontainer.GetClickhouseAsDB(ctx)
if err != nil {
return fmt.Errorf("failed to get clickhouse db: %w", err)
}
if err := migrations.RunGoose(ctx, []string{"up", "-v"}, db); err != nil {
return fmt.Errorf("failed to run migration: %w", err)
}
}
host, err := chcontainer.ClickHouseContainer.ConnectionString(ctx)
if err != nil {
return fmt.Errorf("failed to get clickhouse host: %w", err)
}
fmt.Printf("ClickHouse container is running at: %s\n", host)
fmt.Println("Waiting for ctrl+c")
// wait for exit signal to terminate the containers
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
fmt.Println(" Cya Later!")
return nil
}