Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/_example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"db:executor:up": "cd ../workflow-executor/example && docker compose up -d",
"db:executor:down": "cd ../workflow-executor/example && docker compose down",
"db:executor:reset": "cd ../workflow-executor/example && docker compose down -v && docker compose up -d",
"executor:docker": "docker compose --env-file ../workflow-executor/example/.env.executors -f ../workflow-executor/example/docker-compose.executors.yml up"
"start:with-executor:multiple-instance": "concurrently --kill-others --names 'agent,executors' \"yarn start\" \"bash scripts/start-docker-executors.sh executors\"",
"start:with-executor:multiple-instance:build": "concurrently --kill-others --names 'agent,executors' \"yarn start\" \"bash scripts/start-docker-executors.sh executors:build\""
},
"devDependencies": {
"@types/node": "^20.12.12",
Expand Down
28 changes: 28 additions & 0 deletions packages/_example/scripts/start-docker-executors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Starts the multi-instance docker executors (nginx gateway on :3400), configured ENTIRELY from
# packages/_example/.env. Invoked by the start:with-executor:multiple-instance[:build] scripts.
#
# The executor example's own `executors` script stays config-agnostic (pure `docker compose up`):
# this wrapper sources _example/.env, translates host-local URLs so the containers can reach the
# host, waits for the agent, then delegates. Run standalone from the executor example dir to use
# that package's own .env instead.
set -euo pipefail
set -a
# shellcheck disable=SC1091
source .env

# localhost / 127.0.0.1 -> host.docker.internal (containers reach services on the host).
to_host() {
local v="${1/localhost/host.docker.internal}"
echo "${v/127.0.0.1/host.docker.internal}"
}

AGENT_URL="$(to_host "$EXECUTOR_AGENT_URL")"
DATABASE_URL="$(to_host "$EXECUTOR_DATABASE_URL")"
FOREST_SERVER_URL="$(to_host "${FOREST_SERVER_URL:-}")"

# Executors probe AGENT_URL on startup — wait for the host agent first (avoids restart noise).
until curl -s "$EXECUTOR_AGENT_URL" >/dev/null 2>&1; do sleep 1; done

# Exported vars above are inherited by docker compose interpolation in the example package.
yarn workspace workflow-executor-example "${1:-executors}"
23 changes: 17 additions & 6 deletions packages/workflow-executor/example/docker-compose.executors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
# single Postgres run store (so the write-ahead idempotency log is shared across
# instances). The store is YOUR existing local Postgres, reached via DATABASE_URL.
#
# cp .env.executors.example .env.executors # fill in secrets + DATABASE_URL
# docker compose --env-file .env.executors -f docker-compose.executors.yml up --build
# Config comes entirely from packages/_example/.env — there is nothing to edit here.
# Run it via the example package script, which sources that .env, remaps
# EXECUTOR_AGENT_URL/EXECUTOR_DATABASE_URL -> AGENT_URL/DATABASE_URL and rewrites
# localhost -> host.docker.internal so the containers can reach your host:
#
# yarn workspace workflow-executor-example executors[:build]
# # or, with the agent, from packages/_example:
# yarn start:with-executor:multiple-instance[:build]
#
# Point your agent at the gateway: workflowExecutorUrl: "http://localhost:3400".
# Your agent must be running on the host (executors probe AGENT_URL on startup).
#
# DATABASE_URL must use host.docker.internal (NOT localhost) to reach a Postgres
# running on your host, e.g. postgres://user:pass@host.docker.internal:5432/db

name: workflow-executor-gateway

Expand All @@ -28,12 +31,20 @@ x-executor-common: &executor-common
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
# Forest local-dev domains resolve to 127.0.0.1 via the host's /etc/hosts (the orchestrator
# runs on the host). Inside containers 127.0.0.1 is the container itself, so map them to the
# host. Inert for non-dev setups (prod api.forestadmin.com is unaffected).
- "api.development.forestadmin.com:host-gateway"
- "app.development.forestadmin.com:host-gateway"
- "static.development.forestadmin.com:host-gateway"

services:
executor-1:
<<: *executor-common
build:
context: ../..
# Repo root (relative to this compose file): the Dockerfile does `COPY . .` over the
# whole monorepo, so the build context must be the root, not packages/.
context: ../../..
dockerfile: packages/workflow-executor/Dockerfile
environment: *executor-env

Expand Down
4 changes: 3 additions & 1 deletion packages/workflow-executor/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"db:up": "docker compose up -d",
"db:down": "docker compose down",
"db:reset": "docker compose down -v && docker compose up -d",
"db:psql": "docker compose exec postgres psql -U executor -d workflow_executor"
"db:psql": "docker compose exec postgres psql -U executor -d workflow_executor",
"executors": "docker compose -f docker-compose.executors.yml up",
"executors:build": "docker compose -f docker-compose.executors.yml up --build"
},
"dependencies": {
"@forestadmin/workflow-executor": "*"
Expand Down
Loading