1- # Lab 05 — Advanced Integration: postgresql with full IT-Stack ecosystem
2- ---
31services :
4- postgresql :
5- image : postgres:16
6- container_name : it-stack-postgresql
7- restart : unless-stopped
2+
3+ # ── PostgreSQL: serves as DB for Keycloak AND app ─────────────────
4+ postgres :
5+ image : postgres:16-alpine
6+ environment :
7+ POSTGRES_PASSWORD : Lab05Password!
8+ command : >
9+ postgres
10+ -c shared_buffers=256MB
11+ -c max_connections=200
12+ -c log_connections=on
13+ ports :
14+ - " 5432:5432"
15+ networks :
16+ - int-net
17+ volumes :
18+ - pg-int:/var/lib/postgresql/data
19+ - ./integration/pg-init.sh:/docker-entrypoint-initdb.d/pg-init.sh:ro
20+ healthcheck :
21+ test : ["CMD-SHELL", "pg_isready -U postgres"]
22+ interval : 5s
23+ timeout : 3s
24+ retries : 20
25+
26+ # ── Redis: session cache shared by app nodes ──────────────────────
27+ redis :
28+ image : redis:7.2-alpine
29+ command : redis-server --requirepass Lab05Password! --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
830 ports :
9- - " 5432:$firstPort"
31+ - " 6379:6379"
32+ networks :
33+ - int-net
34+ volumes :
35+ - redis-int:/data
36+ healthcheck :
37+ test : ["CMD", "redis-cli", "-a", "Lab05Password!", "--no-auth-warning", "PING"]
38+ interval : 5s
39+ timeout : 3s
40+ retries : 15
41+
42+ # ── Keycloak: uses PostgreSQL as its database ─────────────────────
43+ keycloak :
44+ image : quay.io/keycloak/keycloak:24.0
45+ command : start-dev
46+ depends_on :
47+ postgres :
48+ condition : service_healthy
1049 environment :
11- - IT_STACK_ENV=lab-05-integration
12- - KEYCLOAK_URL=
13- - DB_HOST=
14- - REDIS_HOST=
15- - SMTP_HOST=
16- - GRAYLOG_HOST=
17- extra_hosts :
18- - " lab-id1:10.0.50.11"
19- - " lab-db1:10.0.50.12"
20- - " lab-proxy1:10.0.50.15"
50+ KC_BOOTSTRAP_ADMIN_USERNAME : admin
51+ KC_BOOTSTRAP_ADMIN_PASSWORD : Lab05Password!
52+ KC_DB : postgres
53+ KC_DB_URL : " jdbc:postgresql://postgres:5432/keycloak"
54+ KC_DB_USERNAME : keycloak
55+ KC_DB_PASSWORD : Lab05Password!
56+ KC_HTTP_PORT : " 8080"
57+ KC_HOSTNAME_STRICT : " false"
58+ KC_PROXY : edge
2159 networks :
22- - it-stack-net
60+ - int-net
61+ healthcheck :
62+ test : ["CMD-SHELL", "curl -sf http://localhost:8080/health/ready || exit 1"]
63+ interval : 10s
64+ timeout : 5s
65+ retries : 30
66+ start_period : 60s
67+ labels :
68+ - " traefik.enable=true"
69+ - " traefik.http.routers.keycloak.rule=PathPrefix(`/auth`) || PathPrefix(`/realms`) || PathPrefix(`/admin`)"
70+ - " traefik.http.routers.keycloak.entrypoints=web"
71+ - " traefik.http.services.keycloak.loadbalancer.server.port=8080"
72+
73+ # ── App node 1 (whoami — simulates app backed by PG + Redis) ──────
74+ app-1 :
75+ image : traefik/whoami:latest
76+ environment :
77+ WHOAMI_NAME : " app-node-1"
78+ networks :
79+ - int-net
80+ labels :
81+ - " traefik.enable=true"
82+ - " traefik.http.routers.app.rule=PathPrefix(`/app`)"
83+ - " traefik.http.routers.app.entrypoints=web"
84+ - " traefik.http.services.app.loadbalancer.server.port=80"
85+
86+ # ── App node 2 (second replica — load balanced by Traefik) ────────
87+ app-2 :
88+ image : traefik/whoami:latest
89+ environment :
90+ WHOAMI_NAME : " app-node-2"
91+ networks :
92+ - int-net
93+ labels :
94+ - " traefik.enable=true"
95+ - " traefik.http.routers.app.rule=PathPrefix(`/app`)"
96+ - " traefik.http.routers.app.entrypoints=web"
97+ - " traefik.http.services.app.loadbalancer.server.port=80"
98+
99+ # ── Traefik: routes to Keycloak + app ─────────────────────────────
100+ traefik :
101+ image : traefik:v3.0
102+ command :
103+ - --api.dashboard=true
104+ - --api.insecure=true
105+ - --entrypoints.web.address=:80
106+ - --entrypoints.metrics.address=:8082
107+ - --metrics.prometheus=true
108+ - --metrics.prometheus.entrypoint=metrics
109+ - --providers.docker=true
110+ - --providers.docker.exposedbydefault=false
111+ - --accesslog=true
112+ - --accesslog.format=json
113+ ports :
114+ - " 80:80"
115+ - " 8080:8080"
116+ - " 8082:8082"
117+ volumes :
118+ - /var/run/docker.sock:/var/run/docker.sock:ro
119+ networks :
120+ - int-net
121+ depends_on :
122+ keycloak :
123+ condition : service_healthy
23124
24125networks :
25- it-stack -net :
126+ int -net :
26127 driver : bridge
128+
129+ volumes :
130+ pg-int :
131+ redis-int:
0 commit comments