0 Votes

Code source wiki de Dawarich

Modifié par john le 2026/09/23 20:01

Afficher les derniers auteurs
1 Historique de localisation auto-hébergé, alternative à Google Timeline. Le géocodage inverse (adresse et nom des lieux) est assuré par une instance Photon locale, sans service externe ni limite de requêtes.
2
3 == Architecture ==
4
5 |=Conteneur|=Rôle
6 |dawarich_app|Application web (Rails)
7 |dawarich_sidekiq|Tâches de fond : imports, détection des visites, géocodage
8 |dawarich_db|PostgreSQL + PostGIS
9 |dawarich_redis|File de tâches
10 |photon|Géocodage inverse, stack séparée
11
12 Dawarich et Photon communiquent par le réseau ##proxy##, sur lequel se trouve aussi SWAG.
13
14 == Variables d'environnement ==
15
16 À définir dans l'onglet « Environment variables » de la stack Portainer :
17
18 |=Variable|=Valeur
19 |##POSTGRES_USER##|Utilisateur de la base
20 |##POSTGRES_PASSWORD##|Mot de passe de la base
21 |##POSTGRES_DB##|Nom de la base
22 |##APPLICATION_HOSTS##|Nom de domaine d'accès
23 |##SECRET_KEY_BASE##|Clé générée avec ##openssl rand -hex 64##
24
25 == Stack Dawarich ==
26
27 {{code language="yaml"}}
28 name: dawarich
29
30 networks:
31 dawarich:
32 proxy:
33 external: true
34
35 services:
36 dawarich_redis:
37 image: redis:7.4-alpine
38 container_name: dawarich_redis
39 command: >
40 redis-server
41 --save 900 1
42 --save 300 10
43 --appendonly no
44 networks:
45 - dawarich
46 volumes:
47 - dawarich_shared:/data
48 restart: always
49 healthcheck:
50 test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
51 interval: 10s
52 retries: 5
53 start_period: 30s
54 timeout: 10s
55
56 dawarich_db:
57 image: postgis/postgis:17-3.5-alpine
58 shm_size: 1G
59 container_name: dawarich_db
60 volumes:
61 - dawarich_db_data:/var/lib/postgresql/data
62 - dawarich_shared:/var/shared
63 networks:
64 - dawarich
65 environment:
66 POSTGRES_USER: ${POSTGRES_USER}
67 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
68 POSTGRES_DB: ${POSTGRES_DB}
69 restart: always
70 healthcheck:
71 test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
72 interval: 10s
73 retries: 5
74 start_period: 30s
75 timeout: 10s
76
77 dawarich_app:
78 image: freikin/dawarich:latest
79 container_name: dawarich_app
80 volumes:
81 - dawarich_public:/var/app/public
82 - dawarich_watched:/var/app/tmp/imports/watched
83 - dawarich_storage:/var/app/storage
84 - dawarich_db_data:/dawarich_db_data
85 networks:
86 - dawarich
87 - proxy
88 ports:
89 - "3001:3000"
90 stdin_open: true
91 tty: true
92 entrypoint: web-entrypoint.sh
93 command: ['bin/rails', 'server', '-p', '3000', '-b', '::']
94 restart: unless-stopped
95 environment:
96 RAILS_ENV: production
97 REDIS_URL: redis://dawarich_redis:6379
98 DATABASE_HOST: dawarich_db
99 DATABASE_PORT: 5432
100 DATABASE_USERNAME: ${POSTGRES_USER}
101 DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
102 DATABASE_NAME: ${POSTGRES_DB}
103 APPLICATION_HOSTS: ${APPLICATION_HOSTS}
104 TIME_ZONE: Europe/Paris
105 APPLICATION_PROTOCOL: https
106 PROMETHEUS_EXPORTER_ENABLED: "false"
107 SECRET_KEY_BASE: ${SECRET_KEY_BASE}
108 RAILS_LOG_TO_STDOUT: "true"
109 SELF_HOSTED: "true"
110 STORE_GEODATA: "true"
111 PHOTON_API_HOST: photon:2322
112 PHOTON_API_USE_HTTPS: "false"
113 logging:
114 driver: "json-file"
115 options:
116 max-size: 100m
117 max-file: "5"
118 healthcheck:
119 test: [ "CMD-SHELL", "wget -qO - --header='X-Forwarded-Proto: https' http://127.0.0.1:3000/api/v1/health | grep -q '\"status\"\\s*:\\s*\"ok\"'" ]
120 interval: 10s
121 retries: 30
122 start_period: 30s
123 timeout: 10s
124 depends_on:
125 dawarich_db:
126 condition: service_healthy
127 restart: true
128 dawarich_redis:
129 condition: service_healthy
130 restart: true
131 deploy:
132 resources:
133 limits:
134 cpus: "0.50"
135 memory: 4G
136
137 dawarich_sidekiq:
138 image: freikin/dawarich:latest
139 container_name: dawarich_sidekiq
140 volumes:
141 - dawarich_public:/var/app/public
142 - dawarich_watched:/var/app/tmp/imports/watched
143 - dawarich_storage:/var/app/storage
144 networks:
145 - dawarich
146 - proxy
147 stdin_open: true
148 tty: true
149 entrypoint: sidekiq-entrypoint.sh
150 command: ['sidekiq']
151 restart: on-failure
152 environment:
153 RAILS_ENV: production
154 REDIS_URL: redis://dawarich_redis:6379
155 DATABASE_HOST: dawarich_db
156 DATABASE_PORT: 5432
157 DATABASE_USERNAME: ${POSTGRES_USER}
158 DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
159 DATABASE_NAME: ${POSTGRES_DB}
160 APPLICATION_HOSTS: ${APPLICATION_HOSTS}
161 BACKGROUND_PROCESSING_CONCURRENCY: "5"
162 APPLICATION_PROTOCOL: https
163 PROMETHEUS_EXPORTER_ENABLED: "false"
164 SECRET_KEY_BASE: ${SECRET_KEY_BASE}
165 RAILS_LOG_TO_STDOUT: "true"
166 SELF_HOSTED: "true"
167 STORE_GEODATA: "true"
168 PHOTON_API_HOST: photon:2322
169 PHOTON_API_USE_HTTPS: "false"
170 logging:
171 driver: "json-file"
172 options:
173 max-size: 100m
174 max-file: "5"
175 healthcheck:
176 test: [ "CMD-SHELL", "pgrep -f sidekiq" ]
177 interval: 10s
178 retries: 30
179 start_period: 30s
180 timeout: 10s
181 depends_on:
182 dawarich_db:
183 condition: service_healthy
184 restart: true
185 dawarich_redis:
186 condition: service_healthy
187 restart: true
188 dawarich_app:
189 condition: service_healthy
190 restart: true
191
192 volumes:
193 dawarich_db_data:
194 dawarich_shared:
195 dawarich_public:
196 dawarich_watched:
197 dawarich_storage:
198 {{/code}}
199
200 Points particuliers :
201
202 * Port hôte 3001 : le 3000 est déjà pris sur le serveur.
203 * L'en-tête ##X-Forwarded-Proto: https## du healthcheck est indispensable avec ##APPLICATION_PROTOCOL: https##, sinon sidekiq ne démarre jamais (voir [[Dépannage>>Wiki Batcave John.Infrastructure.ServeurPrincipal.Depannage.WebHome]]).
204 * ##PHOTON_API_HOST## et ##PHOTON_API_USE_HTTPS## doivent être présents sur **app et sidekiq**.
205
206 == Géocodage ==
207
208 Le géocodage inverse est assuré par une instance Photon locale, dans une stack séparée : voir [[Photon>>Wiki Batcave John.Infrastructure.ServeurPrincipal.Photon.WebHome]].
209
210 == Accès ==
211
212 Publié par SWAG sur un sous-domaine, avec un proxy-conf écrit à la main (SWAG n'en fournit pas pour Dawarich) : voir l'exemple commenté sur la page [[Reverse proxy>>Wiki Batcave John.Infrastructure.ServeurPrincipal.ReverseProxy.WebHome]].
213
214 Pas d'Authelia : l'accès est protégé par l'identifiant de Dawarich. Les chemins ##/api## (applications mobiles de suivi) et ##/cable## (mises à jour en direct) ont chacun leur bloc ##location##.
215
216 == Import de l'historique ==
217
218 * Source fiable : les fichiers JSON exportés directement depuis l'application Google Maps du téléphone.
219 * L'archive Google Takeout ne contient plus la Timeline : seulement des métadonnées de photos, qui créent un point par photo. Ne pas l'importer.
220
221 == Console Rails ==
222
223 {{code language="bash"}}
224 docker exec -it dawarich_app bin/rails console
225 {{/code}}
226
227 Utile pour les opérations en masse ; exemples dans [[Dépannage>>Wiki Batcave John.Infrastructure.ServeurPrincipal.Depannage.WebHome]].
228
229 == Lieux et tags ==
230
231 * Un tag s'applique à un **lieu**, jamais à un point ni à une zone.
232 * Le rayon d'un tag est un rayon de confidentialité : les points qu'il contient sont masqués dans les exports et les vues publiques.
233
234 == Sauvegarde ==
235
236 Les données sont dans des volumes Docker nommés, hors du dossier sauvegardé. Seul le dump SQL de ##dawarich_db## les protège : il doit figurer dans la boucle PostgreSQL du script de [[Sauvegarde>>Wiki Batcave John.Infrastructure.Sauvegarde.WebHome]].