Skip to content

Commit d13ff71

Browse files
committed
initial setup
1 parent 0ec7506 commit d13ff71

File tree

8 files changed

+179
-0
lines changed

8 files changed

+179
-0
lines changed

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
11
# Self Hosting [Plausible](https://plausible.io/docs/self-hosting) on [Fly.io](https://fly.io/)
22

33
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: <YOUR 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=<FROM ABOVE>
42+
43+
<SET ADDITIONAL CONFIGURATION (See Below)>
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 <BASE_URL>
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+
```

clickhouse/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

clickhouse/clickhouse-config.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<yandex>
2+
<logger>
3+
<level>warning</level>
4+
<console>true</console>
5+
</logger>
6+
7+
<!-- Stop all the unnecessary logging -->
8+
<query_thread_log remove="remove"/>
9+
<query_log remove="remove"/>
10+
<text_log remove="remove"/>
11+
<trace_log remove="remove"/>
12+
<metric_log remove="remove"/>
13+
<asynchronous_metric_log remove="remove"/>
14+
</yandex>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<yandex>
2+
<profiles>
3+
<default>
4+
<log_queries>0</log_queries>
5+
<log_query_threads>0</log_query_threads>
6+
</default>
7+
</profiles>
8+
</yandex>

clickhouse/fly.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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"

clickhouse/ulimits.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
ulimit -n 262144

plausible/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://github.com/plausible/analytics/blob/master/Dockerfile
2+
FROM plausible/analytics:latest

plausible/fly.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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"

0 commit comments

Comments
 (0)