@yunuseon/kayra 0.24.0 → 0.24.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.
@@ -7,7 +7,8 @@
7
7
  # {{ apps_dir }}/<app>/.env operator config for compose
8
8
  # app-apply secrets → app-secrets/<app>/
9
9
  # app-restore a deployed app that runs
10
- # nothing, deployed again
10
+ # nothing, or whose registration
11
+ # or .env changed, deployed again
11
12
  # {{ platform_dir }}/apps/<app>.json the registration the deployer
12
13
  # and the builder read
13
14
  #
@@ -99,6 +100,7 @@
99
100
  owner: deploy
100
101
  group: deploy
101
102
  mode: "0644"
103
+ register: app_env
102
104
  become: true
103
105
 
104
106
  # Secrets before the registration: a push in between finds them in place.
@@ -127,17 +129,22 @@
127
129
  path: "{{ app.path | default('.') }}"
128
130
  hosts: "{{ app_subdomains | map('regex_replace', '$', '.' ~ domain) | list }}"
129
131
  secrets: "{{ manifest.secrets | default([]) }}"
132
+ register: app_registration
130
133
  become: true
131
134
 
132
135
  # A Docker update or a reboot stops every container, and one deployed before
133
136
  # the platform gave each service a restart policy stays down (bin/app-restore).
137
+ # A changed registration or .env (a new domain moves every host; new config)
138
+ # reaches a running app only by a deploy: until then it keeps the routes and
139
+ # environment it started with, and a new domain's redirects send visitors to
140
+ # hosts it does not serve. So then it is deployed again at the release it runs.
134
141
  # The retries wait out a deployer the host layer has just restarted.
135
- - name: Restore the app if it was deployed but runs nothing
142
+ - name: Restore the app if it was deployed but runs nothing, or redeploy it if its registration changed
136
143
  ansible.builtin.command:
137
- cmd: "{{ platform_dir }}/bin/app-restore {{ app.name }}"
144
+ cmd: "{{ platform_dir }}/bin/app-restore {{ app.name }}{{ ' --changed' if (app_env is changed or app_registration is changed) else '' }}"
138
145
  register: app_restored
139
146
  retries: 5
140
147
  delay: 3
141
148
  until: app_restored.rc == 0
142
- changed_when: "'restored ' in app_restored.stdout"
149
+ changed_when: "'restored ' in app_restored.stdout or 'redeployed ' in app_restored.stdout"
143
150
  become: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yunuseon/kayra",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "description": "A self-hosted app platform and the CLI that runs it: Traefik, Authelia, a registry, rootless BuildKit and a small deployer per server, set up with OpenTofu and Ansible.",
5
5
  "license": "MIT",
6
6
  "author": "Yunus Öztürk",
@@ -1,20 +1,30 @@
1
1
  #!/usr/bin/env bash
2
2
  # =============================================================================
3
- # app-restore <app> — an app that was deployed, yet runs no container now,
4
- # deployed again at the release that ran.
3
+ # app-restore <app> [--changed] — an app that was deployed, yet runs no
4
+ # container now, deployed again at the release that ran. With --changed, the
5
+ # app's registration or .env has just changed (its hosts, after a new domain;
6
+ # its config): it is deployed again at that release even if it runs, since a
7
+ # running deploy keeps the routes and environment it was started with.
5
8
  #
6
9
  # A Docker update or a reboot stops every container; one deployed before the
7
10
  # platform gave each service a restart policy stays down. The deployer's ctl
8
11
  # follows the run to its end, so this exits as the run did. An app never
9
- # deployed (no release record) and one that runs are left alone.
12
+ # deployed (no release record) is left alone, and so is one that runs unless
13
+ # --changed.
10
14
  #
11
15
  # Installed by the platform role at <platform_dir>/bin; run by the app role
12
16
  # after it registers the app. Run as root. Prints what it did on its last line:
13
- # "never deployed", "runs", or "restored <sha>".
17
+ # "never deployed", "runs", "restored <sha>" or "redeployed <sha>".
14
18
  # =============================================================================
15
19
  set -euo pipefail
16
20
 
17
- app="${1:?Usage: app-restore <app>}"
21
+ app="${1:?Usage: app-restore <app> [--changed]}"
22
+ changed=false
23
+ case "${2:-}" in
24
+ "") ;;
25
+ --changed) changed=true ;;
26
+ *) echo "Usage: app-restore <app> [--changed]" >&2; exit 2 ;;
27
+ esac
18
28
  platform_dir="${PLATFORM_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
19
29
  releases="${platform_dir}/releases/${app}"
20
30
 
@@ -29,11 +39,12 @@ if [ -z "$live" ]; then
29
39
  exit 0
30
40
  fi
31
41
 
32
- if [ -n "$(docker ps -q --filter "label=com.docker.compose.project=${app}" --filter status=running --filter status=restarting)" ]; then
42
+ running="$(docker ps -q --filter "label=com.docker.compose.project=${app}" --filter status=running --filter status=restarting)"
43
+ if [ -n "$running" ] && [ "$changed" = false ]; then
33
44
  echo "runs"
34
45
  exit 0
35
46
  fi
36
47
 
37
48
  cd "$platform_dir"
38
49
  docker compose exec -T deployer kayra-deployer ctl deploy "$app" "$live"
39
- echo "restored ${live}"
50
+ if [ -n "$running" ]; then echo "redeployed ${live}"; else echo "restored ${live}"; fi