Skip to content

Commit

Permalink
Add docker-compose file (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Dec 11, 2022
1 parent 537fde3 commit 23b32f5
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Fix: JSON responses now always return the proper content type. (#334)
- Dev: Improve BetterTTV emote tests. (#282)
- Minor: BetterTTV cache key changed from plural to singular form. (#282)
- Dev: Add docker-compose support. (#395)
- Dev: Improve Twitch.tv clip tests. (#283)
- Dev: Improve YouTube tests. (#284)
- Dev: Resolver Check now returns a context. (#287)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ Uptime: 928h5m7.937821282s - Memory: Alloc=510 MiB, TotalAlloc=17419213 MiB, Sys
If you host your own version of this API, you can modify which url Chatterino2 uses to resolve links and to resolve twitch emote sets.
[Change link resolver](https://wiki.chatterino.com/Environment%20Variables/#chatterino2_link_resolver_url)
[Change Twitch emote resolver](https://wiki.chatterino.com/Environment%20Variables/#chatterino2_twitch_emote_set_resolver_url)
[How to build and host](docs/build.md)
[How to build and host](docs/build.md)
[Running in Docker](docker/README.md)
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3.9"
services:
api:
restart: always
image: ghcr.io/chatterino/api:latest
environment:
- CHATTERINO_API_DSN=postgres://${PG_USER:-api}:${PG_PASS:-api}@db:5432/${PG_USER:-api}
- CHATTERINO_API_PROMETHEUS_BIND_ADDRESS=0.0.0.0:9182
env_file: docker/chatterino2-api.env
ports:
- "${API_PORT:-1234}:1234"
depends_on:
- "db"
db:
image: postgres:15-alpine
restart: always
env_file: docker/env
environment:
- POSTGRES_USER=${PG_USER:-api}
- POSTGRES_PASSWORD=${PG_PASS:-api}
volumes:
- db:/var/lib/postgresql/data
prometheus:
restart: always
image: prom/prometheus:latest
env_file: docker/env
volumes:
- $PWD/docker/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- "${PROM_PORT:-9090}:9090"
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
pg_exporter:
restart: always
image: quay.io/prometheuscommunity/postgres-exporter:latest
env_file: docker/env
environment:
- DATA_SOURCE_URI=db?sslmode=disable
- DATA_SOURCE_USER=${PG_USER:-api}
- DATA_SOURCE_PASS=${PG_PASS:-api}
- PG_EXPORTER_EXCLUDE_DATABASES=template0,template1
depends_on:
- "db"
volumes:
db:
prometheus_data:
27 changes: 27 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Running in Docker

In the root directory there's a `docker-compose.yml` file which defines the Chatterino API, a PostgreSQL database, and Prometheus

You can configure those with the `env` and `chatterino2-api.env` files in this directory.

If you're going to make changes to the env files directly in the repo, you will want to ignore them locally:
`git update-index --assume-unchanged env chatterino2-api.env`

## Forwarding prometheus

If you want to forward prometheus at a different route, you'll need to add a `--web.route-prefix` to the command in the `docker-compose.yml` file. For example:

```diff
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
+ - '--web.route-prefix=/prometheus'
```

## Changing the base URL

If you host this service under a subpath, you'll need to add and modify the `CHATTERINO_API_BASE_URL` environment variable to the `chatterino2-api.env` file. For example:

```env
CHATTERINO_API_BASE_URL=https://braize.pajlada.com/chatterino
```
13 changes: 13 additions & 0 deletions docker/chatterino2-api.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CHATTERINO_API_LOG_LEVEL=info
CHATTERINO_API_ENABLE_ANIMATED_THUMBNAILS=true

CHATTERINO_API_DISCORD_TOKEN=

CHATTERINO_API_IMGUR_CLIENT_ID=

CHATTERINO_API_TWITCH_CLIENT_ID=
CHATTERINO_API_TWITCH_CLIENT_SECRET=

CHATTERINO_API_YOUTUBE_API_KEY=

CHATTERINO_API_TWITTER_BEARER_TOKEN=
11 changes: 11 additions & 0 deletions docker/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## .env file for docker-compose

# Postgres credentials - Will default to "api" if not set
PG_USER=
PG_PASS=

# Port to expose the API from. Use 127.0.0.1:1234 to expose on localhost only
API_PORT=127.0.0.1:1234

# Port to expose the Prometheus server from. Use 127.0.0.1:9090 to expose on localhost only
PROM_PORT=127.0.0.1:9090
16 changes: 16 additions & 0 deletions docker/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
metrics_path: '/prometheus/metrics'
static_configs:
- targets: ['127.0.0.1:9090']

- job_name: 'postgres'
static_configs:
- targets: ['pg_exporter:9187']

- job_name: 'chatterino2_api'
static_configs:
- targets: ['api:9182']

0 comments on commit 23b32f5

Please sign in to comment.