trek 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. checksums.yaml +4 -4
  2. data/.node-version +1 -1
  3. data/AGENTS.md +18 -14
  4. data/CHANGELOG.md +88 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +135 -124
  7. data/Makefile +9 -1
  8. data/README.md +17 -21
  9. data/app/components/trek/dashboard/tile_component/tile_component.css +9 -0
  10. data/app/components/trek/dashboard/tile_component/tile_component.html.slim +4 -2
  11. data/app/components/trek/dashboard/tile_component.rb +12 -2
  12. data/app/components/trek/form/content_editor_component/content_editor_component.css +9 -8
  13. data/app/components/trek/form/content_editor_component/content_editor_component.html.slim +19 -93
  14. data/app/components/trek/form/content_editor_component/content_editor_component.js +94 -251
  15. data/app/components/trek/form/content_editor_component/extensions/block_view.js +40 -0
  16. data/app/components/trek/form/content_editor_component/extensions/image_block.js +28 -26
  17. data/app/components/trek/form/content_editor_component/extensions/prompts_block.js +15 -26
  18. data/app/components/trek/form/content_editor_component/extensions/table_of_contents.js +1 -3
  19. data/app/components/trek/form/content_editor_component.rb +15 -0
  20. data/app/components/trek/form/image_field_component/image_field_component.css +40 -1
  21. data/app/components/trek/form/image_field_component/image_field_component.html.slim +0 -9
  22. data/app/components/trek/form/image_field_component/image_field_component.js +1 -2
  23. data/app/components/trek/form/image_field_component.rb +36 -9
  24. data/app/components/trek/form/password_strength_component/password_strength_component.css +2 -0
  25. data/app/components/trek/form/sound_field_component/sound_field_component.js +1 -2
  26. data/app/components/trek/security_check_component/security_check_component.css +69 -0
  27. data/app/components/trek/security_check_component/security_check_component.html.slim +19 -0
  28. data/app/components/trek/security_check_component/security_check_component.js +15 -0
  29. data/app/components/trek/security_check_component.rb +19 -0
  30. data/app/content/trek/content/cleaner.rb +53 -0
  31. data/app/content/trek/content/document.rb +2 -2
  32. data/app/content/trek/content/list_item.rb +1 -1
  33. data/app/content/trek/content/paragraph.rb +7 -2
  34. data/app/content/trek/content/prompts_block.rb +1 -2
  35. data/app/content/trek/content.rb +6 -0
  36. data/app/controllers/concerns/trek/auditable.rb +5 -2
  37. data/app/controllers/concerns/trek/localization.rb +6 -2
  38. data/app/controllers/concerns/trek/reorderable.rb +24 -6
  39. data/app/controllers/trek/csp_reports_controller.rb +14 -1
  40. data/app/controllers/trek/panels/prompts_controller.rb +1 -1
  41. data/app/controllers/trek/resource_controller.rb +5 -5
  42. data/app/jobs/trek/purge_expired_sessions_job.rb +4 -3
  43. data/app/jobs/trek/purge_expired_sign_in_codes_job.rb +15 -0
  44. data/app/models/concerns/trek/contentable.rb +15 -1
  45. data/app/models/concerns/trek/users/sign_in_code.rb +70 -0
  46. data/app/models/concerns/trek/users/sign_in_lockout.rb +4 -2
  47. data/app/policies/trek/security_check_policy.rb +8 -0
  48. data/app/uploaders/image_uploader.rb +77 -15
  49. data/app/views/trek/panels/links/_form.html.slim +2 -4
  50. data/app/views/trek/panels/prompts/create.turbo_stream.slim +0 -1
  51. data/config/locales/trek.en.yml +97 -11
  52. data/config/locales/trek.fr.yml +97 -11
  53. data/docs/.vitepress/config.mjs +5 -1
  54. data/docs/background-jobs.md +74 -0
  55. data/docs/content-editor.md +219 -0
  56. data/docs/customize.md +2 -0
  57. data/docs/deploy.md +69 -6
  58. data/docs/getting-started.md +16 -18
  59. data/docs/index.md +2 -2
  60. data/docs/personal-data.md +61 -0
  61. data/docs/proxies.md +2 -2
  62. data/docs/reference/components.md +4 -4
  63. data/docs/reference/concerns/contentable.md +10 -4
  64. data/docs/reference/concerns/formattable.md +1 -1
  65. data/docs/reference/concerns/fragmentable.md +12 -6
  66. data/docs/reference/concerns/orderable.md +2 -2
  67. data/docs/reference/concerns/search-engine-optimizable.md +1 -1
  68. data/docs/reference/concerns/searchable.md +14 -1
  69. data/docs/reference/concerns/sectionable.md +7 -3
  70. data/docs/reference/concerns/versionable.md +1 -1
  71. data/docs/reference/controllers.md +33 -1
  72. data/docs/reference/environment-variables.md +3 -2
  73. data/docs/reference/formatters.md +4 -31
  74. data/docs/reference/forms.md +7 -4
  75. data/docs/reference/generators/admin-user.md +1 -1
  76. data/docs/reference/generators/audit-log.md +12 -13
  77. data/docs/reference/generators/install.md +23 -11
  78. data/docs/reference/generators/public-accounts.md +159 -0
  79. data/docs/reference/generators/scaffold.md +28 -9
  80. data/docs/reference/generators/security-headers.md +5 -4
  81. data/docs/reference/generators/taxonomies.md +1 -1
  82. data/docs/reference/icons.md +5 -3
  83. data/docs/reference/index.md +10 -7
  84. data/docs/reference/models/current.md +5 -3
  85. data/docs/reference/models/page-version.md +1 -1
  86. data/docs/reference/models/user.md +7 -8
  87. data/docs/reference/uploaders.md +25 -0
  88. data/docs/reference/validators.md +1 -1
  89. data/docs/security.md +30 -9
  90. data/docs/what-is-trek.md +4 -4
  91. data/lib/generators/trek/USAGE +1 -1
  92. data/lib/generators/trek/audit_log_generator.rb +62 -0
  93. data/lib/generators/trek/helpers.rb +17 -0
  94. data/lib/generators/trek/install/admin/routes_generator.rb +2 -1
  95. data/lib/generators/trek/install/admin/security_check_generator.rb +36 -0
  96. data/lib/generators/trek/install/admin/users_generator.rb +6 -1
  97. data/lib/generators/trek/install/audit_log_generator.rb +9 -45
  98. data/lib/generators/trek/install/ci_generator.rb +19 -0
  99. data/lib/generators/trek/install/good_job_generator.rb +161 -0
  100. data/lib/generators/trek/install/model_specs_generator.rb +3 -3
  101. data/lib/generators/trek/install/postcss_generator.rb +1 -2
  102. data/lib/generators/trek/install/ruby_generator.rb +1 -1
  103. data/lib/generators/trek/install/scalingo_generator.rb +7 -45
  104. data/lib/generators/trek/install/translations_generator.rb +1 -2
  105. data/lib/generators/trek/install_generator.rb +18 -2
  106. data/lib/generators/trek/public_accounts_generator.rb +294 -0
  107. data/lib/generators/trek/scaffold_generator.rb +22 -21
  108. data/lib/generators/trek/scalingo_generator.rb +67 -0
  109. data/lib/generators/trek/templates/.gitlab-ci.yml +10 -1
  110. data/lib/generators/trek/templates/AGENTS.md +2 -2
  111. data/lib/generators/trek/templates/Makefile +1 -0
  112. data/lib/generators/trek/templates/config/i18n-tasks.yml.erb +0 -8
  113. data/lib/generators/trek/templates/controllers/admin/password_renewals_controller.rb +11 -0
  114. data/lib/generators/trek/templates/controllers/admin/security_checks_controller.rb +11 -0
  115. data/lib/generators/trek/templates/controllers/admin/user_sessions_controller.rb +1 -1
  116. data/lib/generators/trek/templates/controllers/admin/users_controller.rb +0 -8
  117. data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +13 -4
  118. data/lib/generators/trek/templates/initializers/content_security_policy.rb +3 -2
  119. data/lib/generators/trek/templates/initializers/good_job.rb.tt +40 -0
  120. data/lib/generators/trek/templates/jobs/mail_delivery_job.rb +6 -0
  121. data/lib/generators/trek/templates/layouts/admin.html.slim +10 -0
  122. data/lib/generators/trek/templates/mailers/admin_mailer.rb +4 -2
  123. data/lib/generators/trek/templates/package.json.tt +1 -1
  124. data/lib/generators/trek/templates/policies/security_check.rb +4 -0
  125. data/lib/generators/trek/templates/public_accounts/api/authentication.rb.tt +76 -0
  126. data/lib/generators/trek/templates/public_accounts/api/controllers/accounts_controller.rb.tt +22 -0
  127. data/lib/generators/trek/templates/public_accounts/api/controllers/active_sessions_controller.rb.tt +21 -0
  128. data/lib/generators/trek/templates/public_accounts/api/controllers/base_controller.rb.tt +71 -0
  129. data/lib/generators/trek/templates/public_accounts/api/controllers/email_changes_controller.rb.tt +55 -0
  130. data/lib/generators/trek/templates/public_accounts/api/controllers/email_confirmations_controller.rb.tt +19 -0
  131. data/lib/generators/trek/templates/public_accounts/api/controllers/password_resets_controller.rb.tt +28 -0
  132. data/lib/generators/trek/templates/public_accounts/api/controllers/passwords_controller.rb.tt +17 -0
  133. data/lib/generators/trek/templates/public_accounts/api/controllers/registrations_controller.rb.tt +17 -0
  134. data/lib/generators/trek/templates/public_accounts/api/controllers/sessions_controller.rb.tt +57 -0
  135. data/lib/generators/trek/templates/public_accounts/api/controllers/sign_in_codes_controller.rb.tt +20 -0
  136. data/lib/generators/trek/templates/public_accounts/jobs/sign_in_code_job.rb.tt +23 -0
  137. data/lib/generators/trek/templates/public_accounts/locales/accounts.en.yml.tt +215 -0
  138. data/lib/generators/trek/templates/public_accounts/locales/accounts.fr.yml.tt +215 -0
  139. data/lib/generators/trek/templates/public_accounts/mailers/account_mailer.rb.tt +85 -0
  140. data/lib/generators/trek/templates/public_accounts/migrations/create_accounts.rb.tt +46 -0
  141. data/lib/generators/trek/templates/public_accounts/models/account/session.rb.tt +47 -0
  142. data/lib/generators/trek/templates/public_accounts/models/account/sign_in_code.rb.tt +8 -0
  143. data/lib/generators/trek/templates/public_accounts/models/account.rb.tt +87 -0
  144. data/lib/generators/trek/templates/public_accounts/spec/api/accounts_spec.rb.tt +90 -0
  145. data/lib/generators/trek/templates/public_accounts/spec/api/sign_ins_spec.rb.tt +188 -0
  146. data/lib/generators/trek/templates/public_accounts/spec/models/account/sign_in_code_spec.rb.tt +66 -0
  147. data/lib/generators/trek/templates/public_accounts/spec/models/account_spec.rb.tt +129 -0
  148. data/lib/generators/trek/templates/public_accounts/spec/web/accounts_spec.rb.tt +126 -0
  149. data/lib/generators/trek/templates/public_accounts/spec/web/authentication_spec.rb.tt +43 -0
  150. data/lib/generators/trek/templates/public_accounts/spec/web/sign_ins_spec.rb.tt +237 -0
  151. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.html.slim.tt +10 -0
  152. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.text.erb.tt +8 -0
  153. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.html.slim.tt +13 -0
  154. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.text.erb.tt +8 -0
  155. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.html.slim.tt +9 -0
  156. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.text.erb.tt +11 -0
  157. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.html.slim.tt +11 -0
  158. data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.text.erb.tt +11 -0
  159. data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.html.slim.tt +10 -0
  160. data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.text.erb.tt +8 -0
  161. data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.html.slim.tt +10 -0
  162. data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.text.erb.tt +8 -0
  163. data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.html.slim.tt +10 -0
  164. data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.text.erb.tt +8 -0
  165. data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.html.slim.tt +13 -0
  166. data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.text.erb.tt +8 -0
  167. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.html.slim.tt +9 -0
  168. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.text.erb.tt +11 -0
  169. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.html.slim.tt +9 -0
  170. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.text.erb.tt +11 -0
  171. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.html.slim.tt +23 -0
  172. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.text.erb.tt +14 -0
  173. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.html.slim.tt +24 -0
  174. data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.text.erb.tt +14 -0
  175. data/lib/generators/trek/templates/public_accounts/web/authentication.rb.tt +97 -0
  176. data/lib/generators/trek/templates/public_accounts/web/controllers/accounts_controller.rb.tt +33 -0
  177. data/lib/generators/trek/templates/public_accounts/web/controllers/active_sessions_controller.rb.tt +15 -0
  178. data/lib/generators/trek/templates/public_accounts/web/controllers/base_controller.rb.tt +52 -0
  179. data/lib/generators/trek/templates/public_accounts/web/controllers/email_changes_controller.rb.tt +85 -0
  180. data/lib/generators/trek/templates/public_accounts/web/controllers/email_confirmations_controller.rb.tt +19 -0
  181. data/lib/generators/trek/templates/public_accounts/web/controllers/password_resets_controller.rb.tt +41 -0
  182. data/lib/generators/trek/templates/public_accounts/web/controllers/passwords_controller.rb.tt +23 -0
  183. data/lib/generators/trek/templates/public_accounts/web/controllers/registrations_controller.rb.tt +24 -0
  184. data/lib/generators/trek/templates/public_accounts/web/controllers/sessions_controller.rb.tt +85 -0
  185. data/lib/generators/trek/templates/public_accounts/web/controllers/sign_in_codes_controller.rb.tt +32 -0
  186. data/lib/generators/trek/templates/public_accounts/web/views/_flash.html.slim.tt +5 -0
  187. data/lib/generators/trek/templates/public_accounts/web/views/accounts/show.html.slim.tt +52 -0
  188. data/lib/generators/trek/templates/public_accounts/web/views/email_changes/edit.html.slim.tt +17 -0
  189. data/lib/generators/trek/templates/public_accounts/web/views/email_changes/new.html.slim.tt +15 -0
  190. data/lib/generators/trek/templates/public_accounts/web/views/password_resets/edit.html.slim.tt +29 -0
  191. data/lib/generators/trek/templates/public_accounts/web/views/password_resets/new.html.slim.tt +15 -0
  192. data/lib/generators/trek/templates/public_accounts/web/views/passwords/edit.html.slim.tt +28 -0
  193. data/lib/generators/trek/templates/public_accounts/web/views/registrations/new.html.slim.tt +30 -0
  194. data/lib/generators/trek/templates/public_accounts/web/views/sessions/new.html.slim.tt +40 -0
  195. data/lib/generators/trek/templates/public_accounts/web/views/sign_in_codes/new.html.slim.tt +17 -0
  196. data/lib/generators/trek/templates/spec/jobs/mail_delivery_job_spec.rb +11 -0
  197. data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +10 -0
  198. data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +1 -1
  199. data/lib/generators/trek/templates/spec/requests/admin/good_job_spec.rb +34 -0
  200. data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +12 -1
  201. data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +16 -0
  202. data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +2 -2
  203. data/lib/generators/trek/templates/spec/requests/admin/security_checks_spec.rb +24 -0
  204. data/lib/generators/trek/templates/spec/requests/admin/sign_in_lockout_spec.rb +1 -1
  205. data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +33 -0
  206. data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +2 -2
  207. data/lib/generators/trek/templates/views/admin/pages/_form.html.slim +1 -1
  208. data/lib/generators/trek/templates/views/admin/security_checks/show.html.slim +9 -0
  209. data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +6 -1
  210. data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +4 -1
  211. data/lib/generators/trek/templates/views/admin/users/index.html.slim +1 -1
  212. data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.html.slim +1 -1
  213. data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.text.erb +1 -1
  214. data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.html.slim +1 -1
  215. data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.text.erb +1 -1
  216. data/lib/tasks/trek/attachments.rake +12 -0
  217. data/lib/tasks/trek/security.rake +10 -0
  218. data/lib/trek/csp_reports.rb +22 -4
  219. data/lib/trek/disposable_email_domains.rb +9 -20
  220. data/lib/trek/engine.rb +5 -0
  221. data/lib/trek/json_compatibility.rb +20 -0
  222. data/lib/trek/security_check.rb +241 -0
  223. data/lib/trek/stored_image_metadata.rb +88 -0
  224. data/lib/trek/typography_formatter.rb +35 -4
  225. data/lib/trek/version.rb +1 -1
  226. data/lib/trek.rb +2 -1
  227. data/package.json +16 -13
  228. data/postcss.config.js +0 -3
  229. data/trek.gemspec +6 -7
  230. data/vitest.config.mjs +24 -0
  231. data/yarn.lock +1667 -1010
  232. metadata +122 -33
