Skip to content

Commit 92d2ab9

Browse files
committed
initial commit
1 parent 263e073 commit 92d2ab9

File tree

4 files changed

+707
-2
lines changed

4 files changed

+707
-2
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package chipingress
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"time"
8+
9+
"github.com/pkg/errors"
10+
"github.com/testcontainers/testcontainers-go"
11+
"github.com/testcontainers/testcontainers-go/modules/compose"
12+
)
13+
14+
type Output struct {
15+
InternalURL string
16+
ExternalURL string
17+
}
18+
19+
func New(ctx context.Context) (*Output, error) {
20+
composeFile := "./docker-compose.yml"
21+
stack, err := compose.NewDockerCompose([]string{composeFile},
22+
compose.WithStackName("chip_stack"),
23+
compose.WithEnv(map[string]string{
24+
// optional: override any env vars here
25+
// "SERVER_METRICS_OTEL_EXPORTER_GRPC_ENDPOINT": "otel-lgtm:4317",
26+
}),
27+
)
28+
if err != nil {
29+
return nil, errors.Wrap(err, "failed to create compose stack")
30+
}
31+
32+
// Add to existing Docker network
33+
stack = stack.WithAdditionalOptions(func(s *testcontainers.DockerCompose) {
34+
s.WithCustomNetwork("my_shared_net") // your existing network name
35+
})
36+
37+
fmt.Println("Bringing up stack...")
38+
if err := stack.Up(ctx, compose.Wait(true)); err != nil {
39+
log.Fatalf("Failed to start stack: %v", err)
40+
}
41+
defer func() {
42+
_ = stack.Down(ctx, compose.RemoveOrphans(true), compose.RemoveImagesLocal)
43+
}()
44+
45+
// Optional: wait for chip-ingress to become healthy
46+
time.Sleep(5 * time.Second)
47+
48+
// Retrieve internal and external ports
49+
ingress, err := stack.ServiceContainer(ctx, "chip-ingress")
50+
if err != nil {
51+
log.Fatalf("Failed to get chip-ingress container: %v", err)
52+
}
53+
54+
internalHost := "chip-ingress"
55+
internalPort := "50051" // from service definition
56+
externalHost := "localhost"
57+
externalPort, err := ingress.MappedPort(ctx, "50051")
58+
if err != nil {
59+
log.Fatalf("Failed to get mapped port: %v", err)
60+
}
61+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
services:
2+
3+
chip-ingress:
4+
image: chip-ingress:latest
5+
container_name: chip-ingress
6+
depends_on:
7+
- redpanda-0
8+
- otel-lgtm
9+
10+
restart: on-failure
11+
tty: true
12+
command: ["write-service"]
13+
environment:
14+
SERVER_HOST: "0.0.0.0"
15+
SERVER_GRPC_PORT: "50051"
16+
SERVER_METRICS_PORT: "9090"
17+
SERVER_HEALTHCHECKS_PORT: "9091"
18+
SERVER_METRICS_IMPLEMENTATION: "otel"
19+
SERVER_METRICS_OTEL_EXPORTER_GRPC_ENDPOINT: ${SERVER_METRICS_OTEL_EXPORTER_GRPC_ENDPOINT:-otel-lgtm:4317}
20+
KAFKA_BROKERS: "redpanda-0:9092"
21+
SCHEMA_REGISTRY_URL: "http://redpanda-0:8081"
22+
BASIC_AUTH_ENABLED: ${BASIC_AUTH_ENABLED:-true}
23+
BASIC_AUTH_PREFIX: ${BASIC_AUTH_PREFIX:-CE_SA_}
24+
CE_SA_BEHOLDER_DEMO_CLIENT: |
25+
{"username": "beholder-demo-client", "password": "password", "allowed_domains": ["*"]}
26+
CSA_AUTH_ENABLED: ${CSA_AUTH_ENABLED:-false}
27+
CSA_AUTH_ADDRESS: ${CSA_AUTH_ADDRESS:-}
28+
CSA_AUTH_USERNAME: ${CSA_AUTH_USERNAME:-}
29+
CSA_AUTH_PASSWORD: ${CSA_AUTH_PASSWORD:-}
30+
CSA_AUTH_REQUIRE_TLS: ${CSA_AUTH_REQUIRE_TLS:-false}
31+
ports:
32+
- "50051:50051"
33+
- "9090:9090"
34+
- "9092:9091"
35+
healthcheck:
36+
# test: [ "CMD", "grpc_health_probe", "-addr=localhost:50051" ]
37+
test: [ "CMD-SHELL", "sleep 1"]
38+
interval: 200ms
39+
timeout: 10s
40+
retries: 10
41+
42+
redpanda-0:
43+
image: docker.redpanda.com/redpandadata/redpanda
44+
container_name: redpanda-0
45+
hostname: redpanda-0
46+
command:
47+
- redpanda
48+
- start
49+
- --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
50+
- --advertise-kafka-addr internal://redpanda-0:9092,external://localhost:19092
51+
- --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
52+
- --advertise-pandaproxy-addr internal://redpanda-0:8082,external://localhost:18082
53+
- --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
54+
- --rpc-addr redpanda-0:33145
55+
- --advertise-rpc-addr redpanda-0:33145
56+
- --mode dev-container
57+
- --smp 1
58+
- --default-log-level=info
59+
- --set redpanda.auto_create_topics_enabled=true
60+
ports:
61+
- "18081:18081"
62+
- "18082:18082"
63+
- "19092:19092"
64+
- "19644:9644"
65+
healthcheck:
66+
test: curl -f http://localhost:9644/v1/status/ready || exit 1
67+
interval: 1s
68+
timeout: 10s
69+
retries: 5
70+
start_period: 1s
71+
72+
redpanda-console:
73+
container_name: redpanda-console
74+
image: docker.redpanda.com/redpandadata/console
75+
entrypoint: /bin/sh
76+
command: -c 'echo "$$CONSOLE_CONFIG_FILE" > /tmp/config.yml; /app/console'
77+
environment:
78+
CONFIG_FILEPATH: /tmp/config.yml
79+
CONSOLE_CONFIG_FILE: |
80+
kafka:
81+
brokers: ["redpanda-0:9092"]
82+
schemaRegistry:
83+
enabled: true
84+
urls: ["http://redpanda-0:8081"]
85+
protobuf:
86+
enabled: true
87+
schemaRegistry:
88+
enabled: true
89+
refreshInterval: 5s
90+
redpanda:
91+
adminApi:
92+
enabled: true
93+
urls: ["http://redpanda-0:9644"]
94+
ports:
95+
- "8080:8080"
96+
depends_on:
97+
- redpanda-0
98+
99+
otel-lgtm:
100+
image: grafana/otel-lgtm
101+
ports:
102+
- "3000:3000"
103+
- "4317:4317"
104+
- "4318:4318"
105+
- "3100:3100"
106+

0 commit comments

Comments
 (0)