Skip to content

Commit 56dc236

Browse files
authored
Add instructions and configuration for running everything locally (#1328)
1 parent c6600ba commit 56dc236

File tree

23 files changed

+723
-10
lines changed

23 files changed

+723
-10
lines changed

DEV-LOCAL.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Develop the application locally
2+
3+
1. `sudo modprobe nbd nbds_max=64`
4+
2. `make local-infra`: runs clickhouse, grafana, loki, memcached, mimir, otel, postgres, redis, tempo
5+
3. `cd packages/db && make migrate-local` initialize the database
6+
4. `cd packages/local-dev && go run seed-local-database.go` generate user, team, and token for local development
7+
5. `cd packages/api && make run-local` run the api locally
8+
6. `cd packages/orchestrator && make build-debug && sudo make run-local` run the orchestrator and template-manager locally.
9+
7. `cd packages/client-proxy && make run-local` run the client-proxy locally.
10+
11+
# Services
12+
- grafana: http://localhost:53000)
13+
- postgres: postgres:postgres@127.0.0.1:5432
14+
- clickhouse: clickhouse:clickhouse@127.0.0.1:9000

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,7 @@ generate-mocks:
162162
.PHONY: tidy
163163
tidy:
164164
scripts/golang-dependencies-integrity.sh
165+
166+
.PHONY: local-infra
167+
local-infra:
168+
docker compose --file ./packages/local-dev/docker-compose.yaml up --abort-on-container-failure

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use (
77
./packages/db
88
./packages/docker-reverse-proxy
99
./packages/envd
10+
./packages/local-dev
1011
./packages/orchestrator
1112
./packages/shared
1213

packages/api/.env.local

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DNS_PORT=9953
2+
ENVIRONMENT=local
3+
OTEL_COLLECTOR_GRPC_ENDPOINT=localhost:4317
4+
POSTGRES_CONNECTION_STRING=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
5+
REDIS_URL=localhost:6379
6+
SANDBOX_ACCESS_TOKEN_HASH_SEED=--sandbox-access-token-hash-seed--
7+
SD_ORCHESTRATOR_PROVIDER=STATIC
8+
SD_ORCHESTRATOR_STATIC=127.0.0.1
9+
SD_EDGE_PROVIDER=STATIC
10+
SD_EDGE_STATIC=127.0.0.1

packages/api/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ run:
4343
LOCAL_CLUSTER_TOKEN=$(EDGE_TOKEN) \
4444
./bin/api --port 3000
4545

46+
define setup_local_env
47+
$(eval include .env.local)
48+
$(eval export $(shell sed 's/=.*//' .env.local))
49+
endef
50+
51+
.PHONY: run-local
52+
run-local:
53+
make build-debug
54+
$(call setup_local_env)
55+
NODE_ID=$$(hostname) ./bin/api --port 3000
56+
4657
# Run the API using air
4758
.PHONY: dev
4859
dev:

packages/api/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ func run() int {
217217
flag.StringVar(&debug, "debug", "false", "is debug")
218218
flag.Parse()
219219

220-
config, err := cfg.Parse()
221-
if err != nil {
222-
zap.L().Fatal("Error parsing config", zap.Error(err))
223-
}
224-
225220
serviceInstanceID := uuid.New().String()
226221
nodeID := env.GetNodeID()
227222

@@ -284,6 +279,11 @@ func run() int {
284279
expectedMigration = 0
285280
}
286281

282+
config, err := cfg.Parse()
283+
if err != nil {
284+
zap.L().Fatal("Error parsing config", zap.Error(err))
285+
}
286+
287287
err = utils.CheckMigrationVersion(config.PostgresConnectionString, expectedMigration)
288288
if err != nil {
289289
logger.Fatal("failed to check migration version", zap.Error(err))

packages/client-proxy/.env.local

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
EDGE_SECRET=--edge-secret--
2+
EDGE_URL=http://localhost:3000
3+
LOKI_URL=http://localhost:3100
4+
NODE_IP=127.0.0.1
5+
REDIS_URL=localhost:6379
6+
SD_EDGE_PROVIDER=STATIC
7+
SD_EDGE_STATIC=127.0.0.1
8+
SD_ORCHESTRATOR_PROVIDER=STATIC
9+
SD_ORCHESTRATOR_STATIC=127.0.0.1
10+
SKIP_ORCHESTRATOR_READINESS_CHECK=true
11+
USE_CATALOG_RESOLUTION=true

packages/client-proxy/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ run:
4343
LOKI_URL=unset \
4444
./bin/client-proxy
4545

46+
define setup_local_env
47+
$(eval include .env.local)
48+
$(eval export $(shell sed 's/=.*//' .env.local))
49+
endef
50+
51+
.PHONY: run-local
52+
run-local:
53+
make build-debug
54+
$(call setup_local_env)
55+
NODE_ID=$$(hostname) ./bin/client-proxy
56+
4657
.PHONY: generate
4758
generate:
4859
$(codegen) -old-config-style -generate gin --package api $(openapi) > ../shared/pkg/http/edge/api.gen.go

packages/db/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ ENV := $(shell cat ../../.last_used_env || echo "not-set")
22
-include ../../.env.${ENV}
33

44
goose := GOOSE_DBSTRING=$(POSTGRES_CONNECTION_STRING) go tool goose -table "_migrations" -dir "migrations" postgres
5+
goose-local := GOOSE_DBSTRING=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable go tool goose -table "_migrations" -dir "migrations" postgres
6+
57
IMAGE := e2b-orchestration/db-migrator
68

79
.PHONY: migrate
810
migrate:
911
@echo "Applying Postgres migration *$(notdir $@)* for ${ENV}"
1012
@$(goose) up
1113
@echo "Done"
14+
migrate-local:
15+
@echo "Applying Postgres migration *$(notdir $@)* for ${ENV}"
16+
@$(goose-local) up
17+
@echo "Done"
18+
1219
migrate/up: migrate
1320
migrate/down:
1421
@echo "Reverting Postgres migration *$(notdir $@)* for ${ENV}"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
services:
2+
clickhouse:
3+
image: "clickhouse:25.4.5.24"
4+
environment:
5+
CLICKHOUSE_DB: clickhouse
6+
CLICKHOUSE_USER: clickhouse
7+
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: '1'
8+
CLICKHOUSE_PASSWORD: clickhouse
9+
ports:
10+
- "8123:8123"
11+
- "9000:9000"
12+
volumes:
13+
- clickhouse:/var/lib/clickhouse
14+
15+
grafana:
16+
image: grafana/grafana:12.0.0
17+
volumes:
18+
- ./grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
19+
environment:
20+
- GF_AUTH_ANONYMOUS_ENABLED=true
21+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
22+
- GF_AUTH_DISABLE_LOGIN_FORM=true
23+
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor metricsSummary
24+
- GF_INSTALL_PLUGINS=https://storage.googleapis.com/integration-artifacts/grafana-exploretraces-app/grafana-exploretraces-app-latest.zip;grafana-traces-app
25+
ports:
26+
- "53000:3000"
27+
28+
loki:
29+
image: grafana/loki:3.4.1
30+
command: -config.file=/etc/loki/local-config.yaml
31+
ports:
32+
- "3100:3100"
33+
34+
memcached:
35+
image: memcached:1.6.38
36+
container_name: memcached
37+
ports:
38+
- "11211:11211"
39+
environment:
40+
- MEMCACHED_MAX_MEMORY=64m # Set the maximum memory usage
41+
- MEMCACHED_THREADS=4 # Number of threads to use
42+
43+
mimir:
44+
image: grafana/mimir:2.17.1
45+
command: -config.file=/etc/mimir/mimir.yaml
46+
volumes:
47+
- ./mimir.yaml:/etc/mimir/mimir.yaml
48+
49+
otel-collector:
50+
image: otel/opentelemetry-collector-contrib:0.135.0
51+
volumes:
52+
- ./otel-collector.yaml:/etc/otelcol-contrib/config.yaml
53+
ports:
54+
- "4317:4317" # OTLP gRPC receiver
55+
- "4318:4318" # OTLP HTTP receiver"
56+
57+
postgres:
58+
image: postgres:17.4
59+
environment:
60+
POSTGRES_USER: postgres
61+
POSTGRES_PASSWORD: postgres
62+
POSTGRES_DB: postgres
63+
PGDATA: /var/lib/postgresql/17/docker
64+
ports:
65+
- "5432:5432"
66+
volumes:
67+
- postgres:/var/lib/postgresql/17/docker
68+
69+
redis:
70+
image: redis:7.4.2
71+
ports:
72+
- "6379:6379"
73+
74+
tempo:
75+
image: grafana/tempo:2.8.2
76+
command: ["-config.file=/etc/tempo.yaml"]
77+
volumes:
78+
- ./tempo.yaml:/etc/tempo.yaml
79+
- tempo:/var/tempo
80+
ports:
81+
- "3200"
82+
depends_on:
83+
- tempo-init
84+
- memcached
85+
86+
# Tempo runs as user 10001, and docker compose creates the volume as root.
87+
# As such, we need to chown the volume in order for Tempo to start correctly.
88+
tempo-init:
89+
image: bash
90+
user: root
91+
entrypoint:
92+
- "chown"
93+
- "10001:10001"
94+
- "/var/tempo"
95+
volumes:
96+
- tempo:/var/tempo
97+
98+
volumes:
99+
clickhouse: {}
100+
postgres: {}
101+
tempo: {}

0 commit comments

Comments
 (0)