@@ -6,23 +6,23 @@ fr:
6
6
  alt: Texte alternatif
7
7
  credit: Crédit
8
8
  file: Image
9
- size: Taille
10
- text: Légende
9
+ size: Largeur d'affichage
10
+ text: Légende de l'image
11
11
  trek/content_editor/link:
12
- href: Adresse
13
- target: Ouvrir dans
14
- text: Texte
12
+ href: Lien vers
13
+ target: Ouvrir ce lien dans…
14
+ text: Texte du lien
15
15
  title: Titre
16
16
  trek/content_editor/prompt:
17
- href: Adresse
18
- target: Ouvrir dans
19
- text: Texte
17
+ href: Lien vers
18
+ target: Ouvrir ce lien dans…
19
+ text: Texte du bouton
20
20
  title: Titre
21
21
  options:
22
22
  trek/content_editor/image:
23
23
  size:
24
24
  default: Comme la colonne de texte
25
- larger: Plus large
25
+ larger: Dépasse sur les côtés
26
26
  activerecord:
27
27
  attributes:
28
28
  audit_log:
@@ -94,6 +94,7 @@ fr:
94
94
  browse: Parcourir…
95
95
  cancel: Annuler
96
96
  delete: Supprimer
97
+ download_original: Télécharger l'original
97
98
  edit: Éditer
