Files
ghost-docker/compose.yml
Chris Raible e6d4754682 Added Tinybird migrations (#2)
no refs

The current setup runs the base Ghost installation without Traffic Analytics functionality. This commit adds:

- `tinybird-sync` service, which copies the latest Tinybird datafiles from the `ghost` container into a shared volume
- `tinybird-deploy` service & Dockerfile that includes the `tb` CLI, and runs `tb --cloud deploy` on boot
- Instructions for one-time manual setup of the Tinybird workspace in `TINYBIRD.md`

After the one-time manual setup, this configuration should automatically update Tinybird's datasources and endpoints in sync with the Ghost container when it is updated.


The initial setup is a bit clumsy and requires more manual steps than expected:
- The tinybird datafiles are in the Ghost image, but we need to access them from the `tinybird-deploy` service, which includes the `tb` CLI.
- When creating a new workspace in Tinybird, you can't access your admin token right away. Instead, it forces you to run `tb login` and `tb --cloud deploy` before you can access the rest of your workspace UI. This requires the user to install the `tb` CLI locally, and run an interactive login to authenticate with their Tinybird workspace. The generated `.tinyb` file is then mounted into the `tinybird-deploy` container, so this is only required for initial setup.
- Ghost requires the Tinybird `stats` and `tracker` token to be provided at boot. This means the user has to manually copy these tokens (either from CLI or the Workspace UI) and add them to their `.env` file manually. 
- We may want to either publish the Docker image with the Tinybird CLI installed, or possibly add the `tb` CLI to the traffic-analytics container.
2025-06-01 14:13:40 -07:00

135 lines
3.7 KiB
YAML

services:
caddy:
image: caddy:2-alpine
restart: always
ports:
- "80:80"
- "443:443"
environment:
DOMAIN: ${DOMAIN:?DOMAIN environment variable is required}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
depends_on:
- ghost
networks:
- ghost_network
ghost:
image: ghost:5-alpine
restart: always
expose:
- "2368"
environment:
url: https://${DOMAIN:?DOMAIN environment variable is required}
database__client: mysql
database__connection__host: db
database__connection__user: ${DATABASE_USER:-ghost}
database__connection__password: ${DATABASE_PASSWORD:?DATABASE_PASSWORD environment variable is required}
database__connection__database: ghost
enableDeveloperExperiments: true
tinybird__tracker__endpoint: https://${DOMAIN:?DOMAIN environment variable is required}/.ghost/analytics/tb/web_analytics
tinybird__tracker__id: ${TINYBIRD_ID:-}
tinybird__tracker__datasource: analytics_events
tinybird__tracker__token: ${TINYBIRD_TRACKER_TOKEN:-}
tinybird__stats__endpoint: ${TINYBIRD_API_URL:-https://api.tinybird.co}
tinybird__stats__id: ${TINYBIRD_ID:-}
tinybird__stats__token: ${TINYBIRD_STATS_TOKEN:-}
volumes:
- ghost_content:/var/lib/ghost/content
depends_on:
db:
condition: service_healthy
tinybird-sync:
condition: service_completed_successfully
required: false
tinybird-deploy:
condition: service_completed_successfully
required: false
networks:
- ghost_network
db:
image: mysql:8.0
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD:?DATABASE_ROOT_PASSWORD environment variable is required}
MYSQL_USER: ${DATABASE_USER:-ghost}
MYSQL_PASSWORD: ${DATABASE_PASSWORD:?DATABASE_PASSWORD environment variable is required}
MYSQL_DATABASE: ghost
MYSQL_MULTIPLE_DATABASES: activitypub
volumes:
- db_data:/var/lib/mysql
- ./mysql-init:/docker-entrypoint-initdb.d
healthcheck:
test: mysql -u${DATABASE_USER:-ghost} -p${DATABASE_PASSWORD:?DATABASE_PASSWORD environment variable is required} ghost -e 'select 1'
interval: 1s
retries: 120
networks:
- ghost_network
traffic-analytics:
image: ghost/traffic-analytics:edge
restart: always
expose:
- "3000"
environment:
NODE_ENV: production
PROXY_TARGET: ${TINYBIRD_API_URL:-https://api.tinybird.co}/v0/events
LOG_LEVEL: debug
profiles: [analytics]
networks:
- ghost_network
tinybird-sync:
image: ghost:5-alpine
command: >
sh -c "
if [ -d /var/lib/ghost/current/core/server/data/tinybird ]; then
rm -rf /shared/tinybird/*;
cp -rf /var/lib/ghost/current/core/server/data/tinybird/* /shared/tinybird/;
echo 'Tinybird files synced into shared volume.';
else
echo 'Tinybird source directory not found.';
fi
"
volumes:
- tinybird_files:/shared/tinybird
networks:
- ghost_network
profiles: [analytics]
restart: no
tinybird-deploy:
build:
context: ./tinybird
dockerfile: Dockerfile
working_dir: /home/tinybird
command: >
sh -c "
tb --cloud deploy
"
volumes:
- .tinyb:/home/tinybird/.tinyb
- tinybird_files:/home/tinybird
depends_on:
tinybird-sync:
condition: service_completed_successfully
profiles: [analytics]
networks:
- ghost_network
tty: true
volumes:
ghost_content:
db_data:
caddy_data:
caddy_config:
tinybird_files:
networks:
ghost_network: