├── README.md ├── clickhouse ├── Dockerfile ├── clickhouse-config.xml ├── clickhouse-user-config.xml ├── fly.toml └── ulimits.sh └── plausible ├── Dockerfile └── fly.toml /README.md: -------------------------------------------------------------------------------- 1 | # Self Hosting [Plausible](https://plausible.io/docs/self-hosting) on [Fly.io](https://fly.io/) 2 | 3 | This repo is based on the [docker-compose version](https://github.com/plausible/hosting) published by Plausible 4 | 5 | ## Overview 6 | 7 | There are 4-5 Services that are required to run plausible: The plausible service itself, a postgres DB, a Clickhouse Server, an SMTP Service, and an (optional) geolocation database. The self-hosting guide and the associated repository are a great place to start, but they only provide a docker-compose file and kubernetes examples. To run on fly.io, I'd like to deploy each service separately. 8 | 9 | ## Postgres 10 | 11 | Refer to the [Fly.io documenation](https://fly.io/docs/reference/postgres/) for complete instructions. 12 | 13 | ``` 14 | flyctl postgres create 15 | ? App Name: plausible-db 16 | ? Select organization: 17 | ? Select region: ewr (Secaucus, NJ (US)) 18 | ? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk 19 | ``` 20 | 21 | Save the credentials somewhere safe 22 | 23 | ## Clickhouse 24 | 25 | (from the clickhouse directory) 26 | 27 | ``` 28 | flyctl volumes create plausible_clickhouse_data --region ewr --size 1 29 | flyctl deploy 30 | ``` 31 | 32 | ## Plausible 33 | 34 | (from the plausible directory) 35 | 36 | ``` 37 | flyctl postgres attach --postgres-app plausible-db 38 | 39 | openssl rand -base64 64 | tr -d '\n' ; echo 40 | 41 | flyctl secrets set SECRET_KEY_BASE= 42 | 43 | 44 | 45 | flyctl deploy 46 | ``` 47 | 48 | The default VM was running out of memory: 49 | 50 | ``` 51 | fly scale memory 1024 52 | ``` 53 | 54 | ``` 55 | fly ssh console 56 | 57 | entrypoint.sh db init-admin 58 | ``` 59 | 60 | ### [DNS Entries / SSL](https://fly.io/docs/app-guides/custom-domains-with-fly/) 61 | A Record 62 | AAAA Record 63 | 64 | ``` 65 | flyctl certs create 66 | ``` 67 | 68 | ### Secrets & Configuration 69 | 70 | Please refer the [configuration documentation](https://plausible.io/docs/self-hosting-configuration#mailersmtp-setup) 71 | 72 | These are the configurations we used: 73 | 74 | ``` 75 | ADMIN_USER_NAME 76 | ADMIN_USER_EMAIL 77 | ADMIN_USER_PWD 78 | 79 | BASE_URL 80 | SECRET_KEY_BASE 81 | DISABLE_REGISTRATION=true 82 | 83 | MAILER_ADAPTER=Bamboo.PostmarkAdapter 84 | POSTMARK_API_KEY 85 | MAILER_EMAIL 86 | 87 | GOOGLE_CLIENT_ID 88 | GOOGLE_CLIENT_SECRET 89 | ``` 90 | -------------------------------------------------------------------------------- /clickhouse/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM yandex/clickhouse-server:21.3.2.5 2 | 3 | COPY clickhouse-config.xml /etc/clickhouse-server/config.d/logging.xml 4 | COPY clickhouse-user-config.xml /etc/clickhouse-server/users.d/logging.xml 5 | 6 | # Set recommended ulimits: https://hub.docker.com/r/yandex/clickhouse-server 7 | COPY ulimits.sh /docker-entrypoint-initdb.d/ulimits.sh 8 | -------------------------------------------------------------------------------- /clickhouse/clickhouse-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | warning 4 | true 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /clickhouse/clickhouse-user-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /clickhouse/fly.toml: -------------------------------------------------------------------------------- 1 | app = "plausible-clickhouse" 2 | 3 | kill_signal = "SIGINT" 4 | kill_timeout = 5 5 | processes = [] 6 | services = [] 7 | 8 | [env] 9 | 10 | [experimental] 11 | allowed_public_ports = [] 12 | auto_rollback = true 13 | 14 | [[mounts]] 15 | source = "plausible_clickhouse_data" 16 | destination = "/var/lib/clickhouse" 17 | -------------------------------------------------------------------------------- /clickhouse/ulimits.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ulimit -n 262144 4 | -------------------------------------------------------------------------------- /plausible/Dockerfile: -------------------------------------------------------------------------------- 1 | # https://github.com/plausible/analytics/blob/master/Dockerfile 2 | FROM plausible/analytics:latest 3 | -------------------------------------------------------------------------------- /plausible/fly.toml: -------------------------------------------------------------------------------- 1 | app = "plausible" 2 | 3 | kill_signal = "SIGTERM" 4 | kill_timeout = 5 5 | processes = [] 6 | 7 | [deploy] 8 | release_command = "db migrate" 9 | 10 | [env] 11 | CLICKHOUSE_DATABASE_URL="http://plausible-clickhouse.internal:8123/plausible_dev" 12 | LISTEN_IP="::" 13 | ECTO_IPV6=true 14 | 15 | [experimental] 16 | allowed_public_ports = [] 17 | auto_rollback = true 18 | 19 | [[services]] 20 | http_checks = [] 21 | internal_port = 8000 22 | processes = ["app"] 23 | protocol = "tcp" 24 | script_checks = [] 25 | 26 | [services.concurrency] 27 | hard_limit = 25 28 | soft_limit = 20 29 | type = "connections" 30 | 31 | [[services.ports]] 32 | handlers = ["http"] 33 | port = 80 34 | 35 | [[services.ports]] 36 | handlers = ["tls", "http"] 37 | port = 443 38 | 39 | [[services.tcp_checks]] 40 | grace_period = "30s" 41 | interval = "15s" 42 | restart_limit = 0 43 | timeout = "2s" 44 | --------------------------------------------------------------------------------