98
99
  logout: Se déconnecter
99
100
  manage: Gérer
@@ -187,6 +188,7 @@ fr:
187
188
  intro: Fragment
188
189
  update:
189
190
  success: Fragment mis à jour
191
+ jobs: Tâches de fond
190
192
  metadata: Métadonnées
191
193
  navigation: Navigation
192
194
  pages:
@@ -237,6 +239,9 @@ fr:
237
239
  success: Clé d'accès ajoutée
238
240
  destroy:
239
241
  success: Clé d'accès supprimée
242
+ password_renewals:
243
+ create:
244
+ success: Chaque utilisateur devra choisir un nouveau mot de passe
240
245
  passwords_mailer:
241
246
  reset:
242
247
  subject: Nouveau mot de passe
@@ -251,6 +256,10 @@ fr:
251
256
  success: Section ajoutée
252
257
  update:
253
258
  success: Section mise à jour
259
+ security_checks:
260
+ show:
261
+ intro: Vérifié le %{time}, avec Trek %{trek} et Rails %{rails}, par rapport aux réglages recommandés
262
+ title: Sécurité
254
263
  seo: SEO
255
264
  settings: Paramètres
256
265
  user_password_resets:
@@ -298,8 +307,6 @@ fr:
298
307
  last_used: Utilisée il y a %{time}
299
308
  never_used: Jamais utilisée
300
309
  title: Se connecter sans mot de passe
301
- require_password_renewal:
302
- success: Chaque utilisateur devra choisir un nouveau mot de passe
303
310
  search:
304
311
  alert: Utilisateur non trouvé avec cette adresse e-mail
305
312
  sessions:
@@ -333,6 +340,18 @@ fr:
333
340
  errors:
334
341
  messages:
