@yunuseon/kayra 0.19.0 → 0.20.1
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.
- package/agent/skills/kayra-release/SKILL.md +1 -4
- package/agent/skills/kayra-rollout/SKILL.md +1 -4
- package/ansible/roles/app/tasks/main.yml +24 -0
- package/ansible/roles/platform/defaults/main.yml +3 -0
- package/ansible/roles/platform/tasks/main.yml +6 -86
- package/ansible/roles/platform/templates/platform.env.j2 +2 -0
- package/bin/kayra-app-hook.js +6 -0
- package/bin/kayra-app-init.js +6 -0
- package/bin/kayra-app-launch.js +6 -0
- package/bin/kayra-app-values.js +6 -0
- package/cli/dist/app-hook.js +75 -0
- package/cli/dist/app-init.js +65 -0
- package/cli/dist/app-launch.js +89 -0
- package/cli/dist/app-values.js +37 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-400-normal-BTotfTJu.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-400-normal-DZqxrq2p.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-600-normal-71GNu3SW.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-600-normal-BGq0mW3O.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-400-normal-Dsrv2Tcn.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-400-normal-g30qAdWV.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-600-normal-Bz0x94Yp.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-600-normal-DUMzJB7m.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-400-normal-D9ESIMu3.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-400-normal-_efipK4i.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-600-normal-D-CqTdkO.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-600-normal-DzTrcv_p.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-400-normal-C5H60-Va.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-400-normal-RBey6euL.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-600-normal-DIrixKbi.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-600-normal-DOrvGEcy.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-400-normal-DG4YqDda.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-400-normal-fK1oJ5dG.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-600-normal-DgdngZtN.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-600-normal-DpPYBSTl.woff2 +0 -0
- package/cli/dist/browser/assets/index-DzIVPXyL.css +1 -0
- package/cli/dist/browser/assets/index-SP8bCDrl.js +7 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-600-normal-8K4wrrwR.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-700-normal-BWTpRfYl.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-700-normal-CEoEElIJ.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-600-normal-mc2nkWzM.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-700-normal-C6CZE3T8.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-700-normal-DEigVDxa.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-600-normal-BfsvjouI.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-700-normal-BYuf6tUa.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-700-normal-D3wTyLJW.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-600-normal-DObL3zCW.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-700-normal-CZipNAKV.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-700-normal-CxPITLHs.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-600-normal-OWROknRo.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-700-normal-BDLVIk2r.woff +0 -0
- package/cli/dist/browser/index.html +10 -3
- package/cli/dist/clients/api/start.js +1 -1
- package/cli/dist/clients/cli/invocation.js +25 -0
- package/cli/dist/clients/cli/parser.js +24 -7
- package/cli/dist/clients/cli/text.js +3 -3
- package/cli/dist/clients/cli/values.js +0 -1
- package/cli/dist/clients/cli/views.js +9 -2
- package/cli/dist/clients/mcp/tools.js +8 -1
- package/cli/dist/clients/ui/assets.js +1 -0
- package/cli/dist/clients/wire/contract.js +2 -2
- package/cli/dist/clients/wire/queries.js +1 -0
- package/cli/dist/clients/wire/schemas.js +4 -1
- package/cli/dist/clients/wire/words.js +14 -0
- package/cli/dist/core/adapters/opentofu.js +1 -1
- package/cli/dist/core/app-hook/hooks.js +90 -0
- package/cli/dist/core/app-hook/token.js +49 -0
- package/cli/dist/core/app-init/plan.js +208 -0
- package/cli/dist/core/app-values/model.js +45 -0
- package/cli/dist/core/app-values/store.js +124 -0
- package/cli/dist/core/ctl/answers.js +14 -9
- package/cli/dist/core/fleet/brand.js +10 -12
- package/cli/dist/core/fleet/settings.js +14 -9
- package/cli/dist/core/operations/catalog.js +46 -1
- package/cli/dist/core/operations/dispatch.js +37 -6
- package/cli/dist/core/recipes/app-check.js +14 -1
- package/cli/dist/core/recipes/app-hook.js +26 -0
- package/cli/dist/core/recipes/app-values.js +21 -0
- package/cli/dist/core/recipes/doctor.js +2 -2
- package/cli/dist/core/recipes/launch.js +51 -0
- package/cli/dist/core/validation/facts.js +1 -3
- package/cli/dist/deployer/brand.js +8 -5
- package/cli/dist/deployer/build/builder.js +10 -4
- package/cli/dist/deployer/build/client.js +44 -0
- package/cli/dist/deployer/build/routes.js +27 -6
- package/cli/dist/deployer/ctl/answers.js +6 -2
- package/cli/dist/deployer/ctl/ctl.js +66 -9
- package/cli/dist/deployer/deployer.js +113 -196
- package/cli/dist/deployer/forges/forge.js +0 -12
- package/cli/dist/deployer/forges/notify.js +3 -3
- package/cli/dist/deployer/http/http.js +0 -1
- package/cli/dist/deployer/http/page.js +4 -2
- package/cli/dist/deployer/http/webhook.js +0 -1
- package/cli/dist/deployer/runs/effects.js +70 -0
- package/cli/dist/deployer/runs/queue.js +5 -4
- package/cli/dist/deployer/runs/records.js +22 -3
- package/cli/dist/deployer/runs/restore.js +6 -0
- package/cli/dist/deployer/runs/run.js +51 -5
- package/cli/dist/deployer/runs/store.js +19 -3
- package/cli/dist/deployer/settings.js +69 -0
- package/cli/dist/lib/forge-repo.js +15 -0
- package/cli/dist/lib/names.js +13 -0
- package/cli/dist/main.js +46 -25
- package/compose/docker-compose.ci.yml +2 -0
- package/package.json +2 -2
- package/schema/app.json +5 -0
- package/schema/defaults.json +8 -0
- package/schema/vars-platform.json +8 -0
- package/scripts/local/verify.sh +9 -2
- package/terraform/modules/platform-dns/main.tf +66 -0
- package/terraform/modules/platform-dns/outputs.tf +9 -0
- package/terraform/modules/platform-dns/tests/fleet/.cache/apps/blog/site/app.yml +3 -0
- package/terraform/modules/platform-dns/tests/fleet/.cache/apps/shop/app.yml +6 -0
- package/terraform/modules/platform-dns/tests/fleet/servers/nested/server.yml +6 -0
- package/terraform/modules/platform-dns/tests/fleet/servers/shop/server.yml +7 -0
- package/terraform/modules/platform-dns/tests/fleet/servers/uncloned/server.yml +6 -0
- package/terraform/modules/platform-dns/tests/platform-dns.tftest.hcl +64 -0
- package/terraform/modules/platform-dns/variables.tf +25 -0
- package/cli/dist/browser/assets/index-C4HCL022.js +0 -7
- package/cli/dist/browser/assets/index-Ct0Eudk4.css +0 -1
- 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.
|
|
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.
|
|
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
|
|
|
@@ -125,3 +125,27 @@
|
|
|
125
125
|
hosts: "{{ app_subdomains | map('regex_replace', '$', '.' ~ domain) | list }}"
|
|
126
126
|
secrets: "{{ manifest.secrets | default([]) }}"
|
|
127
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
|
+
releases={{ platform_dir }}/releases/{{ app.name }}
|
|
138
|
+
if [ ! -d "$releases" ]; then echo "never deployed"; exit 0; fi
|
|
139
|
+
live="$(find "$releases" -maxdepth 1 -name '*.env' -printf '%f\n' | sort | tail -1 | sed -n 's/^[0-9]\{8\}T[0-9]\{6\}Z-\([0-9a-f]\{40\}\)\.env$/\1/p')"
|
|
140
|
+
if [ -z "$live" ]; then echo "never deployed"; exit 0; fi
|
|
141
|
+
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
|
|
142
|
+
cd {{ platform_dir }}
|
|
143
|
+
docker compose exec -T deployer kayra-deployer ctl deploy {{ app.name }} "$live"
|
|
144
|
+
echo "restored ${live}"
|
|
145
|
+
executable: /bin/bash
|
|
146
|
+
register: app_restored
|
|
147
|
+
retries: 5
|
|
148
|
+
delay: 3
|
|
149
|
+
until: app_restored.rc == 0
|
|
150
|
+
changed_when: "'restored ' in app_restored.stdout"
|
|
151
|
+
become: true
|
|
@@ -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,30 +292,13 @@
|
|
|
354
292
|
# It holds secrets: --diff (kayra plan) says that it would change, never how.
|
|
355
293
|
diff: false
|
|
356
294
|
|
|
357
|
-
#
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
# Retired dynamic config; the copy above never deletes files. The registry
|
|
373
|
-
# used to have a public, basic-auth router, but nothing outside the server
|
|
374
|
-
# pushes or pulls. ratelimit.yml held one app's rate limit: routes declare
|
|
375
|
-
# their own now.
|
|
376
|
-
- name: Remove retired Traefik dynamic config
|
|
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
|
|
377
299
|
ansible.builtin.file:
|
|
378
|
-
path: "{{ platform_dir }}/traefik/dynamic/
|
|
300
|
+
path: "{{ platform_dir }}/traefik/dynamic/ratelimit.yml"
|
|
379
301
|
state: absent
|
|
380
|
-
loop: [registry-auth.yml, registry-htpasswd, ratelimit.yml]
|
|
381
302
|
become: true
|
|
382
303
|
|
|
383
304
|
# ---------------------------------------------------------------------------
|
|
@@ -393,8 +314,7 @@
|
|
|
393
314
|
ignore_buildable: true
|
|
394
315
|
policy: missing
|
|
395
316
|
|
|
396
|
-
# remove_orphans: services the platform dropped
|
|
397
|
-
# must not keep running.
|
|
317
|
+
# remove_orphans: services the platform dropped must not keep running.
|
|
398
318
|
- name: Start platform
|
|
399
319
|
community.docker.docker_compose_v2:
|
|
400
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
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|