Skip to content

Commit 011cd8c

Browse files
committed
refactor: [#272] improve docker-compose template whitespace handling
- Use Tera whitespace trimming ({%- and -%}) to reduce excessive blank lines - Generated docker-compose.yml now has cleaner, more readable formatting - Single blank lines between services, compact network/volume sections
1 parent 56ad1dc commit 011cd8c

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

templates/docker-compose/docker-compose.yml.tera

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ x-defaults: &defaults
2929
max-file: "10"
3030

3131
services:
32-
{% if caddy %}
32+
{%- if caddy %}
3333
# Caddy reverse proxy for automatic HTTPS with Let's Encrypt
3434
# Placed first as it's the entry point for HTTPS traffic
3535
caddy:
@@ -45,17 +45,17 @@ services:
4545
- caddy_data:/data # TLS certificates (MUST persist!)
4646
- caddy_config_vol:/config
4747
networks:
48-
{% for network in caddy.networks %}
48+
{%- for network in caddy.networks %}
4949
- {{ network }}
50-
{% endfor %}
50+
{%- endfor %}
5151
healthcheck:
5252
test: ["CMD", "caddy", "validate", "--config", "/etc/caddy/Caddyfile"]
5353
interval: 10s
5454
timeout: 5s
5555
retries: 5
5656
start_period: 10s
57+
{%- endif %}
5758

58-
{% endif %}
5959
tracker:
6060
<<: *defaults
6161
# TODO: Pin to stable v4.0.0 when released (currently using develop tag)
@@ -64,20 +64,20 @@ services:
6464
# Pinning to a stable release ensures predictable deployments and easier rollback.
6565
image: torrust/tracker:develop
6666
container_name: tracker
67-
{% if mysql %}
67+
{%- if mysql %}
6868
depends_on:
6969
mysql:
7070
condition: service_healthy
71-
{% endif %}
71+
{%- endif %}
7272
environment:
7373
- USER_ID=1000
7474
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER}
7575
- TORRUST_TRACKER_CONFIG_TOML_PATH=${TORRUST_TRACKER_CONFIG_TOML_PATH}
7676
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN}
7777
networks:
78-
{% for network in tracker.networks %}
78+
{%- for network in tracker.networks %}
7979
- {{ network }}
80-
{% endfor %}
80+
{%- endfor %}
8181
{%- if tracker.needs_ports_section %}
8282
ports:
8383
# UDP Tracker Ports (always exposed - UDP doesn't use TLS)
@@ -97,16 +97,16 @@ services:
9797
- ./storage/tracker/lib:/var/lib/torrust/tracker:Z
9898
- ./storage/tracker/log:/var/log/torrust/tracker:Z
9999
- ./storage/tracker/etc:/etc/torrust/tracker:Z
100+
{%- if prometheus %}
100101

101-
{% if prometheus %}
102102
prometheus:
103103
<<: *defaults
104104
image: prom/prometheus:v3.5.0
105105
container_name: prometheus
106106
networks:
107-
{% for network in prometheus.networks %}
107+
{%- for network in prometheus.networks %}
108108
- {{ network }}
109-
{% endfor %}
109+
{%- endfor %}
110110
ports:
111111
- "127.0.0.1:9090:9090" # Localhost only - not exposed to external network
112112
# Grafana accesses Prometheus via Docker network: http://prometheus:9090
@@ -121,17 +121,17 @@ services:
121121
start_period: 10s
122122
depends_on:
123123
- tracker
124-
{% endif %}
124+
{%- endif %}
125+
{%- if grafana %}
125126

126-
{% if grafana %}
127127
grafana:
128128
<<: *defaults
129129
image: grafana/grafana:12.3.1
130130
container_name: grafana
131131
networks:
132-
{% for network in grafana.networks %}
132+
{%- for network in grafana.networks %}
133133
- {{ network }}
134-
{% endfor %}
134+
{%- endfor %}
135135
{%- if not grafana.has_tls %}
136136
ports:
137137
- "3100:3000"
@@ -149,15 +149,15 @@ services:
149149
retries: 5
150150
start_period: 30s
151151
depends_on:
152-
{% if prometheus %}
152+
{%- if prometheus %}
153153
prometheus:
154154
condition: service_healthy
155-
{% else %}
155+
{%- else %}
156156
- tracker
157-
{% endif %}
158-
{% endif %}
157+
{%- endif %}
158+
{%- endif %}
159+
{%- if mysql %}
159160

160-
{% if mysql %}
161161
mysql:
162162
<<: *defaults
163163
image: mysql:8.4
@@ -168,9 +168,9 @@ services:
168168
- MYSQL_USER=${MYSQL_USER}
169169
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
170170
networks:
171-
{% for network in mysql.networks %}
171+
{%- for network in mysql.networks %}
172172
- {{ network }}
173-
{% endfor %}
173+
{%- endfor %}
174174
ports:
175175
- "3306:3306"
176176
volumes:
@@ -182,7 +182,7 @@ services:
182182
timeout: 5s
183183
retries: 5
184184
start_period: 30s
185-
{% endif %}
185+
{%- endif %}
186186

187187
# SECURITY: Three-Network Segmentation (Defense in Depth)
188188
# =========================================================
@@ -212,24 +212,25 @@ services:
212212
# See Analysis: docs/analysis/security/docker-network-segmentation-analysis.md
213213

214214
networks:
215-
{% if mysql %}
215+
{%- if mysql %}
216216
database_network:
217217
driver: bridge
218-
{% endif %}
219-
{% if prometheus %}
218+
{%- endif %}
219+
{%- if prometheus %}
220220
metrics_network:
221221
driver: bridge
222-
{% endif %}
223-
{% if grafana %}
222+
{%- endif %}
223+
{%- if grafana %}
224224
visualization_network:
225225
driver: bridge
226-
{% endif %}
227-
{% if caddy %}
226+
{%- endif %}
227+
{%- if caddy %}
228228
proxy_network:
229229
driver: bridge
230-
{% endif %}
230+
{%- endif %}
231+
231232

232-
{% if mysql or grafana or caddy %}
233+
{%- if mysql or grafana or caddy %}
233234
volumes:
234235
{%- if mysql %}
235236
mysql_data:

0 commit comments

Comments
 (0)