-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose.yaml
248 lines (237 loc) · 7.52 KB
/
compose.yaml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
### DESCRIPTION
# Docker compose to run complete infrastructure for Investment system.
# Configured services:
# - PostgreSQL <- database for storing all system related data
# - Flask <- API used to pull quotation form the Internet and perform calculations
# - Checker <- service to check if there are new quotation available and trigger download mechanism
# - DataImporter <- service to run on system start-up to insert initial configuration of:
# - monitored funds
# - investments
# - Grafana <- data visualisation tool
# - Loki <- database for systems' logs
# - Promtail <- scraper for logs generated by system
#
# Persistent storage:
# - APP_DATA <- system data to store DBs, current system status etc.
# - APP_LOG <- shared volume to allow Promtail service to access system log files.
#
# Networks:
# - LAN <- local network for internal communication between system components
# - WAN <- external network to allow interaction with the system.
# Ultimately, only Grafana will have access to the external network,
# as the frontend of the system.
### INPUTS
# .env file
### CHANGE LOG
# Author: Stanisław Horna
# GitHub Repository: https://github.com/StanislawHornaGitHub/Investment
# Created: 23-Apr-2024
# Version: 1.10
# Date Who What
# 2024-04-29 Stanisław Horna Add checker service to compose.
#
# 2024-05-01 Stanisław Horna Add health checks for components,
# and orchestrate the order of starting-up particular components.
#
# 2024-05-02 Stanisław Horna Add loki service to compose.
#
# 2024-05-04 Stanisław Horna Separate persistant storage based on type, to Logs and Data.
#
# 2024-05-05 Stanisław Horna Add timezone variable in .env file and assign it across services.
#
# 2024-05-05 Stanisław Horna Reflect new environment variables for DB read/write users.
#
# 2024-05-13 Stanisław Horna Add config directory volume to DataImporter service.
# Set all continuously running services to restart: unless-stopped.
#
# 2024-05-17 Stanisław Horna DataImporter implemented as a module of Checker service.
#
# 2024-05-18 Stanisław Horna Add healthcheck for Checker service.
#
# 2024-05-22 Stanisław Horna Fix compatibility with newer docker compose versions,
# Structure unified with standards.
#
services:
Grafana:
image: investment/grafana
build:
context: ./Grafana
dockerfile: Grafana.Dockerfile
container_name: ${GRAFANA_CONTAINER_NAME}
hostname: ${GRAFANA_HOSTNAME}
restart: unless-stopped
environment:
TZ: ${SYSTEM_TIME_ZONE}
GF_DATE_FORMATS_DEFAULT_TIMEZONE: ${SYSTEM_TIME_ZONE}
volumes:
- ./Grafana/datasources:/etc/grafana/provisioning/datasources
- ./Grafana/dashboards_provisioning:/etc/grafana/provisioning/dashboards
- ./Grafana/dashboards:/var/lib/grafana/dashboards
- ${APP_DATA_PATH}/${GRAFANA_PERSISTENT_STORAGE_DIR}:/var/lib/grafana
- ${APP_LOG_PATH}/${GRAFANA_PERSISTENT_STORAGE_DIR}:/var/log/grafana
ports:
- ${GRAFANA_EXTERNAL_PORT}:3000
networks:
Internal:
ipv4_address: ${GRAFANA_INTERNAL_IP}
External: null
healthcheck:
test: curl --fail http://${GRAFANA_HOSTNAME}:3000/api/health
start_period: 2s
interval: 3s
timeout: 1s
retries: 5
Flask:
image: investment/flask
build:
context: ./Flask
dockerfile: Flask.Dockerfile
depends_on:
PostgreSQL:
condition: service_healthy
container_name: ${FLASK_CONTAINER_NAME}
hostname: ${FLASK_HOSTNAME}
environment:
TZ: ${SYSTEM_TIME_ZONE}
DB_IP_Address: ${POSTGRESQL_INTERNAL_IP}
DB_Port: "5432"
DB_Username_rw: ${FLASK_DB_USERNAME_rw}
DB_Password_rw: ${FLASK_DB_PASSWORD_rw}
DB_Username_ro: ${FLASK_DB_USERNAME_ro}
DB_Password_ro: ${FLASK_DB_PASSWORD_ro}
restart: unless-stopped
volumes:
- ${APP_LOG_PATH}/${FLASK_PERSISTENT_STORAGE_DIR}:/log
ports:
- 5500:5000
networks:
Internal:
ipv4_address: ${FLASK_INTERNAL_IP}
External: null
healthcheck:
test: curl --fail http://${FLASK_HOSTNAME}:5000/health
start_period: 2s
interval: 2s
timeout: 1s
retries: 10
PostgreSQL:
image: investment/postgresql
build:
context: ./PostgreSQL
dockerfile: PostgreSQL.Dockerfile
container_name: ${POSTGRESQL_CONTAINER_NAME}
hostname: ${POSTGRESQL_HOSTNAME}
environment:
TZ: ${SYSTEM_TIME_ZONE}
restart: unless-stopped
volumes:
- ${APP_DATA_PATH}/${POSTGRESQL_PERSISTENT_STORAGE_DIR}:/var/lib/postgresql/data
ports:
- ${POSTGRESQL_EXTERNAL_PORT}:5432
networks:
Internal:
ipv4_address: ${POSTGRESQL_INTERNAL_IP}
External: null
healthcheck:
test: ["CMD-SHELL", "pg_isready -U Investments"]
start_period: 2s
interval: 2s
timeout: 5s
retries: 10
Checker:
image: investment/checker
build:
context: ./Checker
dockerfile: Checker.Dockerfile
depends_on:
PostgreSQL:
condition: service_healthy
Flask:
condition: service_healthy
container_name: ${CHECKER_CONTAINER_NAME}
hostname: ${CHECKER_HOSTNAME}
environment:
TZ: ${SYSTEM_TIME_ZONE}
restart: unless-stopped
volumes:
- ${APP_LOG_PATH}/${CHECKER_PERSISTENT_STORAGE_DIR}:/log
- ./Checker/Configs:/etc/checker
- ${APP_DATA_PATH}/${CHECKER_PERSISTENT_STORAGE_DIR}:/var/lib/checker
networks:
Internal:
ipv4_address: ${CHECKER_INTERNAL_IP}
External: null
healthcheck:
test: python3 ./HealthCheck.py
start_period: 2s
interval: 60s
timeout: 1s
retries: 5
Loki:
image: investment/loki
build:
context: ./Loki
dockerfile: Loki.Dockerfile
container_name: ${LOKI_CONTAINER_NAME}
hostname: ${LOKI_HOSTNAME}
environment:
TZ: ${SYSTEM_TIME_ZONE}
restart: unless-stopped
volumes:
- ./Loki:/etc/loki
- ${APP_DATA_PATH}/${LOKI_PERSISTENT_STORAGE_DIR}:/loki
ports:
- "${LOKI_EXTERNAL_PORT}:3100"
networks:
Internal:
ipv4_address: ${LOKI_INTERNAL_IP}
External: null
healthcheck:
test: curl -s http://localhost:3100/ready | grep -q -w ready
start_period: 2s
interval: 2s
timeout: 1s
retries: 10
Promtail:
image: investment/promtail
build:
context: ./Promtail
dockerfile: Promtail.Dockerfile
depends_on:
Loki:
condition: service_healthy
container_name: ${PROMTAIL_CONTAINER_NAME}
hostname: ${PROMTAIL_HOSTNAME}
environment:
TZ: ${SYSTEM_TIME_ZONE}
restart: unless-stopped
volumes:
- ./Promtail:/etc/promtail
- ./${APP_DATA_PATH}/${PROMTAIL_PERSISTENT_STORAGE_DIR}:/var/lib/promtail
- ./${APP_LOG_PATH}:/APP_LOG
- ./${APP_DATA_PATH}:/APP_DATA
ports:
- ${PROMTAIL_EXTERNAL_PORT}:9080
networks:
Internal:
ipv4_address: "${PROMTAIL_INTERNAL_IP}"
External: null
healthcheck:
test: curl --fail http://${PROMTAIL_HOSTNAME}:9080
start_period: 2s
interval: 2s
timeout: 5s
retries: 10
networks:
Internal:
name: LAN
internal: true
ipam:
driver: default
config:
- subnet: "10.10.10.0/24"
gateway: 10.10.10.1
External:
name: WAN
ipam:
driver: default