-
Notifications
You must be signed in to change notification settings - Fork 11
Posthog Unlocked Setup
Knowledge of docker and docker compose is required.
Primarily docker compose is supported to run Posthog Installation. Use Posthog Official installation docs and change the docker image of posthog for web, worker and async migration to: ghcr.io/karambir/posthog-unlocked:latest
.
Use the docker-compose.hobby.yml file. Here is an example file for use:
services:
db:
image: postgres:13-alpine
restart: unless-stopped
environment:
POSTGRES_USER: posthog
POSTGRES_DB: posthog
POSTGRES_PASSWORD: posthog
volumes:
- postgres-data:/var/lib/postgresql/data
redis:
image: redis:alpine
restart: unless-stopped
clickhouse:
image: ${CLICKHOUSE_SERVER_IMAGE:-clickhouse/clickhouse-server:22.8}
restart: unless-stopped
healthcheck:
# test: ["CMD-SHELL", "wget http://localhost:8123/"]
test: wget --no-verbose --tries=1 --spider http://localhost:8123/?query=SELECT%201 || exit 1
interval: 60s
timeout: 5s
retries: 5
start_period: 10s
depends_on:
- kafka
- zookeeper
volumes:
- clickhouse-data:/var/lib/clickhouse
- ./posthog-unlocked/posthog/idl:/idl
- ./posthog-unlocked/docker/clickhouse/config.xml:/etc/clickhouse-server/config.xml
- ./posthog-unlocked/docker/clickhouse/users.xml:/etc/clickhouse-server/users.xml
zookeeper:
image: zookeeper:3.7.0
restart: unless-stopped
volumes:
- zookeeper-datalog:/datalog
- zookeeper-data:/data
- zookeeper-logs:/logs
kafka:
image: bitnami/kafka:2.8.1-debian-10-r99
restart: unless-stopped
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1001
KAFKA_CFG_RESERVED_BROKER_MAX_ID: 1001
KAFKA_CFG_LISTENERS: PLAINTEXT://:9092
KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_CFG_ZOOKEEPER_CONNECT: zookeeper:2181
ALLOW_PLAINTEXT_LISTENER: 'true'
worker:
&worker
image: ghcr.io/karambir/posthog-unlocked:${POSTHOG_IMAGE_TAG}
restart: unless-stopped
command: ./bin/docker-worker-celery --with-scheduler
env_file:
- ./.env
depends_on:
db:
condition: service_started
redis:
condition: service_started
clickhouse:
condition: service_healthy
kafka:
condition: service_started
web:
<<: *worker
command: ./bin/docker-server
ports:
- 127.0.0.1:7600:8000
volumes:
- ./compose:/compose
plugins:
image: ghcr.io/karambir/posthog-unlocked:${POSTHOG_IMAGE_TAG}
restart: unless-stopped
command: ./bin/plugin-server --no-restart-loop
environment:
DATABASE_URL: 'postgres://posthog:posthog@db:5432/posthog'
KAFKA_HOSTS: 'kafka:9092'
REDIS_URL: 'redis://redis:6379/'
CLICKHOUSE_HOST: 'clickhouse'
depends_on:
- db
- redis
- clickhouse
- kafka
asyncmigrationscheck:
<<: *worker
command: python manage.py run_async_migrations --check
restart: 'no'
scale: 0
volumes:
postgres-data:
clickhouse-data:
zookeeper-data:
zookeeper-datalog:
zookeeper-logs:
version: '3'
Above compose file needs posthog-unlocked
repository to be cloned beside it. It references clickhouse configurations from it.
Some helpful environment vars to be set in .env
file for docker compose:
IS_DOCKER="true"
NODE_ENV="production"
# Django Web service
SECRET_KEY="randomkey"
SITE_URL="https://posthog.example.com"
DISABLE_SECURE_SSL_REDIRECT=True
IS_BEHIND_PROXY=True
# Trust all proxies or only trust host nginx
TRUST_ALL_PROXIES=True
# TRUSTED_PROXIES
DEPLOYMENT="onprem"
# Enable self capture
# See posthog/utils.py:206 line
# Capture posthog events in the same instance, not posthog.com
SELF_CAPTURE=True
# if using above example compose file:
POSTHOG_IMAGE_TAG="latest"
SKIP_SERVICE_VERSION_REQUIREMENTS=1
REDIS_URL="redis://redis:6379/"
DATABASE_URL="postgres://posthog:posthog@db:5432/posthog"
KAFKA_HOSTS="kafka:9092"
KAFKA_URL="kafka://kafka"
CLICKHOUSE_HOST="clickhouse"
CLICKHOUSE_DATABASE="posthog"
CLICKHOUSE_SECURE=False
CLICKHOUSE_VERIFY=False
Also add email related settings(in .env
) for password reset and user invites to work:
EMAIL_ENABLED=True
EMAIL_HOST="smtphost.com"
EMAIL_PORT=587
EMAIL_HOST_USER="smtpuser"
EMAIL_HOST_PASSWORD="smtppassword"
EMAIL_USE_TLS=True
EMAIL_DEFAULT_FROM="user@example.com"
Once docker compose is up and running, verify it did run postgres and clickhouse migrations. If not try following:
docker compose run --rm web /code/bin/migrate
Posthog unlocked has hard disabled signup, so you can't signup from web ui. Instead we have a small django management script to create a user. Checkout https://github.com/karambir/posthog-unlocked/blob/master/posthog/management/commands/create_staff_user.py
docker compose exec web python manage.py create_staff_user --first-name ExampleUser --email user@example.com --password examplePassword --org-name ExampleOrg
Once this is created, you can login, create and invite other users from web ui.