Skip to content

Commit

Permalink
v2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Sep 3, 2024
1 parent 4e949e8 commit 60d6815
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 73 deletions.
96 changes: 29 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,107 +70,87 @@ Right now the latter looks like this:
```env
BASE_URL=replace-me
SECRET_KEY_BASE=replace-me
TOTP_VAULT_KEY=replace-me
HTTP_PORT=8000
HTTPS_PORT=8001
```

Let's do as it asks and populate these required environment variables with our own values.

#### Required configuration

First we generate the [secret key base](#secret_key_base) and [TOTP vault key](#totp_vault_key) using OpenSSL:
First we generate the [secret key base](#secret_key_base) using OpenSSL:

<sub><kbd>console</kbd></sub>
```console
$ openssl rand -base64 48
GLVzDZW04FzuS1gMcmBRVhwgd4Gu9YmSl/k/TqfTUXti7FLBd7aflXeQDdwCj6Cz
$ openssl rand -base64 32
dsxvbn3jxDd16az2QpsX5B8O+llxjQ2SJE2i5Bzx38I=
```

And then we decide on the [base URL](#base_url) where the instance would be accessible:

<sub><kbd>plausible-conf.env</kbd></sub>
```diff
- BASE_URL=replace-me
+ BASE_URL=http://plausible.example.com
+ BASE_URL=https://plausible.example.com
- SECRET_KEY_BASE=replace-me
+ SECRET_KEY_BASE=GLVzDZW04FzuS1gMcmBRVhwgd4Gu9YmSl/k/TqfTUXti7FLBd7aflXeQDdwCj6Cz
- TOTP_VAULT_KEY=replace-me
+ TOTP_VAULT_KEY=dsxvbn3jxDd16az2QpsX5B8O+llxjQ2SJE2i5Bzx38I=
HTTP_PORT=8000
HTTPS_PORT=8001
```

We can start our instance now but the requests would be served over HTTP. Not cool! Let's configure [Caddy](https://caddyserver.com) to enable HTTPS.
We can start our instance now.

#### Caddy

> [!TIP]
> For other reverse-proxy setups please see [reverse-proxy](./reverse-proxy) docs.
#### Reverse proxy

<details>
<summary>Don't need reverse proxy?</summary>
<summary>Using a reverse proxy?</summary>

---

If you're **opting out** of a reverse proxy and HTTPS, you'll need to adjust the Plausible service [configuration](./docker-compose.yml#L38) to ensure it's not limited to localhost (127.0.0.1). This change allows the service to be accessible from any network interface:
> [!TIP]
> Please see [reverse-proxy](./reverse-proxy) docs for some reverse-proxy setups.
If you're using a reverse proxy, you'll might want to adjust the Plausible service [configuration](./docker-compose.yml#L38) to ensure it's limited to localhost (127.0.0.1).

<sub><kbd>[docker-compose.yml](./docker-compose.yml#L38)</kbd></sub>
```diff
plausible:
ports:
- - 127.0.0.1:8000:8000
+ - 8000:8000
- - 8000:8000
+ - 127.0.0.1:8000:8000
```

---

</details>

First we need to point DNS records for our base URL to the IP address of the instance. This is needed for Caddy to issue the TLS certificates.

Then we need to let Caddy know the domain name for which to issue the TLS certificate and the service to redirect the requests to.

<sub><kbd>[reverse-proxy/docker-compose.caddy-gen.yml](./reverse-proxy/docker-compose.caddy-gen.yml)</kbd></sub>
```diff
plausible:
labels:
- virtual.host: "example.com" # change to your domain name
+ virtual.host: "plausible.example.com"
virtual.port: "8000"
- virtual.tls-email: "[email protected]" # change to your email
+ virtual.tls-email: "[email protected]"
```

Finally we need to update the base URL to use HTTPS scheme.
You also need to disable automatic certificate issuance by removing `HTTPS_PORT` from ENV.

<sub><kbd>plausible-conf.env</kbd></sub>
```diff
- BASE_URL=http://plausible.example.com
+ BASE_URL=https://plausible.example.com
BASE_URL=https://plausible.example.com
SECRET_KEY_BASE=GLVzDZW04FzuS1gMcmBRVhwgd4Gu9YmSl/k/TqfTUXti7FLBd7aflXeQDdwCj6Cz
TOTP_VAULT_KEY=dsxvbn3jxDd16az2QpsX5B8O+llxjQ2SJE2i5Bzx38I=
HTTP_PORT=8000
- HTTPS_PORT=8001
```

Now we can start everything together.
---

</details>

#### Launch

<sub><kbd>console</kbd></sub>
```console
$ docker compose -f docker-compose.yml -f reverse-proxy/docker-compose.caddy-gen.yml up -d
$ docker compose up -d
[+] Running 19/19
✔ plausible_db 9 layers [⣿⣿⣿⣿⣿⣿⣿] Pulled
✔ plausible_events_db 7 layers [⣿⣿⣿⣿⣿⣿⣿] Pulled
✔ plausible 7 layers [⣿⣿⣿⣿⣿⣿⣿] Pulled
✔ caddy-gen 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿] Pulled
[+] Running 5/5
[+] Running 4/4
✔ Network hosting_default Created
✔ Container hosting-plausible_db-1 Started
✔ Container hosting-plausible_events_db-1 Started
✔ Container hosting-plausible-1 Started
✔ Container caddy-gen Started
```

It takes some time to start PostgreSQL and ClickHouse, create the databases, and run the migrations. After about fifteen seconds you should be able to access your instance at the base URL and see the registration screen for the admin user.
It takes some time to start PostgreSQL and ClickHouse, create the databases, run the migrations, and issue a TLS certificate. After about fifteen seconds you should be able to access your instance at the base URL and see the registration screen for the admin user.

> [!TIP]
> If something feels off, make sure to check out the logs with <kbd>docker compose logs</kbd> and start a [GitHub discussion.](https://github.com/plausible/analytics/discussions/categories/self-hosted-support)
Expand Down Expand Up @@ -208,7 +188,7 @@ $ docker compose rm plausible
? Going to remove hosting-plausible-1 Yes
[+] Running 1/0
✔ Container hosting-plausible-1 Removed
$ docker compose -f docker-compose.yml -f reverse-proxy/docker-compose.caddy-gen.yml up -d
$ docker compose up -d
[+] Running 8/8
✔ plausible 7 layers [⣿⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 6.4s
✔ 96526aa774ef Pull complete 0.4s
Expand All @@ -218,11 +198,10 @@ $ docker compose -f docker-compose.yml -f reverse-proxy/docker-compose.caddy-gen
✔ 724ddb9b523f Pull complete 2.8s
✔ 32581b0068b9 Pull complete 1.7s
✔ 4f4fb700ef54 Pull complete 2.0s
[+] Running 4/4
[+] Running 3/3
✔ Container hosting-plausible_events_db-1 Running 0.0s
✔ Container hosting-plausible_db-1 Running 0.0s
✔ Container hosting-plausible-1 Started 1.2s
✔ Container caddy-gen Running 0.0s
$ docker images --filter=reference='ghcr.io/plausible/community-edition:*'
REPOSITORY TAG IMAGE ID CREATED SIZE
ghcr.io/plausible/community-edition v2.1 63f7c8708294 6 days ago 83.4MB
Expand All @@ -232,9 +211,6 @@ Untagged: ghcr.io/plausible/community-edition:v2.1.0-rc.0
...
```

> [!TIP]
> You can omit <kbd>-f docker-compose.yml -f reverse-proxy/docker-compose.caddy-gen.yml</kbd> if you are not using Caddy.
Changes in major versions would involve performing a data migration (e.g. [v2.0.0](https://github.com/plausible/analytics/releases/tag/v2.0.0)) or some other extra step.

## Configure
Expand Down Expand Up @@ -355,15 +331,6 @@ $ docker compose exec plausible_db psql -U postgres -h localhost -d plausible_db

### Web

#### LISTEN_IP

Default: `0.0.0.0`

Configures the IP address to bind the listen socket for the web server.

> [!WARNING]
> Note that setting it to `127.0.0.1` in a container would make the web server unavailable from outside the container.
---

#### PORT
Expand Down Expand Up @@ -732,16 +699,11 @@ $ docker compose rm plausible
? Going to remove hosting-plausible-1 Yes
[+] Running 1/0
⠿ Container hosting-plausible-1 Removed
$ docker compose -f docker-compose.yml -f reverse-proxy/docker-compose.caddy-gen.yml up -d
[+] Running 4/4
$ docker compose up -d
[+] Running 3/3
✔ Container hosting-plausible_events_db-1 Running 0.0s
✔ Container hosting-plausible_db-1 Running 0.0s
✔ Container hosting-plausible-1 Started 1.2s
✔ Container caddy-gen Running 0.0s
[+] Running 3/3
⠿ Container hosting-plausible_db-1 Healthy 0.5s
⠿ Container hosting-plausible_events_db-1 Healthy 0.5s
⠿ Container hosting-plausible-1 Started
$ docker compose exec plausible sh -c 'echo $GOOGLE_CLIENT_ID'
974728454958-e1vcqqqs6hmoc394663kjrkgfajrifdg.apps.googleusercontent.com
```
Expand Down
17 changes: 12 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
plausible_db:
# Plausible v2.1.1 was tested against PostgreSQL versions 15 and 16
# https://github.com/plausible/analytics/blob/v2.1.1/.github/workflows/elixir.yml#L21-L32
# https://github.com/plausible/analytics/blob/v2.1.2/.github/workflows/elixir.yml#L21-L32
image: postgres:16-alpine
restart: always
volumes:
Expand All @@ -23,16 +23,23 @@ services:
hard: 262144

plausible:
image: ghcr.io/plausible/community-edition:v2.1.1
image: ghcr.io/plausible/community-edition:v2.1.2
restart: always
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
depends_on:
- plausible_db
- plausible_events_db
ports:
- 127.0.0.1:8000:8000
env_file:
- plausible-conf.env
- 8000:8000
- 8001:8001
env:
BASE_URL: ${BASE_URL}
SECRET_KEY_BASE: ${SECRET_KEY_BASE}
HTTP_PORT: 8000
HTTPS_PORT: 8001
DATABASE_URL: postgres://postgres:postgres@plausible_db:5432/plausible_db
CLICKHOUSE_DATABASE_URL: http://plausible_events_db:8123/plausible_events_db
DISABLE_REGISTRATION: true

volumes:
db-data:
Expand Down
3 changes: 2 additions & 1 deletion plausible-conf.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BASE_URL=replace-me
SECRET_KEY_BASE=replace-me
TOTP_VAULT_KEY=replace-me
HTTP_PORT=8000
HTTPS_PORT=8001

0 comments on commit 60d6815

Please sign in to comment.