/
/
/
Ansible role that deployes services on my runner machine
1# {{ ansible_managed }}
2#
3# Macro Checker: natural-language calorie and macro tracker.
4# App image built by the my_macro_checker repository's CI, pulled from Harbor.
5
6name: macros
7
8services:
9 macros:
10 container_name: macros
11 image: "{{ macros_image }}"
12 restart: unless-stopped
13 depends_on:
14 macros-db:
15 condition: service_healthy
16 env_file:
17 - macros.env
18 ports:
19 - "{{ macros_port }}:8000"
20 volumes:
21 - /etc/localtime:/etc/localtime:ro
22 # NEVO, read-only: the app imports it on start and never writes to it.
23 - {{ macros_nevo_dir }}:/data/nevo:ro
24 networks:
25 - macros
26 - {{ runner_docker_network }}
27 healthcheck:
28 test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
29 interval: 30s
30 timeout: 5s
31 retries: 3
32
33 macros-db:
34 container_name: macros-db
35 image: postgres:16-alpine
36 restart: unless-stopped
37 environment:
38 - POSTGRES_USER=macros
39 - POSTGRES_DB=macros
40 - POSTGRES_PASSWORD={{ macros_postgres_password }}
41 volumes:
42 # Local disk, not NFS: Postgres and NFS locking do not mix.
43 - {{ macros_db_dir }}:/var/lib/postgresql/data
44 networks:
45 - macros
46 healthcheck:
47 test: ["CMD-SHELL", "pg_isready -U macros -d macros"]
48 interval: 10s
49 timeout: 5s
50 retries: 5
51
52 # Nightly logical backup onto the share, {{ macros_backup_keep_days }} days kept.
53 macros-backup:
54 container_name: macros-backup
55 image: postgres:16-alpine
56 restart: unless-stopped
57 depends_on:
58 - macros-db
59 environment:
60 - PGPASSWORD={{ macros_postgres_password }}
61 - TZ={{ runner_timezone }}
62 volumes:
63 - {{ macros_backup_dir }}:/backups
64 networks:
65 - macros
66 entrypoint: ["/bin/sh", "-c"]
67 command:
68 - |
69 until pg_isready -q -h macros-db -U macros; do sleep 5; done
70 while true; do
71 f=/backups/macros-$$(date +%F).sql.gz
72 # Dump to a file first: in a `pg_dump | gzip` pipe a failed dump
73 # still leaves a valid (empty) gzip behind.
74 if pg_dump -h macros-db -U macros -f /tmp/dump.sql macros; then
75 gzip -c /tmp/dump.sql > "$$f.tmp" && mv "$$f.tmp" "$$f" && echo "backup $$f"
76 else
77 echo "backup FAILED" >&2
78 fi
79 rm -f /tmp/dump.sql
80 find /backups -name 'macros-*.sql.gz' -mtime +{{ macros_backup_keep_days }} -delete
81 sleep 86400
82 done
83
84 # Private search for the web-lookup fallback. No published port.
85 macros-searxng:
86 container_name: macros-searxng
87 image: "{{ macros_searxng_image }}"
88 restart: unless-stopped
89 environment:
90 - SEARXNG_SECRET={{ macros_searxng_secret }}
91 - SEARXNG_BASE_URL=http://macros-searxng:8080/
92 volumes:
93 - ./searxng/settings.yml:/etc/searxng/settings.yml:ro
94 networks:
95 - macros
96
97networks:
98 macros:
99 {{ runner_docker_network }}:
100 external: true
101