Files
ghost-docker/TINYBIRD.md
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

2.2 KiB

Tinybird Configuration

Note: Currently Traffic Analytics features are behind a feature flag. For now, you'll need to enable developer experiments by setting ENABLE_DEV_EXPERIMENTS=true in your .env file, and enable the Traffic Analytics feature flag under Settings > Labs > Private Features.

Steps:

  1. Create a Tinybird account and a Tinybird workspace at tinybird.co. You can select any cloud/region you choose.
  2. Follow the first two steps in the Quickstart to install the Tinybird CLI and run tb login, but do not proceed any further with the Quickstart instructions.
  3. Run docker compose --profile=analytics up tinybird-sync. This will copy the Tinybird files from the Ghost container into a shared volume. The service should log "Tinybird files synced into shared volume.", then exit.
  4. Run docker compose --profile=analytics up tinybird-deploy and wait for the service to exit successfully. This will create your Tinybird datasources, pipes and API endpoints. It may take a minute or two to complete the first time. You should see "Deployment #1 is live!" in your terminal before the service exits.
  5. Copy your Tinybird stats_page token: tb --cloud token copy stats_page and add it to your .env file as TINYBIRD_STATS_TOKEN. You can also copy the stats_page token from your Tinybird Workspace's UI.
  6. Copy your Tinybird tracker token: tb --cloud token copy tracker and add it to your .env file as TINYBIRD_TRACKER_TOKEN. You can also copy the tracker token from your Tinybird Workspace's UI.
  7. Find your workspace's events API endpoint: tb --cloud info, copy the value of "api", and add it to your .env file as TINYBIRD_API_URL. You can also find this value in your Tinybird Workspace's UI.
  8. Run docker compose --profile=analytics up -d to start all services in the background. You can also set COMPOSE_PROFILES=analytics in your .env file to automatically include the analytics profile when running docker compose commands.
  9. At this point, everything should be working. You can test it's working by visiting your site's homepage, then checking the Stats page in Ghost Admin — you should see a view recorded.