Skip to content

Commit

Permalink
build: Add Temporal to docker-compose.yml and fix host.docker.internal (
Browse files Browse the repository at this point in the history
#184)

* temporal docker implementation

* remove unnecessary access to internal-network

* adding development compose containing UI and admin tools.

* temporal dev envrionment changes

* build: Combine all services + update .env.example

* build: Update docker compose dev extension

* test: Update conftest session env var

* biuld: Remove docker compose temporal extensions

* fix: Use postgres_db in db uri

---------

Co-authored-by: xander Luedtke <[email protected]>
Co-authored-by: Daryl Lim <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2024
1 parent 9e6e4d4 commit d84c2bb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 25 deletions.
17 changes: 13 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# --- Shared env vars ---
LOG_LEVEL=INFO
COMPOSE_PROJECT_NAME=tracecat

# --- App and DB env vars ---
# One of `development`, `staging`, or `production`
Expand All @@ -23,9 +24,9 @@ TRACECAT__API_URL=http://api:8000
TRACECAT__PUBLIC_RUNNER_URL=http://localhost:8000

# --- Postgres ---
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
TRACECAT__DB_URI=postgresql+psycopg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@host.docker.internal:5432/postgres
TRACECAT__POSTGRES_USER=postgres
TRACECAT__POSTGRES_PASSWORD=postgres
TRACECAT__DB_URI=postgresql+psycopg://${TRACECAT__POSTGRES_USER}:${TRACECAT__POSTGRES_PASSWORD}@postgres_db:5432/postgres

# --- Shared frontend env vars ---
# Important: environment variables prefixed with `NEXT_PUBLIC_` are exposed to the browser client
Expand Down Expand Up @@ -57,8 +58,16 @@ NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up

# --- Temporal ---
TEMPORAL__CLUSTER_URL=http://host.docker.internal:7233
TEMPORAL__CLUSTER_URL=temporal:7233
TEMPORAL__CLUSTER_QUEUE=tracecat-task-queue
TEMPORAL__CLUSTER_NAMESPACE=tracecat
TEMPORAL__VERSION=1.24.2
TEMPORAL__POSTGRES_USER=temporal
TEMPORAL__POSTGRES_PASSWORD=temporal
TEMPORAL__ELASTICSEARCH_VERSION=7.16.2
TEMPORAL__ADMINTOOLS_VERSION=1.24.2-tctl-1.18.1-cli-0.13.0
TEMPORAL__UI_VERSION=2.26.2
TEMPORAL__POSTGRESQL_VERSION=13

# --- Cloud only ---
# Tracecat Cloud only, please ignore if self-hosted:
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ services:
build: .
volumes:
- ./tracecat:/app/tracecat
- app-storage:/var/lib/tracecat
- core-app:/var/lib/tracecat

worker:
build: .
volumes:
- ./tracecat:/app/tracecat
- app-storage:/var/lib/tracecat
- core-app:/var/lib/tracecat

frontend:
build:
Expand All @@ -32,5 +32,4 @@ services:
- ./frontend/node_modules:/app/node_modules

volumes:
app-storage:
db-storage:
core-app:
106 changes: 89 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
services:
api:
image: ghcr.io/tracecathq/tracecat:${TRACECAT__IMAGE_TAG:-latest}
container_name: api
container_name: tracecat_api
ports:
- "8000:8000"
- 8000:8000
environment:
LOG_LEVEL: ${LOG_LEVEL}
TRACECAT__API_URL: ${TRACECAT__API_URL}
Expand All @@ -21,11 +21,12 @@ services:
TEMPORAL__CLUSTER_QUEUE: ${TEMPORAL__CLUSTER_QUEUE} # Sensitive
restart: unless-stopped
networks:
- internal-network
- core
- temporal

worker:
image: ghcr.io/tracecathq/tracecat:${TRACECAT__IMAGE_TAG:-latest}
container_name: worker
container_name: tracecat_worker
environment:
LOG_LEVEL: ${LOG_LEVEL}
TRACECAT__API_URL: ${TRACECAT__API_URL}
Expand All @@ -41,10 +42,11 @@ services:
TEMPORAL__CLUSTER_QUEUE: ${TEMPORAL__CLUSTER_QUEUE} # Sensitive
restart: unless-stopped
networks:
- internal-network
- core
- temporal
entrypoint: ["python", "tracecat/dsl/worker.py"]

frontend:
ui:
build:
context: ./frontend
dockerfile: Dockerfile.prod
Expand All @@ -55,10 +57,10 @@ services:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY} # Sensitive
NEXT_SERVER_API_URL: ${NEXT_SERVER_API_URL}
NODE_ENV: ${NODE_ENV}
container_name: frontend
container_name: tracecat_ui
env_file: .env
ports:
- "3000:3000"
- 3000:3000
environment:
CLERK_SECRET_KEY: ${CLERK_SECRET_KEY} # Sensitive
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL}
Expand All @@ -74,25 +76,95 @@ services:
depends_on:
- api
networks:
- internal-network
- core

postgres_db:
image: postgres:16.2-bullseye
container_name: postgres_db
container_name: tracecat_postgres_db
ports:
- "5432:5432"
- 5432:5432
restart: always
shm_size: 128mb
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${TRACECAT__POSTGRES_USER}
POSTGRES_PASSWORD: ${TRACECAT__POSTGRES_PASSWORD}
networks:
- internal-network
- core
volumes:
- db-storage:/var/lib/postgresql/data
- core-db:/var/lib/postgresql/data

temporal_postgres_db:
image: postgres:${TEMPORAL__POSTGRESQL_VERSION}
container_name: tracecat_temporal_postgres_db
environment:
POSTGRES_USER: ${TEMPORAL__POSTGRES_USER}
POSTGRES_PASSWORD: ${TEMPORAL__POSTGRES_PASSWORD}
networks:
- temporal
volumes:
- temporal-db:/var/lib/postgresql/data

temporal_elasticsearch:
container_name: tracecat_temporal_elasticsearch
environment:
- cluster.routing.allocation.disk.threshold_enabled=true
- cluster.routing.allocation.disk.watermark.low=512mb
- cluster.routing.allocation.disk.watermark.high=256mb
- cluster.routing.allocation.disk.watermark.flood_stage=128mb
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms256m -Xmx256m
- xpack.security.enabled=false
- logger.level=WARN
image: elasticsearch:${TEMPORAL__ELASTICSEARCH_VERSION}
networks:
- temporal
volumes:
- temporal-elasticsearch:/var/lib/elasticsearch/data
expose:
- 9200

temporal_ui:
image: temporalio/ui:${TEMPORAL__UI_VERSION}
container_name: tracecat_temporal_ui
environment:
- TEMPORAL_ADDRESS=temporal:7233
- TEMPORAL_CORS_ORIGINS=http://localhost:3000
depends_on:
- temporal
- temporal_elasticsearch
networks:
- temporal
ports:
- 8080:8080

temporal:
image: temporalio/auto-setup:${TEMPORAL__VERSION}
container_name: tracecat_temporal
environment:
- DB=postgres12
- DB_PORT=5432
- POSTGRES_USER=${TEMPORAL__POSTGRES_USER}
- POSTGRES_PWD=${TEMPORAL__POSTGRES_PASSWORD}
- POSTGRES_SEEDS=temporal_postgres_db
- DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/tracecat-sql.yaml
- ENABLE_ES=true
- ES_SEEDS=temporal_elasticsearch
- ES_VERSION=v7
- LOG_LEVEL=warn
ports:
- 7233:7233
depends_on:
- temporal_postgres_db
networks:
- temporal
volumes:
- ./temporal/config:/etc/temporal/config/dynamicconfig

networks:
internal-network:
core:
temporal:

volumes:
db-storage:
core-db:
temporal-db:
temporal-elasticsearch:
3 changes: 3 additions & 0 deletions temporal/config/tracecat-sql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
limit.maxIDLength:
- value: 255
constraints: {}
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def env_sandbox(monkeysession, request: pytest.FixtureRequest):
# If the worker is running inside a container, use host.docker.internal
monkeysession.setenv("TEMPORAL__CLUSTER_URL", "http://localhost:7233")
monkeysession.setenv("TEMPORAL__CLUSTER_QUEUE", "test-tracecat-task-queue")
monkeysession.setenv("TEMPORAL__CLUSTER_NAMESPACE", "default")
yield
# Cleanup is automatic with monkeypatch
logger.info("Environment variables cleaned up")
Expand Down

0 comments on commit d84c2bb

Please sign in to comment.