335
342
  disposable: est une adresse e-mail jetable, utilisez-en une permanente
343
+ helpers:
344
+ hint:
345
+ trek/content_editor/image:
346
+ alt: Pour l'accessibilité et le référencement, décrire le contenu de l'image, sans répéter le texte de la légende
347
+ credit: Indiquer le nom de l'auteur
348
+ text: Sera affichée sous l'image
349
+ trek/content_editor/link:
350
+ href: Choisir une page ou entrer une URL
351
+ title: Affiché au survol, utile pour l'accessibilité et le référencement
352
+ trek/content_editor/prompt:
353
+ href: Choisir une page ou entrer une URL
354
+ title: Affiché au survol, utile pour l'accessibilité et le référencement
336
355
  notices:
337
356
  authentication_needed: Veuillez vous connecter
338
357
  password_renewal_needed: "Votre mot de passe doit être renouvelé : choisissez-en un nouveau"
@@ -378,6 +397,73 @@ fr:
378
397
  search_component:
379
398
  reset: Réinitialiser la recherche
380
399
  search: Rechercher
400
+ security_check:
401
+ admin_allowed_ips:
402
+ set: L’admin est réservée à %{count} adresses ou plages d’adresses IP (`ADMIN_ALLOWED_IPS`)
403
+ unset: L’admin est ouverte à toutes les adresses IP (`ADMIN_ALLOWED_IPS` n’est pas défini)
404
+ admins:
405
+ count: "%{privileged} utilisateurs peuvent se connecter à l’admin, dont %{admins} avec le rôle admin"
406
+ audit_log:
407
+ not_installed: Pas de journal d’audit (`bin/rails g trek:audit_log`)
408
+ not_purged: La purge du journal d’audit n’est pas planifiée (`Trek::AuditLog::PurgeJob` dans le cron de GoodJob)
409
+ purge_unknown: La purge du journal d’audit ne peut pas être vérifiée avec ce gestionnaire de tâches (`Trek::AuditLog::PurgeJob`)
410
+ purged: Journal d’audit installé, sa purge planifiée
411
+ cache_store:
412
+ per_process: Le cache (`%{store}`) n’est pas partagé par les processus de l’app, ce que les limites de connexion demandent
413
+ per_server: Le cache (`%{store}`) n’est pas partagé par les serveurs de l’app, ce que les limites de connexion demandent
414
+ shared: Cache partagé par les processus de l’app (`%{store}`)
415
+ content_security_policy:
416
+ enforced: Content Security Policy appliquée
417
+ none: Pas de Content Security Policy (`bin/rails g trek:install:security_headers`)
418
+ report_only: La Content Security Policy ne fait que signaler les violations (`content_security_policy_report_only`)
419
+ cron:
420
+ disabled: "Le cron de GoodJob est désactivé (`enable_cron`) : les tâches planifiées ne sont jamais lancées"
421
+ enabled: Le cron de GoodJob est activé
422
+ other_backend: Les tâches planifiées ne peuvent pas être vérifiées avec ce gestionnaire de tâches (`%{adapter}`)
423
+ dormant:
424
+ none: Tous les utilisateurs de l’admin se sont connectés il y a moins de %{duration}
425
+ some:
426
+ one: "%{count} utilisateur de l’admin ne s’est pas connecté depuis %{duration}"
427
+ other: "%{count} utilisateurs de l’admin ne se sont pas connectés depuis %{duration}"
428
+ encryption:
429
+ configured: Clés d’Active Record Encryption configurées
430
+ not_configured: Pas de clés d’Active Record Encryption (`bin/rails db:encryption:init`)
431
+ header: |-
432
+ Vérification de sécurité de %{app}, %{environment}, %{time}
433
+ Trek %{trek}, Rails %{rails}, Ruby %{ruby}
434
+ https:
435
+ no_hsts: HTTPS imposé, mais sans HSTS (`config.ssl_options`)
436
+ "off": HTTPS n’est pas imposé (`config.force_ssl`)
437
+ "on": HTTPS imposé, avec HSTS pendant %{duration}
438
+ passkeys:
439
+ all: Tous les utilisateurs de l’admin ont une clé d’accès
440
+ password_only:
441
+ one: "%{count} utilisateur de l’admin se connecte avec un mot de passe seul, sans clé d’accès"
442
+ other: "%{count} utilisateurs de l’admin se connectent avec un mot de passe seul, sans clé d’accès"
443
+ password_expiry:
444
+ after: Les mots de passe expirent après %{duration}
445
+ never: Les mots de passe n’expirent jamais (`password_expires_after`)
446
+ remote_ip:
447
+ cdn: "Rails voit votre adresse IP comme %{ip}, mais le CDN transmet %{forwarded} : ajoutez ses plages à `trusted_proxies`"
448
+ seen: "Rails voit votre adresse IP comme %{ip} : vérifiez que c’est la vôtre, et non celle du proxy de votre réseau ou du CDN"
449
+ request_https:
450
+ http: "Cette page est arrivée à l’app en HTTP : le proxy devant elle doit transmettre le protocole (`X-Forwarded-Proto`)"
451
+ https: Cette page est arrivée à l’app en HTTPS
452
+ session_purge:
453
+ not_scheduled: La purge des sessions expirées n’est pas planifiée (`Trek::PurgeExpiredSessionsJob` dans le cron de GoodJob)
454
+ scheduled: Purge des sessions expirées planifiée
455
+ unknown: La purge des sessions expirées ne peut pas être vérifiée avec ce gestionnaire de tâches (`Trek::PurgeExpiredSessionsJob`)
456
+ summary: "%{ok} ok, %{info} pour information, %{warning} avertissements, %{failure} échecs"
457
+ trusted_proxies:
458
+ default: "Pas de proxys de confiance en dehors des réseaux privés (`trusted_proxies`) : à définir quand un CDN est devant l’app"
459
+ set: "%{count} proxys de confiance (`trusted_proxies`)"
460
+ security_check_component:
461
+ docs: Documentation
462
+ statuses:
463
+ failure: Échec
464
+ info: Information
465
+ ok: OK
466
+ warning: Avertissement
381
467
  user_agents:
382
468
  browser_on_system: "%{browser} sur %{system}"
383
469
  unknown: Navigateur inconnu
