Skip to content

Commit 93103f7

Browse files
committed
feat: add docker support
1 parent 18744ef commit 93103f7

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
config.json
2+
config.docker.json
23
potat-api
34
perm
45
dump

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# syntax=docker/dockerfile:1.7
2+
3+
FROM golang:1.23 AS builder
4+
WORKDIR /src
5+
6+
# Cache mod download layer
7+
COPY go.mod go.sum ./
8+
RUN --mount=type=cache,target=/go/pkg/mod \
9+
go mod download
10+
11+
COPY . .
12+
RUN --mount=type=cache,target=/go/pkg/mod \
13+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o potat-api ./
14+
15+
FROM gcr.io/distroless/base-debian12 AS runner
16+
WORKDIR /app
17+
18+
COPY --from=builder /src/potat-api /app/potat-api
19+
COPY exampleconfig.json /app/exampleconfig.json
20+
COPY --from=builder /src/haste/static /app/haste/static
21+
22+
EXPOSE 8080
23+
24+
ENTRYPOINT ["/app/potat-api"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ On startup if the required Postgres tables for haste, url shortener, or image ho
1515
- Optionally install [ClickHouse](https://clickhouse.com/docs/en/quick-start), and [RabbitMQ](https://www.rabbitmq.com/docs/download) if enabling the PotatBotat backend, and [Prometheus](https://prometheus.io/docs/prometheus/latest/installation/) if enabling metrics
1616
- Populate `exampleconfig.json` with the database credentials, and ports for services you want to run. It will be renamed on startup.
1717

18+
### To run with Docker
19+
20+
- Copy `config.docker.json.example` to `config.docker.json` and fill in your credentials
21+
- Run `docker compose up --build -d`
22+
- API will be available at `http://localhost:8080`
23+
1824
### Example Chatterino uploader configuration
1925

2026

config.docker.json.example

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"twitch": {
3+
"client_id": "your_twitch_client_id",
4+
"client_secret": "your_twitch_client_secret",
5+
"oauth_uri": "http://localhost:8080"
6+
},
7+
"loops": {
8+
"enabled": false
9+
},
10+
"nats": {
11+
"enabled": false
12+
},
13+
"api": {
14+
"enabled": true,
15+
"host": "0.0.0.0",
16+
"port": "8080"
17+
},
18+
"socket": {
19+
"enabled": false,
20+
"host": "0.0.0.0",
21+
"port": "8090"
22+
},
23+
"redirects": {
24+
"enabled": false,
25+
"host": "0.0.0.0",
26+
"port": "8091"
27+
},
28+
"uploader": {
29+
"authkey": "your_uploader_auth_key",
30+
"enabled": false,
31+
"port": "8092",
32+
"host": "0.0.0.0"
33+
},
34+
"haste": {
35+
"enabled": false,
36+
"host": "0.0.0.0",
37+
"port": "8081",
38+
"keyLength": 6
39+
},
40+
"prometheus": {
41+
"enabled": false,
42+
"host": "0.0.0.0",
43+
"port": "9100"
44+
},
45+
"postgres": {
46+
"host": "postgres",
47+
"port": "5432",
48+
"database": "potat",
49+
"user": "potat",
50+
"password": "potat"
51+
},
52+
"clickhouse": {
53+
"host": "clickhouse",
54+
"port": "9000",
55+
"database": "potat",
56+
"user": "default",
57+
"password": ""
58+
},
59+
"redis": {
60+
"host": "redis",
61+
"port": "6379"
62+
}
63+
}

docker-compose.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
version: "3.9"
2+
3+
services:
4+
potat-api:
5+
build:
6+
context: .
7+
target: runner
8+
image: potat-api:local
9+
depends_on:
10+
postgres:
11+
condition: service_healthy
12+
redis:
13+
condition: service_healthy
14+
clickhouse:
15+
condition: service_healthy
16+
ports:
17+
- "8080:8080"
18+
volumes:
19+
- ./config.docker.json:/app/config.json:ro
20+
restart: unless-stopped
21+
22+
postgres:
23+
image: postgres:16
24+
environment:
25+
POSTGRES_USER: potat
26+
POSTGRES_PASSWORD: potat
27+
POSTGRES_DB: potat
28+
ports:
29+
- "5432:5432"
30+
volumes:
31+
- postgres_data:/var/lib/postgresql/data
32+
healthcheck:
33+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
34+
interval: 5s
35+
timeout: 5s
36+
retries: 12
37+
restart: unless-stopped
38+
39+
redis:
40+
image: redis:7
41+
ports:
42+
- "6379:6379"
43+
volumes:
44+
- redis_data:/data
45+
healthcheck:
46+
test: ["CMD", "redis-cli", "ping"]
47+
interval: 5s
48+
timeout: 3s
49+
retries: 20
50+
restart: unless-stopped
51+
52+
clickhouse:
53+
image: clickhouse/clickhouse-server:24.8
54+
environment:
55+
CLICKHOUSE_DB: potat
56+
CLICKHOUSE_USER: default
57+
CLICKHOUSE_PASSWORD: ""
58+
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: "1"
59+
ports:
60+
- "9000:9000"
61+
volumes:
62+
- clickhouse_data:/var/lib/clickhouse
63+
- clickhouse_logs:/var/log/clickhouse-server
64+
healthcheck:
65+
test: ["CMD-SHELL", "clickhouse-client --query 'SELECT 1'"]
66+
interval: 10s
67+
timeout: 5s
68+
retries: 12
69+
restart: unless-stopped
70+
71+
volumes:
72+
postgres_data:
73+
redis_data:
74+
clickhouse_data:
75+
clickhouse_logs:

0 commit comments

Comments
 (0)