Repository navigation
Expand file tree
/
Copy pathcompose.yml
More file actions
107 lines (101 loc) · 3.77 KB
/
Copy pathcompose.yml
File metadata and controls
107 lines (101 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Local infrastructure.
#
# make run → spring-boot-docker-compose starts `db` (the only un-profiled service) and wires the
# datasource; you rarely start it by hand.
# make observability-up → Prometheus + Grafana + Alloy. Grafana at http://localhost:3000 shows the same
# dashboard production uses; Alloy scrapes the app you run on the host.
# make up → the app image too (profile `full`), for checking the container end to end.
#
# Tests never use this file: Testcontainers gives each fork its own PostgreSQL.
services:
db:
image: postgres:17-alpine
ports:
- "127.0.0.1:${DB_PORT:-5432}:5432"
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
POSTGRES_USER: ${POSTGRES_USER:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-app}
volumes:
- db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-app} -d ${POSTGRES_DB:-app}"]
interval: 5s
timeout: 5s
retries: 5
app:
profiles: ["full"]
build:
context: .
depends_on:
db:
condition: service_healthy
ports:
- "${SERVER_PORT:-8080}:8080"
environment:
APP_NAME: ${APP_NAME:-spring-template}
APP_ENV: local
SPRING_PROFILES_ACTIVE: prod
# Reach the database by its compose service name, not localhost.
DB_URL: jdbc:postgresql://db:5432/${POSTGRES_DB:-app}
DB_USERNAME: ${POSTGRES_USER:-app}
DB_PASSWORD: ${POSTGRES_PASSWORD:-app}
restart: unless-stopped
# --- observability profile -------------------------------------------------------------------------------------
# Same push path as production: Alloy scrapes /actuator/prometheus and remote-writes, here into a throwaway
# Prometheus instead of Grafana Cloud. The dashboard JSON and the Alloy config are the production files.
prometheus:
profiles: ["observability"]
image: prom/prometheus:v3.1.0
command:
- --config.file=/etc/prometheus/prometheus.yml
- --web.enable-remote-write-receiver
- --storage.tsdb.retention.time=24h
volumes:
- ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
ports:
- "127.0.0.1:${PROMETHEUS_PORT:-9090}:9090"
grafana:
profiles: ["observability"]
image: grafana/grafana:11.5.1
environment:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
GF_AUTH_DISABLE_LOGIN_FORM: "true"
GF_USERS_DEFAULT_THEME: dark
volumes:
- ./deploy/grafana/provisioning:/etc/grafana/provisioning:ro
- ./deploy/grafana/dashboards:/var/lib/grafana/dashboards:ro
ports:
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000"
depends_on:
- prometheus
alloy:
profiles: ["observability"]
image: grafana/alloy:v1.10.0
command:
- run
- --server.http.listen-addr=0.0.0.0:12345
- --storage.path=/var/lib/alloy/data
- /etc/alloy/config.alloy
volumes:
- ./deploy/alloy/config.alloy:/etc/alloy/config.alloy:ro
- alloy-data:/var/lib/alloy/data
environment:
GRAFANA_CLOUD_PROM_URL: http://prometheus:9090/api/v1/write
GRAFANA_CLOUD_PROM_USER: local
GRAFANA_CLOUD_PROM_TOKEN: local
# The app normally runs on the HOST (`make run`); host-gateway is how a container reaches it on Linux, and a
# static target is used because /etc/hosts aliases are invisible to DNS discovery (see config.alloy).
APP_METRICS_STATIC_TARGET: host.docker.internal:${APP_METRICS_PORT:-8080}
APP_METRICS_HOST: alloy
APP_ENV: local
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "127.0.0.1:${ALLOY_PORT:-12345}:12345"
depends_on:
- prometheus
volumes:
db-data:
alloy-data: