:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
#!/bin/bash
set -e
set -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
CONTAINER_NAME="posthog-recording-rasterizer"
IMAGE_NAME="recording-rasterizer:local"
# Build for the host: chrome-headless-shell ships an arm64 build, and an emulated amd64 Chromium is
# far too slow to render with. Apple Silicon and the arm64 devboxes both land here.
case "$(uname -m)" in
arm64 | aarch64) PLATFORM="linux/arm64" ;;
*) PLATFORM="linux/amd64" ;;
esac
"$SCRIPT_DIR/build-recording-rasterizer-image"
cd "$ROOT_DIR"
# --- Step 3: Stop existing container ---
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Stopping existing container..."
docker stop "$CONTAINER_NAME" >/dev/null 2>&1 || true
docker rm "$CONTAINER_NAME" >/dev/null 2>&1 || true
fi
# --- Step 4: Start container ---
# The container joins the docker-compose network for Temporal and MinIO,
# and uses host.docker.internal for services running natively on the host
# (recording-api, Django).
# Chrome's namespace-sandbox needs seccomp/apparmor relaxed to bootstrap inside
# the linux/amd64 emulation Docker uses on macOS. Local dev script only — prod
# runs from the Helm chart, not this script.
echo "Starting recording-rasterizer container..."
video_storage_endpoint="${VIDEO_EXPORT_OBJECT_STORAGE_ENDPOINT:-http://posthog-objectstorage-1:19000}"
if [[ "$video_storage_endpoint" =~ ^http://(127\.0\.0\.1|localhost)([:/?#].*)?$ ]]; then
video_storage_endpoint="http://host.docker.internal${BASH_REMATCH[2]}"
fi
# nosemgrep: trailofbits.generic.container-privileged.container-privileged
docker run --rm --security-opt seccomp=unconfined --security-opt apparmor=unconfined \
--name "$CONTAINER_NAME" \
--network posthog_default \
--platform "$PLATFORM" \
--add-host localhost:host-gateway \
--add-host host.docker.internal:host-gateway \
-e NODE_ENV=development \
-e TEMPORAL_HOST="${TEMPORAL_HOST:-posthog-temporal-1}" \
-e TEMPORAL_PORT="${TEMPORAL_PORT:-7233}" \
-e RECORDING_API_BASE_URL="${RECORDING_API_BASE_URL:-http://host.docker.internal:6741}" \
-e SITE_URL="${SITE_URL:-http://host.docker.internal:8000}" \
-e VIDEO_EXPORT_OBJECT_STORAGE_ENDPOINT="$video_storage_endpoint" \
-e AWS_ACCESS_KEY_ID=object_storage_root_user \
-e AWS_SECRET_ACCESS_KEY=object_storage_root_password \
-e DISABLE_BROWSER_SECURITY="${DISABLE_BROWSER_SECURITY:-1}" \
-e MAX_CONCURRENT_ACTIVITIES="${MAX_CONCURRENT_ACTIVITIES:-8}" \
-e CAPTURE_BROWSER_LOGS="${CAPTURE_BROWSER_LOGS:-0}" \
-e SECRET_KEY="${SECRET_KEY:?SECRET_KEY must be set}" \
-e LOG_LEVEL="${LOG_LEVEL:-info}" \
-e SCREENSHOT_FORMAT="${SCREENSHOT_FORMAT:-jpeg}" \
-e SCREENSHOT_JPEG_QUALITY="${SCREENSHOT_JPEG_QUALITY:-80}" \
-e CHROME_HOST_RESOLVER_RULES="MAP localhost host.docker.internal" \
-e RASTERIZER_USE_PROXY="${RASTERIZER_USE_PROXY:-false}" \
-v "$ROOT_DIR/nodejs/dist/session-replay/recording-rasterizer:/code/nodejs/dist/session-replay/recording-rasterizer" \
-v "$ROOT_DIR/common/replay-headless/dist:/code/common/replay-headless/dist" \
"$IMAGE_NAME" \
2>&1 | pnpm --filter=@posthog/nodejs exec pino-pretty --colorize