@yunuseon/kayra 0.18.0 → 0.20.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 (164) hide show
  1. package/agent/skills/kayra-release/SKILL.md +1 -4
  2. package/agent/skills/kayra-rollout/SKILL.md +4 -6
  3. package/ansible/playbooks/edge.yml +5 -0
  4. package/ansible/playbooks/nas.yml +9 -1
  5. package/ansible/playbooks/platform.yml +8 -2
  6. package/ansible/roles/app/tasks/main.yml +33 -3
  7. package/ansible/roles/kayra-version/defaults/main.yml +5 -0
  8. package/ansible/roles/kayra-version/tasks/main.yml +18 -0
  9. package/ansible/roles/platform/defaults/main.yml +3 -0
  10. package/ansible/roles/platform/tasks/main.yml +6 -84
  11. package/ansible/roles/platform/templates/platform.env.j2 +2 -0
  12. package/bin/kayra-app-hook.js +6 -0
  13. package/bin/kayra-app-init.js +6 -0
  14. package/bin/kayra-app-launch.js +6 -0
  15. package/bin/kayra-app-values.js +6 -0
  16. package/cli/dist/app-hook.js +75 -0
  17. package/cli/dist/app-init.js +65 -0
  18. package/cli/dist/app-launch.js +89 -0
  19. package/cli/dist/app-values.js +37 -0
  20. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-400-normal-BTotfTJu.woff +0 -0
  21. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-400-normal-DZqxrq2p.woff2 +0 -0
  22. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-600-normal-71GNu3SW.woff2 +0 -0
  23. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-600-normal-BGq0mW3O.woff +0 -0
  24. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-400-normal-Dsrv2Tcn.woff +0 -0
  25. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-400-normal-g30qAdWV.woff2 +0 -0
  26. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-600-normal-Bz0x94Yp.woff +0 -0
  27. package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-600-normal-DUMzJB7m.woff2 +0 -0
  28. package/cli/dist/browser/assets/ibm-plex-sans-greek-400-normal-D9ESIMu3.woff +0 -0
  29. package/cli/dist/browser/assets/ibm-plex-sans-greek-400-normal-_efipK4i.woff2 +0 -0
  30. package/cli/dist/browser/assets/ibm-plex-sans-greek-600-normal-D-CqTdkO.woff +0 -0
  31. package/cli/dist/browser/assets/ibm-plex-sans-greek-600-normal-DzTrcv_p.woff2 +0 -0
  32. package/cli/dist/browser/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  33. package/cli/dist/browser/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
  34. package/cli/dist/browser/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
  35. package/cli/dist/browser/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  36. package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-400-normal-C5H60-Va.woff2 +0 -0
  37. package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-400-normal-RBey6euL.woff +0 -0
  38. package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-600-normal-DIrixKbi.woff +0 -0
  39. package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-600-normal-DOrvGEcy.woff2 +0 -0
  40. package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-400-normal-DG4YqDda.woff2 +0 -0
  41. package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-400-normal-fK1oJ5dG.woff +0 -0
  42. package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-600-normal-DgdngZtN.woff +0 -0
  43. package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-600-normal-DpPYBSTl.woff2 +0 -0
  44. package/cli/dist/browser/assets/index-DzIVPXyL.css +1 -0
  45. package/cli/dist/browser/assets/index-SP8bCDrl.js +7 -0
  46. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  47. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
  48. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
  49. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
  50. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-600-normal-8K4wrrwR.woff +0 -0
  51. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  52. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-700-normal-BWTpRfYl.woff2 +0 -0
  53. package/cli/dist/browser/assets/jetbrains-mono-cyrillic-700-normal-CEoEElIJ.woff +0 -0
  54. package/cli/dist/browser/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
  55. package/cli/dist/browser/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  56. package/cli/dist/browser/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
  57. package/cli/dist/browser/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
  58. package/cli/dist/browser/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  59. package/cli/dist/browser/assets/jetbrains-mono-greek-600-normal-mc2nkWzM.woff +0 -0
  60. package/cli/dist/browser/assets/jetbrains-mono-greek-700-normal-C6CZE3T8.woff2 +0 -0
  61. package/cli/dist/browser/assets/jetbrains-mono-greek-700-normal-DEigVDxa.woff +0 -0
  62. package/cli/dist/browser/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  63. package/cli/dist/browser/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  64. package/cli/dist/browser/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  65. package/cli/dist/browser/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  66. package/cli/dist/browser/assets/jetbrains-mono-latin-600-normal-BfsvjouI.woff +0 -0
  67. package/cli/dist/browser/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  68. package/cli/dist/browser/assets/jetbrains-mono-latin-700-normal-BYuf6tUa.woff2 +0 -0
  69. package/cli/dist/browser/assets/jetbrains-mono-latin-700-normal-D3wTyLJW.woff +0 -0
  70. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  71. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
  72. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
  73. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
  74. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  75. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-600-normal-DObL3zCW.woff +0 -0
  76. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-700-normal-CZipNAKV.woff2 +0 -0
  77. package/cli/dist/browser/assets/jetbrains-mono-latin-ext-700-normal-CxPITLHs.woff +0 -0
  78. package/cli/dist/browser/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
  79. package/cli/dist/browser/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
  80. package/cli/dist/browser/assets/jetbrains-mono-vietnamese-600-normal-OWROknRo.woff +0 -0
  81. package/cli/dist/browser/assets/jetbrains-mono-vietnamese-700-normal-BDLVIk2r.woff +0 -0
  82. package/cli/dist/browser/index.html +10 -3
  83. package/cli/dist/clients/api/start.js +1 -1
  84. package/cli/dist/clients/cli/invocation.js +25 -0
  85. package/cli/dist/clients/cli/parser.js +24 -7
  86. package/cli/dist/clients/cli/status.js +28 -7
  87. package/cli/dist/clients/cli/text.js +3 -3
  88. package/cli/dist/clients/cli/values.js +0 -1
  89. package/cli/dist/clients/cli/views.js +9 -2
  90. package/cli/dist/clients/mcp/tools.js +8 -1
  91. package/cli/dist/clients/ui/assets.js +1 -0
  92. package/cli/dist/clients/wire/contract.js +2 -2
  93. package/cli/dist/clients/wire/queries.js +1 -0
  94. package/cli/dist/clients/wire/schemas.js +6 -2
  95. package/cli/dist/clients/wire/status.js +7 -1
  96. package/cli/dist/clients/wire/words.js +14 -0
  97. package/cli/dist/core/adapters/network.js +20 -1
  98. package/cli/dist/core/adapters/opentofu.js +1 -1
  99. package/cli/dist/core/app-hook/hooks.js +90 -0
  100. package/cli/dist/core/app-hook/token.js +49 -0
  101. package/cli/dist/core/app-init/plan.js +208 -0
  102. package/cli/dist/core/app-values/model.js +45 -0
  103. package/cli/dist/core/app-values/store.js +124 -0
  104. package/cli/dist/core/ctl/answers.js +14 -9
  105. package/cli/dist/core/fleet/brand.js +10 -7
  106. package/cli/dist/core/fleet/parse.js +10 -1
  107. package/cli/dist/core/fleet/settings.js +32 -12
  108. package/cli/dist/core/operations/catalog.js +46 -1
  109. package/cli/dist/core/operations/dispatch.js +40 -9
  110. package/cli/dist/core/recipes/app-check.js +14 -1
  111. package/cli/dist/core/recipes/app-hook.js +26 -0
  112. package/cli/dist/core/recipes/app-values.js +21 -0
  113. package/cli/dist/core/recipes/doctor.js +5 -5
  114. package/cli/dist/core/recipes/host.js +8 -3
  115. package/cli/dist/core/recipes/launch.js +51 -0
  116. package/cli/dist/core/status/look.js +33 -13
  117. package/cli/dist/core/status/model.js +2 -0
  118. package/cli/dist/core/validation/facts.js +1 -3
  119. package/cli/dist/deployer/brand.js +9 -1
  120. package/cli/dist/deployer/build/builder.js +15 -4
  121. package/cli/dist/deployer/build/bundle.js +5 -0
  122. package/cli/dist/deployer/build/client.js +44 -0
  123. package/cli/dist/deployer/build/compose.js +21 -8
  124. package/cli/dist/deployer/build/routes.js +149 -0
  125. package/cli/dist/deployer/ctl/answers.js +6 -2
  126. package/cli/dist/deployer/ctl/ctl.js +66 -9
  127. package/cli/dist/deployer/deployer.js +114 -191
  128. package/cli/dist/deployer/forges/forge.js +0 -12
  129. package/cli/dist/deployer/forges/notify.js +3 -3
  130. package/cli/dist/deployer/http/http.js +0 -1
  131. package/cli/dist/deployer/http/page.js +4 -2
  132. package/cli/dist/deployer/http/webhook.js +0 -1
  133. package/cli/dist/deployer/runs/effects.js +70 -0
  134. package/cli/dist/deployer/runs/queue.js +5 -4
  135. package/cli/dist/deployer/runs/records.js +22 -3
  136. package/cli/dist/deployer/runs/restore.js +6 -0
  137. package/cli/dist/deployer/runs/run.js +64 -11
  138. package/cli/dist/deployer/runs/store.js +19 -3
  139. package/cli/dist/deployer/settings.js +69 -0
  140. package/cli/dist/lib/forge-repo.js +15 -0
  141. package/cli/dist/lib/names.js +13 -0
  142. package/cli/dist/main.js +46 -25
  143. package/compose/docker-compose.ci.yml +2 -0
  144. package/package.json +2 -2
  145. package/schema/app.json +69 -8
  146. package/schema/defaults.json +8 -0
  147. package/schema/vars-platform.json +8 -0
  148. package/scripts/local/app-check.sh +12 -9
  149. package/scripts/local/app-manifests.sh +11 -6
  150. package/scripts/local/verify.sh +30 -12
  151. package/scripts/platform/compose-policy.sh +37 -40
  152. package/terraform/modules/platform-dns/main.tf +66 -0
  153. package/terraform/modules/platform-dns/outputs.tf +9 -0
  154. package/terraform/modules/platform-dns/tests/fleet/.cache/apps/blog/site/app.yml +3 -0
  155. package/terraform/modules/platform-dns/tests/fleet/.cache/apps/shop/app.yml +6 -0
  156. package/terraform/modules/platform-dns/tests/fleet/servers/nested/server.yml +6 -0
  157. package/terraform/modules/platform-dns/tests/fleet/servers/shop/server.yml +7 -0
  158. package/terraform/modules/platform-dns/tests/fleet/servers/uncloned/server.yml +6 -0
  159. package/terraform/modules/platform-dns/tests/platform-dns.tftest.hcl +64 -0
  160. package/terraform/modules/platform-dns/variables.tf +25 -0
  161. package/cli/dist/browser/assets/index-Ct0Eudk4.css +0 -1
  162. package/cli/dist/browser/assets/index-hcyM6f6T.js +0 -7
  163. package/compose/traefik/dynamic/ratelimit.yml +0 -21
  164. package/scripts/agent/guard.sh +0 -125