@@ -53,9 +53,12 @@ export default defineConfig({
53
53
  text: 'Guides',
54
54
  items: [
55
55
  { text: 'How to customize Trek', link: '/customize' },
56
+ { text: 'Content editor', link: '/content-editor' },
56
57
  { text: 'Deploying to Scalingo', link: '/deploy' },
57
58
  { text: 'IP addresses behind a proxy', link: '/proxies' },
58
- { text: 'Security and compliance', link: '/security' }
59
+ { text: 'Security and compliance', link: '/security' },
60
+ { text: 'Personal data', link: '/personal-data' },
61
+ { text: 'Background jobs', link: '/background-jobs' }
59
62
  ]
60
63
  },
61
64
  {
@@ -77,6 +80,7 @@ export default defineConfig({
77
80
  { text: 'Scaffold', link: '/reference/generators/scaffold' },
78
81
  { text: 'Taxonomies', link: '/reference/generators/taxonomies' },
79
82
  { text: 'Audit log', link: '/reference/generators/audit-log' },
83
+ { text: 'Public accounts', link: '/reference/generators/public-accounts' },
80
84
  { text: 'Security headers', link: '/reference/generators/security-headers' }
81
85
  ]
82
86
  },
@@ -0,0 +1,74 @@
1
+ # Background jobs
2
+
3
+ Trek apps run Active Job on [GoodJob](https://github.com/bensheldon/good_job), installed by `bin/rails g trek:install` (or on its own with `bin/rails g trek:install:good_job`). GoodJob stores its queue in the application's own PostgreSQL database, so there is no second database to provision — which is why the installer removes the Solid Queue setup `rails new` generates.
4
+
5
+ ## What the installer sets up
6
+
7
+ | Where | What |
8
+ | ----------------------------------- | --------------------------------------------------------------------------------------------------------- |
9
+ | `Gemfile` | `good_job` replaces `solid_queue` (Solid Cache stays: its table lives in the primary database) |
10
+ | `config/application.rb` | `config.active_job.queue_adapter = :good_job` and `config.action_mailer.delivery_job = "MailDeliveryJob"` |
11
+ | `config/environments/production.rb` | `config.good_job.execution_mode = :async` and `config.good_job.shutdown_timeout = 25` |
12
+ | `config/environments/test.rb` | `config.active_job.queue_adapter = :test`, so specs can check what is enqueued (`have_enqueued_job`) |
13
+ | `config/initializers/good_job.rb` | queues, cron, error reporting, and the dashboard guard |
14
+ | `config/database.yml` | a connection pool sized for the web threads **and** the job threads |
15
+ | `app/jobs/mail_delivery_job.rb` | the delivery job every `deliver_later` email goes through |
16
+ | `config/routes.rb` | `mount GoodJob::Engine => "good_job"` inside `namespace :admin` |
17
+
18
+ ## Async in Puma, or a dedicated worker
19
+
20
+ In production the jobs run in the web container's own threads (`execution_mode = :async`): nothing else to deploy, nothing else to pay for. `shutdown_timeout = 25` lets a restart drain the jobs in flight instead of dropping them.
21
+
22
+ `GOOD_JOB_MAX_THREADS` sizes the job pool. It also feeds the database pool, since `config/database.yml` reserves connections for the web threads and the job threads separately:
23
+
24
+ ```yml
25
+ max_connections: <%= web = ENV.fetch("RAILS_MAX_THREADS", 5).to_i; 1 + web + ENV.fetch("GOOD_JOB_MAX_THREADS", web).to_i %>
26
+ ```
27
+
28
+ When the jobs outgrow the web container — long-running work, or a queue that must not compete with requests — move them to their own process: set `config.good_job.execution_mode = :external` and uncomment the worker line in the `Procfile` (`worker: bundle exec good_job start`). Note that in `:external` mode only the worker runs a scheduler, so cron then runs there and nowhere else.
29
+
30
+ ## Queues
31
+
32
+ One scheduler serves every queue by default (`config.good_job.queues = "*"`). Give a queue its own lane when it must not wait behind the others:
33
+
34
+ ```ruby
35
+ config.good_job.queues = "mailers:2;*:3"
36
+ ```
37
+
38
+ The thread counts have to stay within `GOOD_JOB_MAX_THREADS` — they are database connections too.
39
+
40
+ ## Scheduled jobs (cron)
41
+
42
+ Recurring jobs are declared in the initializer, and only run in production (a development machine should not fire them). The installer schedules the purge of the admin's expired sessions; [`trek:audit_log`](/reference/generators/audit-log#purging-old-rows) and [`trek:public_accounts`](/reference/generators/public-accounts) add their own purges at the top of the hash:
43
+
44
+ ```ruby
45
+ config.good_job.enable_cron = Rails.env.production?
46
+ config.good_job.cron = {
47
+ purge_audit_logs: {
48
+ cron: "0 4 * * *",
49
+ class: "Trek::AuditLog::PurgeJob",
50
+ description: "Delete the audit log rows past the retention window"
51
+ },
52
+ purge_expired_sessions: {
53
+ cron: "0 3 * * *", # every day at 3am
54
+ class: "Trek::PurgeExpiredSessionsJob",
55
+ description: "Delete the admin's sessions past their idle timeout or lifetime"
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## The dashboard
61
+
62
+ GoodJob's dashboard is mounted at `/admin/good_job`. It sits outside `Admin::BaseController`, so it is guarded in the initializer by the same signed session cookie the admin uses: anyone who is not an administrator gets a 404 rather than a redirect, which keeps the route invisible. The installed request spec covers the three cases (administrator, privileged non-administrator, visitor).
63
+
64
+ ## Mail deliveries are retried
65
+
66
+ GoodJob discards a failed job rather than retrying it, so a transient error from the mail service would lose the email. Every `deliver_later` goes through `MailDeliveryJob` instead, which retries five times with a growing delay:
67
+
68
+ ```ruby
69
+ class MailDeliveryJob < ActionMailer::MailDeliveryJob
70
+ retry_on StandardError, wait: :polynomially_longer, attempts: 5
71
+ end
72
+ ```
73
+
74
+ An error raised in a scheduler thread, outside a job's own execution, has no retry handler to catch it; `config.good_job.on_thread_error` reports it through `Rails.error` like the rest of the app.
@@ -0,0 +1,219 @@
1
+ # Content editor
2
+
3
+ Trek's content editor is where the admin writes the content of pages, page versions and fragments: headings, lists, quotes, links, images and calls to action, laid out as they will read.
4
+
5
+ It's built on [Tiptap](https://tiptap.dev), an editor framework on top of [ProseMirror](https://prosemirror.net). That's why the editor doesn't save HTML. It saves a structured document: a tree of typed nodes (paragraphs, headings, images…) and marks (bold, links…), each with typed attributes. The site turns that document into HTML when it shows it, with the [`prosemirror`](https://github.com/etaminstudio/prosemirror) gem.
6
+
7
+ Keeping structure rather than markup lets Trek:
8
+
9
+ - **render the content safely:** the HTML is built from known types, so content can't inject markup;
10
+ - **change how a block looks** on the site without touching stored content, for example images rendered by the app's own component;
11
+ - **keep links to pages working** when they move: a link stores the page, not its URL;
12
+ - **read the content as data:** extract its text, search it, check it.
13
+
14
+ This guide follows content from end to end:
15
+
16
+ 1. **Editing:** [using the editor](#using-the-editor) in admin forms, and its panels.
17
+ 2. **Storage:** [how content is stored](#how-content-is-stored), as JSON in a `jsonb` column.
18
+ 3. **Rendering:** [rendering on the site](#rendering-on-the-site), through `Trek::Content.schema`, and [customizing it](#customizing-the-rendering).
19
+
20
+ ## Using the editor
21
+
22
+ Add it to an admin form with `f.content_editor`:
23
+
24
+ ```slim
25
+ = form_with model: [:admin, @book] do |f|
26
+ = f.group :content
27
+ = f.content_editor :content
28
+ ```
29
+
30
+ | Option | Default | Effect |
31
+ | --- | --- | --- |
32
+ | `nodes` | `true` | the toolbar's text buttons: bold, italic, link, clear formatting, line break |
33
+ | `blocks` | `true` | the toolbar's block buttons: paragraph, headings 2 to 4, bullet list, quote, horizontal rule |
34
+ | `floating` | `true` | the menu on an empty line, inserting an image or a prompt |
35
+ | `autofocus` | `false` | puts the cursor at the end of the content on load |
36
+
37
+ Undo and redo are always there. For a short field, such as an introduction, turn the rest off:
38
+
39
+ ```slim
40
+ = f.content_editor :intro, blocks: false, floating: false
41
+ ```
42
+
43
+ Tiptap's Markdown shortcuts work too: typing `1. ` starts an ordered list, and `~~text~~` strikes text through, even though the toolbar has no button for them. The site renders them like the rest.
44
+
45
+ ### Links
46
+
47
+ The link button opens a panel to pick a page of the site, or type any URL. A link to a page is stored as its GlobalID (`gid://app/Page/12`) rather than its URL. It's turned into a URL when the content is rendered, so the link survives the page moving or changing its slug (see [Links to records with GlobalID](https://github.com/etaminstudio/prosemirror/blob/main/COOKBOOK.md#links-to-records-with-globalid) in the `prosemirror` gem's cookbook).
48
+
49
+ ### Images
50
+
51
+ The image entry of the floating menu opens a panel to upload an image (with Uppy, stored by Shrine's `ModelImageUploader`). The panel also sets its alternative text, caption, credit and size (`default` or `larger`). The node keeps the uploaded file's data, so the image belongs to the content, not to a record.
52
+
53
+ ### Prompts
54
+
55
+ The prompt entry inserts a call to action: a text, a link (a page or a URL, as for links), where it opens, and a title.
56
+
57
+ ### Panels
58
+
59
+ The link, image and prompt panels are the `Admin::Panels::*` controllers that the installer generates (see [Controllers](/reference/controllers)).
60
+
61
+ ## How content is stored
62
+
63
+ The editor saves a ProseMirror document in the form's field, as JSON, with Tiptap's camelCase type names:
64
+
65
+ ```json
66
+ {
67
+ "type": "doc",
68
+ "content": [
69
+ { "type": "heading", "attrs": { "level": 2 }, "content": [{ "type": "text", "text": "Opening hours" }] },
70
+ {
71
+ "type": "paragraph",
72
+ "content": [
73
+ { "type": "text", "text": "See the " },
74
+ { "type": "text", "text": "map", "marks": [{ "type": "link", "attrs": { "href": "gid://app/Page/12" } }] }
75
+ ]
76
+ },
77
+ { "type": "imageBlock", "attrs": { "file_data": "{\"id\":\"…\",\"storage\":\"store\"}", "alt": "The entrance", "text": "Main entrance", "credit": "Photo: A. Smith", "size": "larger" } }
78
+ ]
79
+ }
80
+ ```
81
+
82
+ - **Column:** Trek's models keep it in a `jsonb` `content` column. [Translatable](/reference/concerns/translatable) models hold one document per locale.
83
+ - **Cleaning:** before saving, [Contentable](/reference/concerns/contentable) removes what rendering skips: empty paragraphs, empty list items, and lists left empty. An empty document keeps one paragraph, and whatever the schema doesn't know is kept. The editor submits the content as a JSON string, and it's stored as a document. Empty paragraphs used for spacing are removed for good.
84
+ - **Typography:** [Formattable](/reference/concerns/formattable) works on documents, changing only their text nodes. Add `:content` to the generated `format_attributes Trek::TypographyFormatter, :title, :description` to apply French typography to it.
85
+ - **Search:** to find content by its words, search the text nodes rather than the JSON, or every document matches `paragraph`. `content_text` gives the plain text, and `Fragment.search` shows a query in SQL (see [Fragment](/reference/models/fragment)).
86
+
87
+ ## Rendering on the site
88
+
89
+ A model with a `content` column includes [Contentable](/reference/concerns/contentable):
90
+
91
+ ```slim
92
+ / ERB or Slim
93
+ = @page.formatted_content
94
+ ```
95
+
96
+ ```ruby
97
+ # Phlex
98
+ render @page.content_document.to_phlex
99
+ ```
100
+
101
+ For a [versioned](/reference/concerns/versionable) page, render its live version's content, `current_content`, which comes from a `PageVersion`: `Trek::Content::Document.parse(@page.current_version || @page, @page.current_content).to_html`.
102
+
103
+ `formatted_content` only reads the `content` column. To render another column, such as a book's `intro`, parse it with `Trek::Content::Document`. Its first argument is the record holding the content: when that content is invalid, the error reports name the record (`trek_content: "Book#3"`, see [Invalid content](#invalid-content)), so you know which one to fix.
104
+
105
+ ```ruby
106
+ Trek::Content::Document.parse(book, book.intro).to_html
107
+ ```
108
+
109
+ ### What the HTML contains
110
+
111
+ - **Escaping:** HTML is escaped as it is built. Nothing a user types can open a tag.
112
+ - **Attributes** are typed: a value that doesn't fit, such as a heading level of 9, is replaced by its default, or removed.
113
+ - **URLs:** links and images only allow `http`, `https`, `mailto`, `tel` and relative URLs.
114
+ - **Links to pages** become the page's URL, through `url_for`. The records a document links to load together, with one query per model. A link to a deleted record is removed, and its text kept.
115
+ - **Empty nodes:** empty paragraphs, empty list items, and lists with only empty items render nothing ([Skip empty paragraphs](https://github.com/etaminstudio/prosemirror/blob/main/COOKBOOK.md#skip-empty-paragraphs)). Saving removes them from the stored content too ([cleaning](#how-content-is-stored)), but content saved before Trek did is only cleaned when it's saved again.
116
+ - **Images** render as a `<figure>` with a `data-size` attribute, with the caption and the credit in its `<figcaption>`.
117
+ - **Prompts** render as a link.
118
+ - **Unknown attributes,** such as heading ids added by the editor, are kept in the JSON but never rendered. To give headings anchors, see [Heading anchors](https://github.com/etaminstudio/prosemirror/blob/main/COOKBOOK.md#heading-anchors) in the `prosemirror` gem's cookbook.
119
+
120
+ ### Invalid content
121
+
122
+ A document that doesn't fit the schema is fixed as it's read, and each problem is reported to `Rails.error` (`handled: true`):
123
+
124
+ - an attribute of the wrong type is converted when the meaning is clear, or replaced by its default, or its node or mark is removed (a link keeps its text);
125
+ - a node of an unknown type renders only its content;
126
+ - links to deleted records, reported as `Prosemirror::UnresolvedURL`.
127
+
128
+ The report's context names the record holding the content (`trek_content: "Page#12"`), which AppSignal shows as a tag, so a problem leads back to the page to fix.
129
+
130
+ ## Customizing the rendering
131
+
132
+ `Trek::Content.schema` is Tiptap's schema (`Prosemirror::Schema.tiptap(case: :camel)`), with Trek's own node types:
133
+
134
+ | Node type | Role |
135
+ | --- | --- |
136
+ | `Trek::Content::Paragraph` | skips empty paragraphs |
137
+ | `Trek::Content::ListItem` | skips empty list items, with no content or only empty paragraphs |
138
+ | `Trek::Content::BulletList`, `OrderedList` | skip lists with only empty items |
139
+ | `Trek::Content::ImageBlock` | renders image blocks as a `<figure>`: the image, its caption and credit |
140
+ | `Trek::Content::PromptsBlock` | renders prompt blocks as a link |
141
+
142
+ Node and mark types are [Phlex](https://www.phlex.fun) components with [Literal](https://literal.fun) properties (see the [`prosemirror` README](https://github.com/etaminstudio/prosemirror#custom-nodes-and-marks)). To change how one renders, subclass it, and put it in the schema from an initializer. The cookbook's [Render your own components](https://github.com/etaminstudio/prosemirror/blob/main/COOKBOOK.md#render-your-own-components) shows the pattern.
143
+
144
+ ### Images with the app's component
145
+
146
+ For example, images at the app's own sizes:
147
+
148
+ ```ruby
149
+ # app/content/image_block.rb
150
+ class ImageBlock < Trek::Content::ImageBlock
151
+ def view_template
152
+ return unless image
153
+
154
+ render Components::Figure.new(
155
+ src: image.derivation_url(:thumbnail, 930, 1200),
156
+ alt: @alt,
157
+ caption: @text,
158
+ credit: @credit
159
+ )
160
+ end
161
+ end
162
+ ```
163
+
164
+ ```ruby
165
+ # config/initializers/trek.rb
166
+ Rails.application.config.to_prepare do
167
+ Trek::Content.schema = Trek::Content.default_schema.with(ImageBlock)
168
+ end
169
+ ```
170
+
171
+ - **Registering:** `with` replaces the type of the same name, and keeps the others.
172
+ - **Reloading:** the default schema is rebuilt after code reloading, so `to_prepare` sees the reloaded classes in development.
173
+ - **Inside a node type:**
174
+ - the node's attributes are instance variables (`@alt`, `@text`);
175
+ - `image` is the uploaded file, or `nil` when the data is missing or invalid;
176
+ - `safe_url(url)` checks a URL against the allowed schemes.
177
+
178
+ ### Prompts as the app's buttons
179
+
180
+ ```ruby
181
+ class PromptsBlock < Trek::Content::PromptsBlock
182
+ def view_template
183
+ href = @href.present? && safe_url(@href)
184
+ return if !href || @text.blank?
185
+
186
+ render Components::Button.new(href:, target: @target, title: @title) { @text }
187
+ end
188
+ end
189
+ ```
190
+
191
+ Register it the same way: `Trek::Content.default_schema.with(ImageBlock, PromptsBlock)`.
192
+
193
+ ### Node types of the app's own
194
+
195
+ A node of a type the schema doesn't know renders only its content, and is reported. To render it, add a class of that name to the schema (`Callout` for `callout`):
196
+
197
+ ```ruby
198
+ class Callout < Prosemirror::NodeType
199
+ group :block
200
+ content "block+"
201
+
202
+ prop :tone, _Union?("info", "warning")
203
+
204
+ def view_template(&) = aside(data_tone: @tone, &)
205
+ end
206
+ ```
207
+
208
+ Trek's editor has a fixed set of Tiptap extensions, so it can't insert such a node yet. It renders nodes that come from elsewhere: imported content, or JSON written by a script.
209
+
210
+ ## Importing content
211
+
212
+ The `prosemirror` gem builds documents from HTML (with the `herb` gem), Markdown (with `commonmarker`) or plain text, using the schema's parse rules. To fill pages from an older site:
213
+
214
+ ```ruby
215
+ document = Prosemirror.from_html(old_html, schema: Trek::Content.schema)
216
+ page.update!(content: document.to_h)
217
+ ```
218
+
219
+ `to_h` gives the JSON the editor reads, with invalid parts fixed. See the [`prosemirror` README](https://github.com/etaminstudio/prosemirror#html-import) for what each import keeps.
data/docs/customize.md CHANGED
@@ -48,6 +48,8 @@ Trek's UI components accept options where it matters:
48
48
  f.content_editor :intro, nodes: false, floating: false
49
49
  ```
50
50
 
51
+ To render content blocks with your own components, see [Customizing the rendering](/content-editor#customizing-the-rendering).
52
+
51
53
  - **`Trek::LayoutComponent`** — use the `panel` slot to add your own side panel to admin screens.
52
54
 
53
55
  ## Models
data/docs/deploy.md CHANGED
@@ -14,22 +14,25 @@ Compared with the stock buildpacks, deploys typically go from around 3 minutes t
14
14
 
15
15
  ## Set up the app
16
16
 
17
- Generate the Scalingo files (an `Aptfile` and a `Procfile` with the web process and post-deploy migrations):
17
+ Generate the Scalingo files (an `Aptfile` and a `Procfile` with the web process and post-deploy migrations). The generator also comments out the `kamal` gem `rails new` adds, which drops its SSH dependencies from the bundle:
18
18
 
19
19
  ```sh
20
- rails g trek:install:scalingo
20
+ bin/rails g trek:scalingo
21
21
  ```
22
22
 
23
23
  Then configure the Scalingo app's environment, pinning the buildpack to a release through its archive:
24
24
 
25
25
  ```sh
26
- scalingo --app <app> env-set BUILDPACK_URL=https://github.com/etaminstudio/trek-buildpack/archive/refs/tags/v0.1.0.tar.gz
26
+ scalingo --app <app> env-set BUILDPACK_URL=https://github.com/etaminstudio/trek-buildpack/archive/refs/tags/v0.1.4.tar.gz
27
27
  scalingo --app <app> env-set 'DATABASE_URL=$SCALINGO_POSTGRESQL_URL'
28
- scalingo --app <app> env-set RAILS_MASTER_KEY=$(cat config/master.key)
28
+ scalingo --app <app> env-set RAILS_MASTER_KEY=$(cat config/master.key) > /dev/null
29
29
  ```
30
30
 
31
+ > `env-set` prints every value it sets, so without `> /dev/null` the master key ends up in the terminal's scrollback and
32
+ > in any log or transcript of the session. Do the same for every secret below.
33
+
31
34
  > Pin through the archive, not a `#tag` suffix: Scalingo reads `#ref` on `BUILDPACK_URL` as a **branch**, so
32
- > `…/trek-buildpack#v0.1.0` asks for a branch named `v0.1.0`, which does not exist, and the build fails with
35
+ > `…/trek-buildpack#v0.1.4` asks for a branch named `v0.1.4`, which does not exist, and the build fails with
33
36
  > `fail to download and extract the custom buildpack: Invalid status code: 404 Not Found`. The `.tar.gz` form above is
34
37
  > downloaded as is and stays pinned to the release.
35
38
 
@@ -44,6 +47,66 @@ production:
44
47
 
45
48
  Provision a PostgreSQL addon (`scalingo --app <app> addons-add postgresql <plan>`), push, and the app boots with `RAILS_ENV`, `RAILS_LOG_TO_STDOUT` and `RAILS_SERVE_STATIC_FILES` already set by the buildpack.
46
49
 
50
+ ### One database
51
+
52
+ The addon is a single database, but the production section `rails new` generates also declares a `cache` database for Solid Cache (`config/cache.yml` says `database: cache`, its schema is `db/cache_schema.rb`). The postdeploy `db:migrate` never loads that schema, so the cache table is never created. Keep the cache in the app's database:
53
+
54
+ * drop the `cache` entry from the production section of `config/database.yml`, and the `database: cache` line from `config/cache.yml`
55
+ * create the table with a regular migration (`bin/rails g migration CreateSolidCacheEntries`), copying `create_table "solid_cache_entries"` and its indexes from `db/cache_schema.rb`
56
+ * delete `db/cache_schema.rb`
57
+
58
+ The same goes for any other extra database in that section (`queue`, `cable`).
59
+
60
+ ### Environment variables
61
+
62
+ Besides the three above, the code Trek generates reads:
63
+
64
+ | Variable | Used for |
65
+ | --- | --- |
66
+ | `DEFAULT_HOSTNAME` | The app's host, for URLs built outside a request, including links in emails (`config/initializers/host.rb`) |
67
+ | `MAILER_FROM` | The sender of the app's emails (`ApplicationMailer`) |
68
+ | `S3_BUCKET`, `S3_REGION`, `S3_ENDPOINT`, `S3_ACCESS_KEY_ID`, `S3_SECRET_ACCESS_KEY` | The uploads' bucket (`config/initializers/shrine.rb`). Required in production: the app doesn't boot without them |
69
+ | `S3_BASE_URL` | The public URL of the bucket's files, e.g. `https://<bucket>.<region>.your-objectstorage.com`. Required in production too |
70
+ | `APPSIGNAL_PUSH_API_KEY` | Turns AppSignal on, unless the key is in the credentials (`config/appsignal.rb`) |
71
+ | `APPSIGNAL_APP_ENV` | The AppSignal environment, e.g. `qa`. The gem reads this name, not `APPSIGNAL_ENV` |
72
+ | `RAILS_MAX_THREADS`, `GOOD_JOB_MAX_THREADS` | Puma's threads and the jobs' threads, which also size the database pool (`config/database.yml`) |
73
+
74
+ Jobs run inside the web container (`config.good_job.execution_mode = :async`), so the generated `Procfile` has no worker to scale.
75
+
76
+ `env-set` doesn't restart the app: running containers keep their old values until `scalingo --app <app> restart`.
77
+
78
+ ### Domains
79
+
80
+ Add each domain to the app, then point it at the app with a CNAME:
81
+
82
+ ```sh
83
+ scalingo --app <app> domains-add <domain>
84
+ # DNS: <domain> CNAME <app>.osc-fr1.scalingo.io.
85
+ ```
86
+
87
+ Scalingo issues the Let's Encrypt certificate once the CNAME resolves; until then the domain shows "Pending DNS".
88
+
89
+ ### Continuous deployment
90
+
91
+ Deploy from GitLab CI rather than linking the Scalingo app to the repository: the deploy then only runs once the pipeline's tests, lint and security jobs have passed. The generated `.gitlab-ci.yml` has a `deploy` stage, with commented-out jobs; replace them with one job per Scalingo app:
92
+
93
+ ```yaml
94
+ qa:
95
+ <<: *deploy_definition
96
+ only:
97
+ - main
98
+ environment:
99
+ name: qa
100
+ url: https://<domain>
101
+ script:
102
+ - curl -O https://cli-dl.scalingo.com/install && bash install
103
+ - scalingo login --api-token $SCALINGO_API_TOKEN
104
+ - tar --exclude=tmp --exclude=log --exclude=spec --exclude=.git --transform='s,^,master/,' -cvzf tmp/main.tar.gz .
105
+ - scalingo --app <app> deploy tmp/main.tar.gz $CI_COMMIT_SHORT_SHA
106
+ ```
107
+
108
+ `SCALINGO_API_TOKEN` is a Scalingo API token, set as a masked CI/CD variable of the project or its group. A `production` job on the `production` branch follows the same pattern.
109
+
47
110
  Before going live, check what Trek expects from the hosting: backups, a shared cache store, the scheduled purges (see [Security and compliance](/security#what-trek-expects-from-the-hosting)).
48
111
 
49
112
  ## Options
@@ -57,7 +120,7 @@ Before going live, check what Trek expects from the hosting: backups, a shared c
57
120
 
58
121
  Apps deployed with the stock `.buildpacks` (apt + ruby) migrate in three steps:
59
122
 
60
- 1. delete `.buildpacks` (re-running `rails g trek:install:scalingo` does it) and check that `.node-version` exists — apps generated with `rails new -j esbuild` have it
123
+ 1. delete `.buildpacks` (re-running `bin/rails g trek:scalingo` does it) and check that `.node-version` exists — apps generated with `rails new -j esbuild` have it
61
124
  2. set `BUILDPACK_URL` as above, and map `DATABASE_URL` if the app doesn't read it yet
62
125
  3. deploy — the first build fills the caches, the next ones benefit from them
63
126