github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/integration/e2e/db/db.go (about) 1 package e2edb 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 8 "github.com/cortexproject/cortex/integration/e2e" 9 "github.com/cortexproject/cortex/integration/e2e/images" 10 ) 11 12 const ( 13 MinioAccessKey = "Cheescake" 14 MinioSecretKey = "supersecret" 15 ) 16 17 // NewMinio returns minio server, used as a local replacement for S3. 18 func NewMinio(port int, bktNames ...string) *e2e.HTTPService { 19 return newMinio(port, map[string]string{}, bktNames...) 20 } 21 22 // NewMinioWithKES returns minio server, configured to talk to a KES service. 23 func NewMinioWithKES(port int, kesEndpoint, rootKeyFile, rootCertFile, caCertFile string, bktNames ...string) *e2e.HTTPService { 24 kesEnvVars := map[string]string{ 25 "MINIO_KMS_KES_ENDPOINT": kesEndpoint, 26 "MINIO_KMS_KES_KEY_FILE": filepath.Join(e2e.ContainerSharedDir, rootKeyFile), 27 "MINIO_KMS_KES_CERT_FILE": filepath.Join(e2e.ContainerSharedDir, rootCertFile), 28 "MINIO_KMS_KES_CAPATH": filepath.Join(e2e.ContainerSharedDir, caCertFile), 29 "MINIO_KMS_KES_KEY_NAME": "my-minio-key", 30 } 31 return newMinio(port, kesEnvVars, bktNames...) 32 } 33 34 func newMinio(port int, envVars map[string]string, bktNames ...string) *e2e.HTTPService { 35 commands := []string{} 36 for _, bkt := range bktNames { 37 commands = append(commands, fmt.Sprintf("mkdir -p /data/%s", bkt)) 38 } 39 commands = append(commands, fmt.Sprintf("minio server --address :%v --quiet /data", port)) 40 41 m := e2e.NewHTTPService( 42 fmt.Sprintf("minio-%v", port), 43 images.Minio, 44 // Create the "cortex" bucket before starting minio 45 e2e.NewCommandWithoutEntrypoint("sh", "-c", strings.Join(commands, " && ")), 46 e2e.NewHTTPReadinessProbe(port, "/minio/health/ready", 200, 200), 47 port, 48 ) 49 envVars["MINIO_ACCESS_KEY"] = MinioAccessKey 50 envVars["MINIO_SECRET_KEY"] = MinioSecretKey 51 envVars["MINIO_BROWSER"] = "off" 52 envVars["ENABLE_HTTPS"] = "0" 53 m.SetEnvVars(envVars) 54 return m 55 } 56 57 // NewKES returns KES server, used as a local key management store 58 func NewKES(port int, serverKeyFile, serverCertFile, rootCertFile string) *e2e.HTTPService { 59 // Run this as a shell command, so sub-shell can evaluate 'identity' of root user. 60 command := fmt.Sprintf("/kes server --addr 0.0.0.0:%d --key=%s --cert=%s --root=$(/kes tool identity of %s) --auth=off --quiet", 61 port, filepath.Join(e2e.ContainerSharedDir, serverKeyFile), filepath.Join(e2e.ContainerSharedDir, serverCertFile), filepath.Join(e2e.ContainerSharedDir, rootCertFile)) 62 63 m := e2e.NewHTTPService( 64 "kes", 65 images.KES, 66 e2e.NewCommandWithoutEntrypoint("sh", "-c", command), 67 nil, // KES only supports https calls - TODO make Scenario able to call https or poll plain TCP socket. 68 port, 69 ) 70 return m 71 } 72 73 func NewConsul() *e2e.HTTPService { 74 return e2e.NewHTTPService( 75 "consul", 76 images.Consul, 77 // Run consul in "dev" mode so that the initial leader election is immediate 78 e2e.NewCommand("agent", "-server", "-client=0.0.0.0", "-dev", "-log-level=err"), 79 e2e.NewHTTPReadinessProbe(8500, "/v1/operator/autopilot/health", 200, 200, `"Healthy": true`), 80 8500, 81 ) 82 } 83 84 func NewETCD() *e2e.HTTPService { 85 return e2e.NewHTTPService( 86 "etcd", 87 images.ETCD, 88 e2e.NewCommand("/usr/local/bin/etcd", "--listen-client-urls=http://0.0.0.0:2379", "--advertise-client-urls=http://0.0.0.0:2379", "--listen-metrics-urls=http://0.0.0.0:9000", "--log-level=error"), 89 e2e.NewHTTPReadinessProbe(9000, "/health", 200, 204), 90 2379, 91 9000, // Metrics 92 ) 93 } 94 95 func NewDynamoDB() *e2e.HTTPService { 96 return e2e.NewHTTPService( 97 "dynamodb", 98 images.DynamoDB, 99 e2e.NewCommand("-jar", "DynamoDBLocal.jar", "-inMemory", "-sharedDb"), 100 // DynamoDB doesn't have a readiness probe, so we check if the / works even if returns 400 101 e2e.NewHTTPReadinessProbe(8000, "/", 400, 400), 102 8000, 103 ) 104 }