@@ -66,10 +66,7 @@ shell.
66
66
  ## 3. Merge and tag
67
67
 
68
68
  `main` is protected: it changes only through a PR with green `checks`, for
69
- admins too. Merging and pushing a tag both ask the operator (kayra's guard);
70
- that is expected, say what you are doing. In auto mode the guard refuses
71
- them instead: stop, give the operator the exact command, and continue once
72
- they ran it (or switched the session to Manual and said so).
69
+ admins too.
73
70
 
74
71
  ```bash
75
72
  gh pr merge <n> --repo yunuseon/kayra --merge --delete-branch
@@ -57,10 +57,7 @@ with the kayra checkout at the released tag.
57
57
  Commit (the message names the release and anything the fleet changed),
58
58
  push, open the PR the fleet's way, wait for its checks (GitHub:
59
59
  `gh pr checks --watch`; Forgejo: `tea api /repos/<owner>/<repo>/commits/<sha>/status`
60
- until `success`), then merge. Merges ask the operator (kayra's guard); that
61
- is expected. In auto mode the guard refuses them, and every non-multipass
62
- deploy below, instead: stop, give the operator the exact command, continue
63
- once they ran it. Remove the worktree and the local branch.
60
+ until `success`), then merge. Remove the worktree and the local branch.
64
61
 
65
62
  ## 3. Deploy, server by server
66
63
 
@@ -88,7 +85,8 @@ Things that have bitten before:
88
85
 
89
86
  ## 4. Report
90
87
 
91
- Per server: the version it runs now, the deploy's recap (nothing failed?),
92
- the `kayra verify` result, and anything left for the user (a DNS apply, a
88
+ Per server: the version it runs now (`kayra status`'s `KAYRA` column, read
89
+ from the server: `1.2.2 → 1.2.3` is one the rollout has not reached), the
90
+ deploy's recap (nothing failed?), the `kayra verify` result, and anything left for the user (a DNS apply, a
93
91
  switch in a vendor UI, a manual cleanup). Then whether the user's checkouts
94
92
  are as they left them.
@@ -41,3 +41,8 @@
41
41
  ansible.builtin.command: ufw disable
42
42
  when: "'Status: active' in ufw_status.stdout"
43
43
  changed_when: true
44
+
45
+ post_tasks:
46
+ - name: Record which kayra set this server up
47
+ ansible.builtin.import_role:
48
+ name: kayra-version
@@ -18,13 +18,16 @@
18
18
  - "{{ server_dir }}/vars.yml"
19
19
  - "{{ server_dir }}/secrets.yml"
20
20
 
21
+ vars:
22
+ kayra_dir: "{{ nas_root }}/.kayra"
23
+
21
24
  pre_tasks:
22
25
  - name: Write only inside nas_root
23
26
  ansible.builtin.assert:
24
27
  that: item is match('^' ~ nas_root ~ '/') and '/../' not in item ~ '/'
25
28
  fail_msg: "{{ item }} lies outside {{ nas_root }}"
26
29
  quiet: true
27
- loop: "{{ [restic_backup.dir, compose_stacks.dir] }}"
30
+ loop: "{{ [restic_backup.dir, compose_stacks.dir, kayra_dir] }}"
28
31
 
29
32
  # Docker creates a missing bind-mount source, a write wherever it points.
30
33
  - name: Find the backed-up paths
@@ -45,3 +48,8 @@
45
48
  roles:
46
49
  - restic-backup
47
50
  - compose-stacks
51
+
52
+ post_tasks:
53
+ - name: Record which kayra set this server up
54
+ ansible.builtin.import_role:
55
+ name: kayra-version
@@ -10,8 +10,9 @@
10
10
  # The platform lives in /opt/platform and knows no app by name. Apps live in
11
11
  # /opt/apps/<name> and register through /opt/platform/bin/app-apply.
12
12
  #
13
- # server, server_dir, domain and target are passed via -e. Platform vars
14
- # (git_token, webhook_secret, etc.) come from servers/<server>/vars.yml.
13
+ # server, server_dir, domain, target and kayra_version are passed via -e.
14
+ # Platform vars (git_token, webhook_secret, etc.) come from
15
+ # servers/<server>/vars.yml.
15
16
  #
16
17
  # Usage: kayra setup <server>
17
18
  # =============================================================================
@@ -52,6 +53,11 @@
52
53
  when: forgejo_config is defined
53
54
 
54
55
  post_tasks:
56
+ - name: Record which kayra set this server up
57
+ ansible.builtin.import_role:
58
+ name: kayra-version
59
+ become: true
60
+
55
61
  - name: Show platform status
56
62
  ansible.builtin.debug:
57
63
  msg: |
@@ -54,23 +54,31 @@
54
54
  - {name: app_secrets, suffix: .secrets.yml}
55
55
  loop_control: {label: "{{ app.name }}{{ item.suffix }}"}
56
56
 
57
+ # An app's hosts are its routes' hosts; the routes themselves are read at
58
+ # each commit, by the builder.
59
+ - name: Read the app's hosts from its routes
60
+ ansible.builtin.set_fact:
61
+ app_subdomains: "{{ manifest.routes | default([]) | map(attribute='host') | unique | list }}"
62
+
57
63
  - name: Check the app against the platform
58
64
  ansible.builtin.assert:
59
65
  that:
60
66
  - manifest.name == app.name
67
+ - manifest.subdomains is not defined
61
68
  - missing_secrets | length == 0
62
69
  - missing_config | length == 0
63
70
  - reserved_subdomains | length == 0
64
71
  fail_msg: >-
65
72
  {{ app.name }}: app.yml name={{ manifest.name }};
73
+ {{ 'subdomains is gone: declare routes instead (the app contract);' if manifest.subdomains is defined else '' }}
66
74
  missing config {{ missing_config }} in servers/{{ server }}/apps/{{ app.name }}.yml,
67
75
  missing secrets {{ missing_secrets }} in servers/{{ server }}/apps/{{ app.name }}.secrets.yml;
68
- subdomains reserved by the platform {{ reserved_subdomains }}
76
+ hosts reserved by the platform {{ reserved_subdomains }}
69
77
  quiet: true
70
78
  vars:
71
79
  missing_secrets: "{{ manifest.secrets | default([]) | difference(app_secrets | default({}) | list) }}"
72
80
  missing_config: "{{ manifest.config | default([]) | difference(app_config | default({}) | list) }}"
73
- reserved_subdomains: "{{ manifest.subdomains | intersect(lookup('file', kayra_root ~ '/hosts.conf').splitlines() | reject('match', '^\\s*(#|$)') | list) }}"
81
+ reserved_subdomains: "{{ app_subdomains | intersect(lookup('file', kayra_root ~ '/hosts.conf').splitlines() | reject('match', '^\\s*(#|$)') | list) }}"
74
82
 
75
83
  - name: Create app directory
76
84
  ansible.builtin.file:
@@ -114,6 +122,28 @@
114
122
  repo: "{{ app_repo }}"
115
123
  ref: "{{ app_ref }}"
116
124
  path: "{{ app.path | default('.') }}"
117
- hosts: "{{ manifest.subdomains | map('regex_replace', '$', '.' ~ domain) | list }}"
125
+ hosts: "{{ app_subdomains | map('regex_replace', '$', '.' ~ domain) | list }}"
118
126
  secrets: "{{ manifest.secrets | default([]) }}"
119
127
  become: true
128
+
129
+ # A Docker update or a reboot stops every container, and one deployed before
130
+ # the platform gave each service a restart policy stays down: its live
131
+ # release, deployed again. ctl follows the run to its end; the retries wait
132
+ # out a deployer the host layer has just restarted.
133
+ - name: Restore the app if it was deployed but runs nothing
134
+ ansible.builtin.shell:
135
+ cmd: |
136
+ set -euo pipefail
137
+ live="$(ls {{ platform_dir }}/releases/{{ app.name }} 2>/dev/null | sort | tail -1 | sed -n 's/^[0-9]\{8\}T[0-9]\{6\}Z-\([0-9a-f]\{40\}\)\.env$/\1/p')"
138
+ if [ -z "$live" ]; then echo "never deployed"; exit 0; fi
139
+ if [ -n "$(docker ps -q --filter label=com.docker.compose.project={{ app.name }} --filter status=running --filter status=restarting)" ]; then echo "runs"; exit 0; fi
140
+ cd {{ platform_dir }}
141
+ docker compose exec -T deployer kayra-deployer ctl deploy {{ app.name }} "$live"
142
+ echo "restored ${live}"
143
+ executable: /bin/bash
144
+ register: app_restored
145
+ retries: 5
146
+ delay: 3
147
+ until: app_restored.rc == 0
148
+ changed_when: "'restored ' in app_restored.stdout"
149
+ become: true
@@ -0,0 +1,5 @@
1
+ ---
2
+ # A NAS's play sets it under nas_root, which it writes nothing outside of.
3
+ # `kayra status` reads <kayra_dir>/version from the same place (versionFile in
4
+ # cli/src/core/fleet/parse.ts).
5
+ kayra_dir: /opt/kayra
@@ -0,0 +1,18 @@
1
+ ---
2
+ # =============================================================================
3
+ # kayra-version role — which kayra set this server up, last in every host
4
+ # play, so only a setup that got this far records it. kayra passes its own
5
+ # version as kayra_version (-e); `kayra status` and `kayra verify` read it.
6
+ # =============================================================================
7
+
8
+ - name: Create kayra's directory
9
+ ansible.builtin.file:
10
+ path: "{{ kayra_dir }}"
11
+ state: directory
12
+ mode: "0755"
13
+
14
+ - name: Record which kayra set this server up
15
+ ansible.builtin.copy:
16
+ content: "{{ kayra_version }}\n"
17
+ dest: "{{ kayra_dir }}/version"
18
+ mode: "0644"
@@ -43,6 +43,9 @@ renovate_token: ""
43
43
  # people's releases; a server whose repos carry the operator's own images
44
44
  # runs it more often, so a new build reaches a PR soon after it is pushed.
45
45
  renovate_schedule: "0 4 * * 1"
46
+ # Push webhooks start a deploy at once; without them, the poll below finds the push.
47
+ webhooks: true
48
+ deploy_poll: "17 * * * *"
46
49
  # Where those repos live: github, gitlab (gitlab.com), or forgejo with
47
50
  # renovate_endpoint, its API on platform-internal
48
51
  # (http://forgejo:3000/api/v1). With a Forgejo, also
@@ -59,29 +59,6 @@
59
59
  mode: "0755"
60
60
  loop: [runs, releases, alerts]
61
61
  become: true
62
- register: deployer_dirs
63
-
64
- # Jenkins kept the release records rollback and GC work from; carried over
65
- # once, the first time releases/ is created. The volume itself stays until
66
- # deleted by hand.
67
- - name: Find Jenkins' release records
68
- community.docker.docker_volume_info:
69
- name: platform_jenkins-home
70
- register: jenkins_home
71
- when: deployer_dirs.results[1] is changed
72
- become: true
73
-
74
- - name: Carry Jenkins' release records over
75
- ansible.builtin.shell: |
76
- set -euo pipefail
77
- [ -d "{{ jenkins_home.volume.Mountpoint }}/releases" ] || exit 0
78
- cp -a "{{ jenkins_home.volume.Mountpoint }}/releases/." "{{ platform_dir }}/releases/"
79
- chown -R 1000:1000 "{{ platform_dir }}/releases"
80
- args:
81
- executable: /bin/bash
82
- when: deployer_dirs.results[1] is changed and jenkins_home.exists | default(false)
83
- become: true
84
- changed_when: true
85
62
 
86
63
  # buildkit/ matters more than it looks: without buildkitd.toml the bind mount
87
64
  # has no source, Docker creates a directory in its place, and buildkitd
@@ -128,45 +105,6 @@
128
105
  code: "{{ 'src' if deployer_source.stat.exists else 'dist' }}"
129
106
  become: true
130
107
 
131
- # result and typed used to sit next to deployer/, before lib/. Drop this
132
- # once every fleet's servers have deployed lib/.
133
- - name: Remove the deployer's shared files of earlier versions
134
- ansible.builtin.file:
135
- path: "{{ platform_dir }}/deployer/app/{{ item.0 }}.{{ item.1 }}"
136
- state: absent
137
- loop: "{{ ['result', 'typed'] | product(['ts', 'js']) | list }}"
138
- become: true
139
-
140
- # The deployer's files used to sit flat in deployer/; those now in folders
141
- # are removed here, since a copy adds and never removes. Idempotent; drop it
142
- # once every fleet's servers have deployed the folders.
143
- - name: Remove the deployer's flat files of earlier versions
144
- ansible.builtin.file:
145
- path: "{{ platform_dir }}/deployer/app/deployer/{{ item.0 }}.{{ item.1 }}"
146
- state: absent
147
- loop: "{{ moved | product(['ts', 'js']) | list }}"
148
- vars:
149
- moved:
150
- - answers
151
- - builder
152
- - bundle
153
- - compose
154
- - ctl
155
- - forge
156
- - forgejo
157
- - github
158
- - github-issues
159
- - gitlab
160
- - http
161
- - notify
162
- - page
163
- - queue
164
- - records
165
- - run
166
- - store
167
- - webhook
168
- become: true
169
-
170
108
  - name: Copy the platform scripts
171
109
  ansible.builtin.copy:
172
110
  src: "{{ kayra_root }}/scripts/platform/"
@@ -354,28 +292,13 @@
354
292
  # It holds secrets: --diff (kayra plan) says that it would change, never how.
355
293
  diff: false
356
294
 
357
- # Jenkins is gone; the copies above never delete files.
358
- - name: Remove what Jenkins left
359
- ansible.builtin.file:
360
- path: "{{ platform_dir }}/{{ item }}"
361
- state: absent
362
- loop:
363
- - jenkins
364
- - jenkins-agent
365
- - jenkins-secrets
366
- - jenkins-agent.env
367
- - bin/jenkins-api
368
- - bin/jenkins-reload
369
- - bin/jenkins-app-apply
370
- become: true
371
-
372
- # The registry used to have a public, basic-auth router. Nothing outside the
373
- # server pushes or pulls, so it is gone; the copy above never deletes files.
374
- - name: Remove the retired registry basic auth
295
+ # ratelimit.yml held one app's rate limit: routes declare their own since
296
+ # 0.19.0, and the copy above never deletes files. Drop this once every
297
+ # fleet's platform servers have deployed 0.19.0 or later.
298
+ - name: Remove the retired rate limit config
375
299
  ansible.builtin.file:
376
- path: "{{ platform_dir }}/traefik/dynamic/{{ item }}"
300
+ path: "{{ platform_dir }}/traefik/dynamic/ratelimit.yml"
377
301
  state: absent
378
- loop: [registry-auth.yml, registry-htpasswd]
379
302
  become: true
380
303
 
381
304
  # ---------------------------------------------------------------------------
@@ -391,8 +314,7 @@
391
314
  ignore_buildable: true
392
315
  policy: missing
393
316
 
394
- # remove_orphans: services the platform dropped (Jenkins' controller and agent)
395
- # must not keep running.
317
+ # remove_orphans: services the platform dropped must not keep running.
396
318
  - name: Start platform
397
319
  community.docker.docker_compose_v2:
398
320
  project_src: "{{ platform_dir }}"
@@ -22,6 +22,8 @@ RENOVATE_GITHUB_COM_TOKEN={{ renovate_github_com_token }}
22
22
  RENOVATE_HOST_RULES={{ renovate_host_rules | to_json if renovate_host_rules else '' }}
23
23
  RENOVATE_REPOSITORIES={{ renovate_repositories | to_json }}
24
24
 
25
+ WEBHOOKS={{ webhooks | lower }}
26
+ DEPLOY_POLL={{ deploy_poll }}
25
27
  WEBHOOK_SECRET={{ webhook_secret }}
26
28
  SERVER={{ server }}
27
29
  NOTIFIER={{ notifier | to_json if notifier else '' }}
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const source = new URL("../cli/src/app-hook.ts", import.meta.url);
6
+ await import(existsSync(fileURLToPath(source)) ? source.href : new URL("../cli/dist/app-hook.js", import.meta.url).href);
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const source = new URL("../cli/src/app-init.ts", import.meta.url);
6
+ await import(existsSync(fileURLToPath(source)) ? source.href : new URL("../cli/dist/app-init.js", import.meta.url).href);
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const source = new URL("../cli/src/app-launch.ts", import.meta.url);
6
+ await import(existsSync(fileURLToPath(source)) ? source.href : new URL("../cli/dist/app-launch.js", import.meta.url).href);
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const source = new URL("../cli/src/app-values.ts", import.meta.url);
6
+ await import(existsSync(fileURLToPath(source)) ? source.href : new URL("../cli/dist/app-values.js", import.meta.url).href);
@@ -0,0 +1,75 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { z } from "zod";
5
+ import { forgeRepo } from "./lib/forge-repo.js";
6
+ import { ensureHook, hookApi, hookUrl } from "./core/app-hook/hooks.js";
7
+ import { operatorToken, tokenVariable } from "./core/app-hook/token.js";
8
+ import { absolutePath, appNameSchema, fleetRoot, serverNameSchema } from "./core/fleet/brand.js";
9
+ import { loadFleet } from "./core/fleet/load.js";
10
+ import { isVaulted } from "./core/fleet/parse.js";
11
+ import { takesWebhooks } from "./core/recipes/app-hook.js";
12
+ import { err, flatMap } from "./lib/result.js";
13
+ import { fields } from "./lib/yaml.js";
14
+ const input = z.strictObject({ root: z.string(), server: serverNameSchema, app: appNameSchema });
15
+ /** secrets.yml, opened with the password the step was given (ANSIBLE_VAULT_PASSWORD_FILE) where it is a vault. */
16
+ const secretsOf = (dir) => {
17
+ const file = join(dir, "secrets.yml");
18
+ const text = readFileSync(file, "utf8");
19
+ if (!isVaulted(text))
20
+ return fields(text);
21
+ const opened = spawnSync("ansible-vault", ["view", file], { encoding: "utf8" });
22
+ return opened.status === 0 ? fields(opened.stdout) : err("cannot open secrets.yml; configure vault_password_file or give the vault password");
23
+ };
24
+ const parsedJson = (text) => {
25
+ try {
26
+ return JSON.parse(text);
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ };
32
+ const http = async (url, init) => {
33
+ const response = await fetch(url, init);
34
+ return { status: response.status, json: parsedJson(await response.text()) };
35
+ };
36
+ const run = async () => {
37
+ const request = input.safeParse(JSON.parse(process.argv[2] ?? "null"));
38
+ if (!request.success)
39
+ return err("invalid app hook request");
40
+ const fleet = flatMap(absolutePath(request.data.root), (path) => loadFleet(fleetRoot(path)));
41
+ if (!fleet.ok)
42
+ return err(`the fleet could not be loaded: ${fleet.error}`);
43
+ const server = fleet.value.servers.find((each) => each.name === request.data.server);
44
+ if (server === undefined)
45
+ return err(`no server ${request.data.server}`);
46
+ const app = server.apps.find((each) => each.name === request.data.app);
47
+ if (app === undefined)
48
+ return err(`${request.data.app} is not in ${server.name}'s server.yml`);
49
+ const takes = takesWebhooks(server);
50
+ if (!takes.ok)
51
+ return takes;
52
+ const repo = forgeRepo(app.repo);
53
+ if (repo === undefined)
54
+ return err(`${app.repo} is on no forge kayra knows (GitHub, GitLab, Forgejo or Gitea): add the hook by hand, or let deploy_poll find pushes`);
55
+ const operator = operatorToken(repo);
56
+ if (operator === undefined)
57
+ return err(`no token for ${new URL(repo.origin).host}: set ${tokenVariable(new URL(repo.origin).host)} to one with admin rights on ${repo.owner}/${repo.name}`);
58
+ const secrets = secretsOf(server.dir);
59
+ if (!secrets.ok)
60
+ return secrets;
61
+ const platform = secrets.value["git_token"];
62
+ const webhook = secrets.value["webhook_secret"];
63
+ if (typeof platform !== "string" || typeof webhook !== "string")
64
+ return err(`${server.name}'s secrets.yml needs git_token and webhook_secret`);
65
+ const done = await ensureHook(hookApi(repo, http), hookUrl(server.domain, app.name), { platform, operator: operator.token }, webhook);
66
+ return done.ok ? { ok: true, value: [...done.value, ` (as you, with ${operator.from})`] } : done;
67
+ };
68
+ const result = await run().catch(() => err("the hook could not be set up; check the forge's address, the tokens and the vault"));
69
+ if (result.ok)
70
+ process.stdout.write(`${result.value.join("\n")}\n`);
71
+ else {
72
+ process.stderr.write(`${result.error}\n`);
73
+ // eslint-disable-next-line functional/immutable-data -- exit after flushing diagnostics
74
+ process.exitCode = 1;
75
+ }
@@ -0,0 +1,65 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, join } from "node:path";
4
+ import { z } from "zod";
5
+ import { envFileKeys, exposed, nameFrom, overlayFile, planInit } from "./core/app-init/plan.js";
6
+ import { names } from "./lib/names.js";
7
+ import { err, ok } from "./lib/result.js";
8
+ /** The compose file a project deploys with, as Compose itself looks for it. */
9
+ const composeNames = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
10
+ const input = z.strictObject({ root: z.string().min(1), name: z.string().optional() });
11
+ const keysOf = (path) => {
12
+ try {
13
+ return envFileKeys(readFileSync(path, "utf8"));
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ };
19
+ const sourceOf = (root, name) => {
20
+ const file = composeNames.find((each) => existsSync(join(root, each)));
21
+ if (file !== undefined) {
22
+ const config = spawnSync("docker", ["compose", "-p", name, "-f", file, "config", "--no-interpolate", "--no-env-resolution", "--format", "json"], { cwd: root, encoding: "utf8" });
23
+ if (config.status !== 0)
24
+ return err(`docker compose cannot read ${file}: ${config.stderr.trim()}`);
25
+ const parsed = JSON.parse(config.stdout);
26
+ return ok({ kind: "compose", file, config: parsed, envKeys: keysOf, isFile: (path) => existsSync(path) && statSync(path).isFile() });
27
+ }
28
+ if (existsSync(join(root, "Dockerfile")))
29
+ return ok({ kind: "dockerfile", expose: exposed(readFileSync(join(root, "Dockerfile"), "utf8")) });
30
+ return err(`no ${composeNames.join(", ")} or Dockerfile in ${root}`);
31
+ };
32
+ const run = () => {
33
+ const request = input.safeParse(JSON.parse(process.argv[2] ?? "null"));
34
+ if (!request.success)
35
+ return err("invalid app init request");
36
+ const { root } = request.data;
37
+ const name = request.data.name ?? nameFrom(basename(root));
38
+ if (name === undefined || !names.app.pattern.test(name))
39
+ return err(`no app name from ${basename(root)}: give one with --name (${names.app.what})`);
40
+ if (existsSync(join(root, "app.yml")))
41
+ return err("app.yml exists already: this project has its app contract; kayra app check checks it");
42
+ if (existsSync(join(root, dirname(overlayFile))))
43
+ return err(`${dirname(overlayFile)}/ exists already; move it away to start over`);
44
+ const source = sourceOf(root, name);
45
+ if (!source.ok)
46
+ return source;
47
+ const init = planInit(name, root, source.value);
48
+ init.files.forEach((file) => {
49
+ mkdirSync(dirname(join(root, file.path)), { recursive: true });
50
+ writeFileSync(join(root, file.path), file.content, { flag: "wx" });
51
+ });
52
+ return ok(Object.freeze([
53
+ `${name}: wrote ${init.files.map((file) => file.path).join(", ")}`,
54
+ ...init.did.map((line) => `✓ ${line}`),
55
+ ...init.todo.map((line) => `! ${line}`),
56
+ ]));
57
+ };
58
+ const result = run();
59
+ if (result.ok)
60
+ process.stdout.write(`${result.value.join("\n")}\n`);
61
+ else {
62
+ process.stderr.write(`${result.error}\n`);
63
+ // eslint-disable-next-line functional/immutable-data -- exit after flushing diagnostics
64
+ process.exitCode = 1;
65
+ }
@@ -0,0 +1,89 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { isMap, isSeq, parseDocument } from "yaml";
4
+ import { z } from "zod";
5
+ import { inspectValues } from "./core/app-values/store.js";
6
+ import { absolutePath, fleetRoot, serverNameSchema } from "./core/fleet/brand.js";
7
+ import { loadFleet } from "./core/fleet/load.js";
8
+ import { appEntrySchema } from "./core/fleet/settings.js";
9
+ import { err, flatMap, ok } from "./lib/result.js";
10
+ const input = z.strictObject({ root: z.string(), server: serverNameSchema, entry: z.record(z.string(), z.unknown()), dir: z.string().optional() });
11
+ const load = (root, name) => {
12
+ const fleet = flatMap(absolutePath(root), (path) => loadFleet(fleetRoot(path)));
13
+ if (!fleet.ok)
14
+ return err(`the fleet could not be loaded: ${fleet.error}`);
15
+ const server = fleet.value.servers.find((each) => each.name === name);
16
+ return server === undefined ? err(`no server ${name} in the fleet`) : ok({ root: fleet.value.root, server });
17
+ };
18
+ /** The entry appended to server.yml's apps, its comments and order kept. */
19
+ const register = (server, entry) => {
20
+ const file = join(server.dir, "server.yml");
21
+ const document = parseDocument(readFileSync(file, "utf8"));
22
+ const apps = document.get("apps");
23
+ if (apps !== undefined && apps !== null && !isSeq(apps))
24
+ return err(`${file}: apps is not a list`);
25
+ if (isSeq(apps))
26
+ apps.add(document.createNode(entry));
27
+ else
28
+ document.set("apps", document.createNode([entry]));
29
+ if (!isMap(document.contents))
30
+ return err(`${file} is not a mapping`);
31
+ writeFileSync(file, document.toString());
32
+ return ok(file);
33
+ };
34
+ const command = (server, app, kind, key) => kind === "config"
35
+ ? `kayra app config set ${server.name} ${app} ${key} VALUE`
36
+ : `kayra app secret generate ${server.name} ${app} ${key} (or: app secret import ${server.name} ${app} ${key} FILE)`;
37
+ const run = async () => {
38
+ const request = input.safeParse(JSON.parse(process.argv[2] ?? "null"));
39
+ if (!request.success)
40
+ return err("invalid app launch request");
41
+ const entry = appEntrySchema.safeParse(request.data.entry);
42
+ if (!entry.success)
43
+ return err("invalid app entry");
44
+ const app = entry.data.name;
45
+ const dir = request.data.dir === undefined ? ok(undefined) : absolutePath(request.data.dir);
46
+ if (!dir.ok)
47
+ return dir;
48
+ const before = load(request.data.root, request.data.server);
49
+ if (!before.ok)
50
+ return before;
51
+ const lines = before.value.server.apps.some((each) => each.name === app)
52
+ ? [`✓ ${app} is registered in ${before.value.server.name}'s server.yml`]
53
+ : (() => {
54
+ const written = register(before.value.server, request.data.entry);
55
+ if (!written.ok)
56
+ return [`✗ ${written.error}`];
57
+ return [
58
+ `✓ registered ${app} in ${written.value}`,
59
+ ...(before.value.server.target === "multipass"
60
+ ? []
61
+ : [` ${before.value.server.name} is a ${before.value.server.target} server: commit this change and merge it to main, then run the launch again`]),
62
+ ];
63
+ })();
64
+ if (lines[0]?.startsWith("✗") === true)
65
+ return err(lines[0].slice(2));
66
+ const after = load(request.data.root, request.data.server);
67
+ if (!after.ok)
68
+ return after;
69
+ const values = await inspectValues(after.value.root, after.value.server, app, dir.value);
70
+ if (!values.ok)
71
+ return err(`${lines.join("\n")}\n${values.error}`);
72
+ const missing = [
73
+ ...values.value.config.filter((each) => each.state === "missing").map((each) => command(after.value.server, app, "config", each.key)),
74
+ ...values.value.secrets.filter((each) => each.state === "missing").map((each) => command(after.value.server, app, "secret", each.key)),
75
+ ];
76
+ if (values.value.hint !== null)
77
+ return err(`${lines.join("\n")}\n${values.value.hint}`);
78
+ if (missing.length > 0)
79
+ return err(`${lines.join("\n")}\n${app} needs ${String(missing.length)} value(s) before it can run; set them, then run the launch again:\n${missing.map((line) => ` ${line}`).join("\n")}`);
80
+ return ok([...lines, `✓ every value ${app} declares is set (${String(values.value.config.length)} config, ${String(values.value.secrets.length)} secret)`]);
81
+ };
82
+ const result = await run().catch(() => err("the launch could not prepare the app; check file access and vault configuration"));
83
+ if (result.ok)
84
+ process.stdout.write(`${result.value.join("\n")}\n`);
85
+ else {
86
+ process.stderr.write(`${result.error}\n`);
87
+ // eslint-disable-next-line functional/immutable-data -- exit after flushing diagnostics
88
+ process.exitCode = 1;
89
+ }
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ import { absolutePath, appNameSchema, fleetRoot, serverNameSchema } from "./core/fleet/brand.js";
3
+ import { loadFleet } from "./core/fleet/load.js";
4
+ import { editSchema } from "./core/app-values/model.js";
5
+ import { editValues } from "./core/app-values/store.js";
6
+ import { err, flatMap } from "./lib/result.js";
7
+ const input = z.strictObject({ root: z.string(), server: serverNameSchema, app: appNameSchema, edit: editSchema, dir: z.string().optional() });
8
+ const run = async () => {
9
+ try {
10
+ const request = input.safeParse(JSON.parse(process.argv[2] ?? ""));
11
+ if (!request.success)
12
+ return err("invalid app values request");
13
+ const { root, server, app, edit, dir } = request.data;
14
+ const fleet = flatMap(absolutePath(root), (path) => loadFleet(fleetRoot(path)));
15
+ if (!fleet.ok)
16
+ return err("the fleet could not be loaded; run kayra validate");
17
+ const target = fleet.value.servers.find((each) => each.name === server);
18
+ if (target === undefined)
19
+ return err("server is not in the fleet");
20
+ const directory = dir === undefined ? undefined : absolutePath(dir);
21
+ if (directory !== undefined && !directory.ok)
22
+ return directory;
23
+ return await editValues(fleet.value.root, target, app, edit, directory?.value);
24
+ }
25
+ catch {
26
+ // Errors may contain YAML or imported secret text. None reaches a run record.
27
+ return err("app values could not be updated; check file access and vault configuration");
28
+ }
29
+ };
30
+ const result = await run();
31
+ if (result.ok)
32
+ process.stdout.write(`${result.value}\n`);
33
+ else {
34
+ process.stderr.write(`${result.error}\n`);
35
+ // eslint-disable-next-line functional/immutable-data -- exit after flushing diagnostics
36
+ process.exitCode = 1;
37
+ }