Add docker and compose config

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-16 13:45:38 +01:00
parent 8983a0d7ed
commit b5ddb7d8cf
6 changed files with 203 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
NPX?= npx
PRETTIER?= $(NPX) prettier
GO?= go
DOCKER?= docker
DOCKER_COMPOSE= $(DOCKER) compose -f compose.yaml $(DOCKER_COMPOSE_FLAGS)
VERSION= unknown
LDFLAGS= -ldflags "-X 'main.version=$(VERSION)' -X 'main.env=prod'"
@@ -41,3 +44,15 @@ fmt-check:
.PHONY: clean
clean:
$(RM) -rf bin/*
.PHONY: stack-up
stack-up:
$(DOCKER_COMPOSE) up -d
.PHONY: stack-down
stack-down:
$(DOCKER_COMPOSE) down
.PHONY: stack-ps
stack-ps:
$(DOCKER_COMPOSE) ps

70
compose.yaml Normal file
View File

@@ -0,0 +1,70 @@
services:
postgres:
image: "postgres:16"
shm_size: "1g"
command: >
postgres -c "shared_buffers=4GB"
-c "max_connections=200"
-c "log_statement=all"
ports:
- "5432:5432"
volumes:
- "./compose/postgres:/docker-entrypoint-initdb.d:ro"
- "postgres-data:/var/lib/postgresql/data:rw"
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
grafana:
image: "grafana/grafana:latest"
ports:
- "3001:3000"
volumes:
- "./compose/grafana/provisioning:/etc/grafana/provisioning:ro"
- "grafana-data:/var/lib/grafana:rw"
environment:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin"
GF_AUTH_DISABLE_LOGIN_FORM: "true"
GF_USERS_DEFAULT_THEME: "light"
prometheus:
image: "prom/prometheus:latest"
volumes:
- "./compose/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml"
- "prometheus-data:/prometheus"
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/etc/prometheus/console_libraries"
- "--web.console.templates=/etc/prometheus/consoles"
- "--web.enable-lifecycle"
- "--web.enable-remote-write-receiver"
- "--web.listen-address=:9191"
ports:
- "9191:9191"
loki:
image: "grafana/loki:latest"
ports:
- "3100:3100"
command:
- "-config.file=/etc/loki/local-config.yaml"
tempo:
image: "grafana/tempo:latest"
command:
- "-config.file=/etc/tempo.yaml"
ports:
- "4317:4317"
volumes:
- "./compose/tempo/tempo.yaml:/etc/tempo.yaml:ro"
- "tempo-data:/var/db/tempo:rw"
volumes:
postgres-data:
grafana-data:
prometheus-data:
tempo-data:

View File

@@ -0,0 +1,42 @@
apiVersion: 1
deleteDatasources:
- name: "Prometheus"
- name: "Loki"
- name: "Tempo"
datasources:
- name: "Prometheus"
type: "prometheus"
access: "proxy"
url: "http://prometheus:9191"
basicAuth: false
jsonData:
httpMethod: "POST"
manageAlerts: true
prometheusType: "Prometheus"
cacheLevel: 'High'
disableRecordingRules: false
incrementalQueryOverlapWindow: 10m
isDefault: false
version: 1
editable: false
- name: "Loki"
type: "loki"
access: "proxy"
url: "http://loki:3100"
basicAuth: false
version: 1
editable: false
jsonData:
derivedFields:
- datasourceUid: "tempo"
matcherRegex: traceID=(\w+)
name: "TraceID"
url: $${__value.raw}
- name: "Tempo"
type: tempo
access: proxy
url: "http://tempo:3200"
basicAuth: false
isDefault: true
version: 1
editable: false

23
compose/postgres/01_probod.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/sh
set -eu
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER <<-EOF
CREATE USER probod;
ALTER USER probod WITH SUPERUSER;
ALTER USER probod PASSWORD 'probod';
CREATE DATABASE probod;
GRANT ALL PRIVILEGES ON DATABASE probod TO probod;
CREATE DATABASE probod_test;
GRANT ALL PRIVILEGES ON DATABASE probod_test TO probod;
EOF
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d probod <<-EOF
ALTER SCHEMA public OWNER TO probod;
GRANT ALL ON SCHEMA public TO probod;
EOF
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d probod_test <<-EOF
ALTER SCHEMA public OWNER TO probod;
GRANT ALL ON SCHEMA public TO probod;
EOF

View File

@@ -0,0 +1,12 @@
global:
scrape_interval: "15s"
evaluation_interval: "15s"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["host.docker.internal:9090"]
- job_name: "tempo"
static_configs:
- targets: ["tempo:3200"]

41
compose/tempo/tempo.yaml Normal file
View File

@@ -0,0 +1,41 @@
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
ingester:
trace_idle_period: "10s"
max_block_bytes: 1_000_000
max_block_duration: "5m"
compactor:
compaction:
compaction_window: "1h"
max_block_bytes: 100_000_000
block_retention: "1h"
compacted_block_retention: "10m"
storage:
trace:
backend: "local"
local:
path: "/var/db/tempo"
block:
bloom_filter_false_positive: .05
v2_index_downsample_bytes: 1000
v2_encoding: "zstd"
wal:
path: "/var/db/tempo/wal"
v2_encoding: "snappy"
pool:
max_workers: 100
queue_depth: 10000
usage_report:
reporting_enabled: false