@fabrika/provider-zerops 0.9.0-dev.1 → 0.9.0-dev.10

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 (174) hide show
  1. package/package.json +17 -14
  2. package/sandbox/Dockerfile +16 -0
  3. package/sandbox/bin/postgres-auth.sh +38 -0
  4. package/sandbox/bin/reset.sh +12 -0
  5. package/sandbox/bin/run-build.sh +35 -0
  6. package/sandbox/bin/run-launcher.sh +18 -0
  7. package/sandbox/bin/start-launcher.sh +25 -0
  8. package/sandbox/bin/stop.sh +47 -0
  9. package/sandbox/init.sh +61 -0
  10. package/src/api/client.ts +15 -1
  11. package/src/api/errors.ts +7 -3
  12. package/src/api/readers.ts +29 -0
  13. package/src/api/types.ts +52 -0
  14. package/src/api.ts +2 -0
  15. package/src/cli.ts +11 -0
  16. package/src/collaborators.ts +0 -14
  17. package/src/compile.ts +1 -1
  18. package/src/control.ts +159 -92
  19. package/src/execution.ts +45 -195
  20. package/src/index.ts +2 -0
  21. package/src/installation/admin.ts +1 -1
  22. package/src/installation/deploy-options.ts +1 -2
  23. package/src/installation/deploy.ts +225 -80
  24. package/src/installation/generated/platform-console-schema.ts +3 -0
  25. package/src/installation/generated/platform-proxy-manifest.ts +1 -1
  26. package/src/installation/guide.md +48 -18
  27. package/src/installation/hosts.ts +1 -7
  28. package/src/installation/index.ts +13 -16
  29. package/src/installation/init-options.ts +2 -1
  30. package/src/installation/install-environment.ts +47 -108
  31. package/src/installation/install-options.ts +3 -1
  32. package/src/installation/install-secrets.ts +24 -68
  33. package/src/installation/install.ts +9 -4
  34. package/src/installation/sidecar.ts +5 -26
  35. package/src/installation/topology/setups.ts +17 -4
  36. package/src/installation/topology/topology.ts +32 -22
  37. package/src/installation/upgrade-options.ts +2 -2
  38. package/src/managed-env.ts +1 -174
  39. package/src/manifest.ts +4 -16
  40. package/src/namespace/claims.ts +60 -1
  41. package/src/namespace/codec.ts +17 -0
  42. package/src/namespace/errors.ts +22 -1
  43. package/src/namespace/manifest.ts +36 -23
  44. package/src/namespace/provisioning.ts +88 -114
  45. package/src/namespace/proxy-attempt.ts +14 -2
  46. package/src/namespace/proxy-reads.ts +28 -23
  47. package/src/namespace/proxy-secrets.ts +18 -5
  48. package/src/namespace/sandbox-host.ts +212 -0
  49. package/src/namespace/subdomain.ts +113 -0
  50. package/src/namespace/topology.ts +1 -1
  51. package/src/namespace/types.ts +13 -0
  52. package/src/namespace/update.ts +1 -0
  53. package/src/namespace-cli.ts +152 -0
  54. package/src/plan.ts +1 -6
  55. package/src/provider.ts +88 -166
  56. package/src/proxy-manifest-carrier.ts +39 -0
  57. package/src/sandbox/base-image.ts +100 -0
  58. package/src/sandbox/constants.ts +44 -0
  59. package/src/sandbox/deploy.ts +471 -0
  60. package/src/sandbox/dev-artifact.ts +206 -0
  61. package/src/sandbox/lifecycle.ts +204 -0
  62. package/src/sandbox/scripts.ts +26 -0
  63. package/src/sandbox-host.ts +28 -0
  64. package/src/source/port.ts +5 -0
  65. package/src/types.ts +0 -2
  66. package/src/zbox/client.ts +259 -0
  67. package/src/zbox/errors.ts +45 -0
  68. package/src/zbox/index.ts +22 -0
  69. package/src/zbox/types.ts +165 -0
  70. package/types/src/api/client.d.ts +5 -0
  71. package/types/src/api/errors.d.ts +26 -0
  72. package/types/src/api/polling.d.ts +41 -0
  73. package/types/src/api/readers.d.ts +1115 -0
  74. package/types/src/api/service-env-limit.d.ts +17 -0
  75. package/types/src/api/service-env-response.d.ts +23 -0
  76. package/types/src/api/types.d.ts +687 -0
  77. package/types/src/api.d.ts +6 -0
  78. package/types/src/authoring.d.ts +9 -0
  79. package/types/src/cli-args.d.ts +19 -0
  80. package/types/src/cli.d.ts +13 -0
  81. package/types/src/collaborators.d.ts +16 -0
  82. package/types/src/compile.d.ts +91 -0
  83. package/types/src/control.d.ts +51 -0
  84. package/types/src/database-budget.d.ts +38 -0
  85. package/types/src/descriptor.d.ts +28 -0
  86. package/types/src/execution.d.ts +114 -0
  87. package/types/src/exposure.d.ts +47 -0
  88. package/types/src/index.d.ts +31 -0
  89. package/types/src/installation/admin-options.d.ts +24 -0
  90. package/types/src/installation/admin.d.ts +35 -0
  91. package/types/src/installation/checker-release.d.ts +12 -0
  92. package/types/src/installation/deploy-options.d.ts +37 -0
  93. package/types/src/installation/deploy.d.ts +136 -0
  94. package/types/src/installation/generated/platform-console-schema.d.ts +2 -0
  95. package/types/src/installation/generated/platform-proxy-manifest.d.ts +2 -0
  96. package/types/src/installation/hosts.d.ts +34 -0
  97. package/types/src/installation/index.d.ts +7 -0
  98. package/types/src/installation/init-options.d.ts +38 -0
  99. package/types/src/installation/init.d.ts +60 -0
  100. package/types/src/installation/install-collaborators.d.ts +24 -0
  101. package/types/src/installation/install-environment.d.ts +63 -0
  102. package/types/src/installation/install-options.d.ts +49 -0
  103. package/types/src/installation/install-project.d.ts +13 -0
  104. package/types/src/installation/install-provisioning.d.ts +58 -0
  105. package/types/src/installation/install-secrets.d.ts +17 -0
  106. package/types/src/installation/install-token.d.ts +10 -0
  107. package/types/src/installation/install.d.ts +23 -0
  108. package/types/src/installation/installation-source.d.ts +8 -0
  109. package/types/src/installation/log.d.ts +44 -0
  110. package/types/src/installation/machine-key.d.ts +19 -0
  111. package/types/src/installation/placement-options.d.ts +11 -0
  112. package/types/src/installation/platform-archive.d.ts +7 -0
  113. package/types/src/installation/platform-source.d.ts +8 -0
  114. package/types/src/installation/platform-upload.d.ts +3 -0
  115. package/types/src/installation/sidecar.d.ts +49 -0
  116. package/types/src/installation/source-options.d.ts +1 -0
  117. package/types/src/installation/topology/artifacts.d.ts +8 -0
  118. package/types/src/installation/topology/index.d.ts +5 -0
  119. package/types/src/installation/topology/installation-schemas.d.ts +2242 -0
  120. package/types/src/installation/topology/invariants.d.ts +23 -0
  121. package/types/src/installation/topology/setups.d.ts +59 -0
  122. package/types/src/installation/topology/topology.d.ts +153 -0
  123. package/types/src/installation/topology/validate.d.ts +11 -0
  124. package/types/src/installation/upgrade-options.d.ts +26 -0
  125. package/types/src/installation/upgrade-output.d.ts +6 -0
  126. package/types/src/installation/upgrade.d.ts +88 -0
  127. package/types/src/managed-env.d.ts +24 -0
  128. package/types/src/manifest.d.ts +199 -0
  129. package/types/src/namespace/claims.d.ts +16 -0
  130. package/types/src/namespace/codec.d.ts +352 -0
  131. package/types/src/namespace/constants.d.ts +25 -0
  132. package/types/src/namespace/errors.d.ts +25 -0
  133. package/types/src/namespace/manifest.d.ts +4 -0
  134. package/types/src/namespace/operator.d.ts +12 -0
  135. package/types/src/namespace/provisioning.d.ts +4 -0
  136. package/types/src/namespace/proxy-attempt.d.ts +39 -0
  137. package/types/src/namespace/proxy-reads.d.ts +27 -0
  138. package/types/src/namespace/proxy-secrets.d.ts +8 -0
  139. package/types/src/namespace/proxy-source.d.ts +74 -0
  140. package/types/src/namespace/sandbox-host.d.ts +23 -0
  141. package/types/src/namespace/subdomain.d.ts +43 -0
  142. package/types/src/namespace/topology.d.ts +9 -0
  143. package/types/src/namespace/types.d.ts +111 -0
  144. package/types/src/namespace/update.d.ts +6 -0
  145. package/types/src/namespace/validation.d.ts +12 -0
  146. package/types/src/namespace-cli.d.ts +2 -0
  147. package/types/src/namespace.d.ts +9 -0
  148. package/types/src/plan.d.ts +11 -0
  149. package/types/src/provider.d.ts +60 -0
  150. package/types/src/proxy-manifest-carrier.d.ts +37 -0
  151. package/types/src/sandbox/base-image.d.ts +28 -0
  152. package/types/src/sandbox/constants.d.ts +30 -0
  153. package/types/src/sandbox/deploy.d.ts +75 -0
  154. package/types/src/sandbox/dev-artifact.d.ts +51 -0
  155. package/types/src/sandbox/lifecycle.d.ts +27 -0
  156. package/types/src/sandbox/scripts.d.ts +11 -0
  157. package/types/src/sandbox-host.d.ts +16 -0
  158. package/types/src/schema.generated.d.ts +376 -0
  159. package/types/src/service-names.d.ts +4 -0
  160. package/types/src/service-references.d.ts +13 -0
  161. package/types/src/source/constants.d.ts +6 -0
  162. package/types/src/source/port.d.ts +65 -0
  163. package/types/src/source/types.d.ts +4 -0
  164. package/types/src/source/validation.d.ts +19 -0
  165. package/types/src/source.d.ts +2 -0
  166. package/types/src/types.d.ts +119 -0
  167. package/types/src/version-attempt.d.ts +8 -0
  168. package/types/src/zbox/client.d.ts +2 -0
  169. package/types/src/zbox/errors.d.ts +25 -0
  170. package/types/src/zbox/index.d.ts +3 -0
  171. package/types/src/zbox/types.d.ts +433 -0
  172. package/src/installation/mcp.ts +0 -102
  173. package/src/installation/proxy-manifest.ts +0 -214
  174. package/src/installation/secrets.ts +0 -78
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/provider-zerops",
3
- "version": "0.9.0-dev.1",
3
+ "version": "0.9.0-dev.10",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,27 +12,29 @@
12
12
  },
13
13
  "files": [
14
14
  "src",
15
- "!src/**/__tests__/**"
15
+ "sandbox",
16
+ "!src/**/__tests__/**",
17
+ "types"
16
18
  ],
17
19
  "exports": {
18
20
  ".": {
19
21
  "bun": "./src/index.ts",
20
- "types": "./src/index.ts",
22
+ "types": "./types/src/index.d.ts",
21
23
  "default": "./src/index.ts"
22
24
  },
23
25
  "./cli": {
24
26
  "bun": "./src/cli.ts",
25
- "types": "./src/cli.ts",
27
+ "types": "./types/src/cli.d.ts",
26
28
  "default": "./src/cli.ts"
27
29
  },
28
30
  "./installation": {
29
31
  "bun": "./src/installation/index.ts",
30
- "types": "./src/installation/index.ts",
32
+ "types": "./types/src/installation/index.d.ts",
31
33
  "default": "./src/installation/index.ts"
32
34
  },
33
35
  "./installation/topology": {
34
36
  "bun": "./src/installation/topology/index.ts",
35
- "types": "./src/installation/topology/index.ts",
37
+ "types": "./types/src/installation/topology/index.d.ts",
36
38
  "default": "./src/installation/topology/index.ts"
37
39
  }
38
40
  },
@@ -43,14 +45,15 @@
43
45
  },
44
46
  "dependencies": {
45
47
  "zod": "^3.25.76",
46
- "@fabrika/auth": "0.9.0-dev.1",
47
- "@fabrika/auth-core": "0.9.0-dev.1",
48
- "@fabrika/email": "0.9.0-dev.1",
49
- "@fabrika/iam-contract": "0.9.0-dev.1",
50
- "@fabrika/installation-init": "0.9.0-dev.1",
51
- "@fabrika/operations-contract": "0.9.0-dev.1",
52
- "@fabrika/provider-contract": "0.9.0-dev.1",
53
- "@fabrika/proxy-core": "0.9.0-dev.1",
48
+ "@fabrika/app": "0.9.0-dev.10",
49
+ "@fabrika/auth": "0.9.0-dev.10",
50
+ "@fabrika/auth-core": "0.9.0-dev.10",
51
+ "@fabrika/email": "0.9.0-dev.10",
52
+ "@fabrika/iam-contract": "0.9.0-dev.10",
53
+ "@fabrika/installation-init": "0.9.0-dev.10",
54
+ "@fabrika/operations-contract": "0.9.0-dev.10",
55
+ "@fabrika/provider-contract": "0.9.0-dev.10",
56
+ "@fabrika/proxy-core": "0.9.0-dev.10",
54
57
  "yaml": "^2.9.1"
55
58
  }
56
59
  }
@@ -0,0 +1,16 @@
1
+ # The base of every dev workspace sandbox: Bun, a PostgreSQL that listens on 127.0.0.1 only, the unprivileged user the
2
+ # build runs as, and the init script. Built on the sandbox host by `POST /base-build`; its name carries the hash of this
3
+ # directory's base files. Every other script reaches a sandbox with each deploy (`bin/`), so a fix needs no new base.
4
+ FROM oven/bun:1.3.14-alpine@sha256:efc5e42c7bedc1661ab0b7272c74c3ebf794f054297f530a62055f2d1a0eb662
5
+
6
+ # The PostgreSQL major is pinned by the package name; the patch floats, because Alpine drops a revision from its index
7
+ # once a newer one ships, and a pinned revision would then fail every later base build.
8
+ RUN apk add --no-cache postgresql17 postgresql17-contrib su-exec \
9
+ && adduser -D -h /home/fabrika-build -s /sbin/nologin -u 10001 fabrika-build
10
+
11
+ COPY init.sh /usr/local/lib/fabrika/
12
+
13
+ WORKDIR /app
14
+
15
+ ENTRYPOINT ["/bin/sh"]
16
+ CMD ["/usr/local/lib/fabrika/init.sh"]
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Converges PostgreSQL's authentication before every build: the socket only root and PostgreSQL reach trusts every
3
+ # connection, and TCP on 127.0.0.1 takes the superuser's password, which only root can read. The build user can thus
4
+ # neither read a credential nor connect as the superuser.
5
+ set -eu
6
+
7
+ STATE=/var/lib/fabrika
8
+ PGDATA=$STATE/postgres
9
+ PASSWORD_FILE=$STATE/postgres-password
10
+
11
+ chown postgres:postgres /run/postgresql
12
+ chmod 700 /run/postgresql
13
+
14
+ waited=0
15
+ until su-exec postgres pg_isready -q -h /run/postgresql; do
16
+ if [ "$waited" -ge 60 ]; then
17
+ echo 'fabrika sandbox: PostgreSQL is not running'
18
+ exit 1
19
+ fi
20
+ sleep 1
21
+ waited=$((waited + 1))
22
+ done
23
+
24
+ if [ ! -s "$PASSWORD_FILE" ]; then
25
+ (
26
+ umask 077
27
+ head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' >"$PASSWORD_FILE.tmp"
28
+ )
29
+ mv "$PASSWORD_FILE.tmp" "$PASSWORD_FILE"
30
+ fi
31
+ chmod 600 "$PASSWORD_FILE"
32
+
33
+ # Through stdin, so the password is in no process's arguments.
34
+ printf "ALTER ROLE postgres PASSWORD '%s';\n" "$(cat "$PASSWORD_FILE")" \
35
+ | su-exec postgres psql -X -q -v ON_ERROR_STOP=1 -h /run/postgresql -U postgres -d postgres -f - >/dev/null
36
+ printf '%s\n' 'local all all trust' 'host all all 127.0.0.1/32 scram-sha-256' >"$PGDATA/pg_hba.conf"
37
+ chown postgres:postgres "$PGDATA/pg_hba.conf"
38
+ su-exec postgres pg_ctl -D "$PGDATA" reload >/dev/null
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+ # What every deploy runs before it touches the application root: stop the previous launcher and any build still running,
3
+ # delete the launcher's environment so the untrusted build cannot read it, and converge PostgreSQL's authentication.
4
+ set -eu
5
+
6
+ BIN=$(dirname "$0")
7
+ STATE=/var/lib/fabrika
8
+
9
+ /bin/sh "$BIN/stop.sh" launcher
10
+ /bin/sh "$BIN/stop.sh" build
11
+ rm -f "$STATE/env" /app/fabrika/dev-booted
12
+ /bin/sh "$BIN/postgres-auth.sh"
@@ -0,0 +1,35 @@
1
+ #!/bin/sh
2
+ # Runs the build steps the deploy wrote to /var/lib/fabrika/build/<n>.sh, in order, each as the unprivileged build user
3
+ # with a clean environment from the application root, and stops at the first failure with its exit code. Whatever the
4
+ # build started is killed when it ends, and root owns the application root again.
5
+ set -eu
6
+
7
+ STATE=/var/lib/fabrika
8
+ STEPS=$STATE/build
9
+ BUILD_USER=fabrika-build
10
+ COUNT=$1
11
+
12
+ finish() {
13
+ code=$?
14
+ su-exec "$BUILD_USER" kill -KILL -1 2>/dev/null || true
15
+ chown -R root:root /app 2>/dev/null || true
16
+ rm -f "$STATE/build.pid"
17
+ exit "$code"
18
+ }
19
+ trap finish EXIT
20
+ echo $$ >"$STATE/build.pid"
21
+ chown -R "$BUILD_USER:$BUILD_USER" /app
22
+
23
+ step=1
24
+ while [ "$step" -le "$COUNT" ]; do
25
+ echo "fabrika-build: step $step/$COUNT"
26
+ code=0
27
+ (cd /app && exec env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/home/$BUILD_USER \
28
+ su-exec "$BUILD_USER" /bin/sh -e "$STEPS/$step.sh") || code=$?
29
+ if [ "$code" -ne 0 ]; then
30
+ echo "fabrika-build: step $step/$COUNT failed with exit code $code"
31
+ exit "$code"
32
+ fi
33
+ step=$((step + 1))
34
+ done
35
+ echo 'fabrika-build: done'
@@ -0,0 +1,18 @@
1
+ #!/bin/sh
2
+ # The launcher process itself: the environment reaches it only through the env file the deploy wrote 0600, never through
3
+ # an argument or the sandbox's launch environment, which the sandbox host echoes. The database URL gets the local
4
+ # superuser's password here, which never leaves the sandbox.
5
+ set -eu
6
+
7
+ STATE=/var/lib/fabrika
8
+
9
+ set -a
10
+ . "$STATE/env"
11
+ set +a
12
+ if [ -n "${FABRIKA_APP_DATABASE_URL:-}" ]; then
13
+ FABRIKA_APP_DATABASE_URL="postgres://postgres:$(cat "$STATE/postgres-password")@127.0.0.1:5432/postgres"
14
+ export FABRIKA_APP_DATABASE_URL
15
+ fi
16
+ cd /app
17
+ echo $$ >"$STATE/launcher.pid"
18
+ exec bun -e 'await import("@fabrika/app/dev").then((dev) => dev.runDevLauncher(process.env))'
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ # Starts the dev launcher detached in its own session and returns. Its output goes to a file only root reads: the
3
+ # launcher reports its log to Control itself.
4
+ set -eu
5
+
6
+ BIN=$(dirname "$0")
7
+ STATE=/var/lib/fabrika
8
+
9
+ if [ ! -f "$STATE/env" ] || [ ! -f /app/fabrika/dev.generated.json ]; then
10
+ echo 'fabrika sandbox: no deploy left a launcher configuration and environment'
11
+ exit 1
12
+ fi
13
+ pid=$(cat "$STATE/launcher.pid" 2>/dev/null || true)
14
+ case "$pid" in
15
+ '' | *[!0-9]*) ;;
16
+ *)
17
+ if kill -0 "$pid" 2>/dev/null; then
18
+ echo "fabrika sandbox: a launcher is already running (pid $pid)"
19
+ exit 1
20
+ fi
21
+ ;;
22
+ esac
23
+ rm -f /app/fabrika/dev-booted
24
+ umask 077
25
+ setsid /bin/sh "$BIN/run-launcher.sh" </dev/null >"$STATE/launcher.log" 2>&1 &
@@ -0,0 +1,47 @@
1
+ #!/bin/sh
2
+ # Stops the process `/var/lib/fabrika/<name>.pid` names and every process below it: TERM to it, then KILL to what is
3
+ # left after a grace period. A missing pidfile or a process already gone is stopped. `build` also kills every process of
4
+ # the build user, so no daemon a build started outlives it.
5
+ set -u
6
+
7
+ case "${1:-}" in
8
+ launcher | build) ;;
9
+ *)
10
+ echo 'usage: stop.sh launcher|build'
11
+ exit 2
12
+ ;;
13
+ esac
14
+ PIDFILE=/var/lib/fabrika/$1.pid
15
+ GRACE_SECONDS=10
16
+
17
+ tree() {
18
+ for child in $(pgrep -P "$1"); do
19
+ tree "$child"
20
+ done
21
+ echo "$1"
22
+ }
23
+
24
+ pid=$(cat "$PIDFILE" 2>/dev/null || true)
25
+ case "$pid" in
26
+ '' | *[!0-9]*) ;;
27
+ *)
28
+ if kill -0 "$pid" 2>/dev/null; then
29
+ before=$(tree "$pid")
30
+ kill -TERM "$pid" 2>/dev/null
31
+ waited=0
32
+ while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt "$GRACE_SECONDS" ]; do
33
+ sleep 1
34
+ waited=$((waited + 1))
35
+ done
36
+ after=''
37
+ if kill -0 "$pid" 2>/dev/null; then after=$(tree "$pid"); fi
38
+ kill -KILL $before $after 2>/dev/null
39
+ fi
40
+ ;;
41
+ esac
42
+ rm -f "$PIDFILE"
43
+ if [ "$1" = build ]; then
44
+ # The kernel signals every process of the build user at once; a fork cannot slip past it.
45
+ su-exec fabrika-build kill -KILL -1 2>/dev/null
46
+ fi
47
+ exit 0
@@ -0,0 +1,61 @@
1
+ #!/bin/sh
2
+ # PID 1 of a dev workspace sandbox. Starts PostgreSQL on 127.0.0.1, then the dev launcher when a deploy left its
3
+ # configuration and environment, so a cold boot serves again without Control. Without them the sandbox idles. The
4
+ # scripts it starts are the ones the last deploy uploaded (`bin/current` names their version).
5
+ set -u
6
+
7
+ STATE=/var/lib/fabrika
8
+ PGDATA=$STATE/postgres
9
+
10
+ uploaded() {
11
+ version=$(cat "$STATE/bin/current" 2>/dev/null || true)
12
+ case "$version" in
13
+ '' | *[!0-9a-f]*) return 1 ;;
14
+ esac
15
+ [ -f "$STATE/bin/$version/$1" ] && echo "$STATE/bin/$version/$1"
16
+ }
17
+
18
+ shutdown() {
19
+ if stop=$(uploaded stop.sh); then /bin/sh "$stop" launcher; fi
20
+ su-exec postgres pg_ctl -D "$PGDATA" -m fast stop >/dev/null 2>&1
21
+ exit 0
22
+ }
23
+ trap shutdown TERM INT
24
+
25
+ mkdir -p "$STATE" /run/postgresql
26
+ # Traversable only: PostgreSQL reaches its own directory below it; every file holding a credential is 0600.
27
+ chmod 711 "$STATE"
28
+ chown postgres:postgres /run/postgresql
29
+ # Only root and PostgreSQL reach the socket, which trusts every local connection.
30
+ chmod 700 /run/postgresql
31
+ # Pidfiles name processes of an earlier boot; their pids may belong to anything now.
32
+ rm -f "$STATE"/*.pid
33
+
34
+ if [ ! -s "$PGDATA/PG_VERSION" ]; then
35
+ rm -rf "$PGDATA"
36
+ mkdir -p "$PGDATA"
37
+ chown postgres:postgres "$PGDATA"
38
+ chmod 700 "$PGDATA"
39
+ # TCP needs the superuser's password, which the first deploy sets (`bin/postgres-auth.sh`).
40
+ if su-exec postgres initdb -D "$PGDATA" -U postgres --auth-local=trust --auth-host=scram-sha-256 --encoding=UTF8 >"$STATE/initdb.log" 2>&1; then
41
+ printf '%s\n' 'local all all trust' 'host all all 127.0.0.1/32 scram-sha-256' >"$PGDATA/pg_hba.conf"
42
+ printf '%s\n' "listen_addresses = '127.0.0.1'" >>"$PGDATA/postgresql.conf"
43
+ else
44
+ echo "fabrika sandbox: initdb failed; see $STATE/initdb.log"
45
+ fi
46
+ fi
47
+
48
+ # PID 1 runs no PostgreSQL yet, so a lock file left by a stopped sandbox is stale.
49
+ rm -f "$PGDATA/postmaster.pid"
50
+ if ! su-exec postgres pg_ctl -D "$PGDATA" -w -t 60 -l "$PGDATA/server.log" start >/dev/null; then
51
+ echo "fabrika sandbox: PostgreSQL did not start; see $PGDATA/server.log"
52
+ fi
53
+
54
+ if [ -f "$STATE/env" ] && [ -f /app/fabrika/dev.generated.json ] && start=$(uploaded start-launcher.sh); then
55
+ /bin/sh "$start"
56
+ fi
57
+
58
+ while :; do
59
+ sleep 3600 &
60
+ wait $!
61
+ done
package/src/api/client.ts CHANGED
@@ -5,6 +5,7 @@ import { waitForProcess } from './polling'
5
5
  import {
6
6
  appVersionListSchema,
7
7
  appVersionSchema,
8
+ backupConfigSchema,
8
9
  importResultSchema,
9
10
  integrationTokenSchema,
10
11
  logAccessSchema,
@@ -370,6 +371,17 @@ export const createZeropsApi = (options: ZeropsApiOptions): ZeropsApi => {
370
371
  return readResponse('configure custom autoscaling', processNilSchema, payload).process ?? null
371
372
  },
372
373
 
374
+ getBackupConfig: async ({ serviceId, signal }) =>
375
+ readResponse('list backups', backupConfigSchema, await request('list backups', 'GET', `/service-stack/${serviceId}/backup`, { signal })),
376
+
377
+ configureBackup: async ({ serviceId, backupPeriod, retentionPolicy, signal }) => {
378
+ const payload = await request('configure backup', 'PUT', `/service-stack/${serviceId}/backup-config`, {
379
+ body: { backupPeriod, retentionPolicy },
380
+ signal,
381
+ })
382
+ return readResponse('configure backup', processNilSchema, payload).process ?? null
383
+ },
384
+
373
385
  getService: async ({ serviceId, signal }) =>
374
386
  readResponse('get service', serviceSchema, await request('get service', 'GET', `/service-stack/${serviceId}`, { signal })),
375
387
 
@@ -441,7 +453,9 @@ export const createZeropsApi = (options: ZeropsApiOptions): ZeropsApi => {
441
453
  await awaitUserDataSync(created, label, signal)
442
454
  return
443
455
  } catch (error) {
444
- if (!(error instanceof ZeropsApiError) || error.code !== USER_DATA_DUPLICATE_KEY) {
456
+ // A key the platform generated itself (a managed service's own variable) answers an `errorList` that holds the
457
+ // duplicate beside `userDataUseOfSystemKey`; updating its record is allowed (measured on `zbox@1`).
458
+ if (!(error instanceof ZeropsApiError) || (error.code !== USER_DATA_DUPLICATE_KEY && !error.listedCodes.includes(USER_DATA_DUPLICATE_KEY))) {
445
459
  throw error
446
460
  }
447
461
  }
package/src/api/errors.ts CHANGED
@@ -21,8 +21,11 @@ export const isAppVersionNotFoundResponse = (value: unknown): boolean => {
21
21
  * branch on `userDataDuplicateKey` rather than matching a prose message.
22
22
  */
23
23
  export class ZeropsApiError extends Error {
24
- constructor(message: string, readonly status: number, readonly code: string) {
24
+ /** The codes of an `errorList` answer's entries: the platform reports several refusals of one request there. */
25
+ readonly listedCodes: readonly string[]
26
+ constructor(message: string, readonly status: number, readonly code: string, listedCodes: readonly string[] = []) {
25
27
  super(message)
28
+ this.listedCodes = listedCodes
26
29
  this.name = 'ZeropsApiError'
27
30
  }
28
31
  }
@@ -45,6 +48,7 @@ export const apiError = (label: string, status: number, body: unknown, redactDet
45
48
  const { error: inner, ...outer } = errorEnvelopeSchema.parse(body)
46
49
  const code = inner.code ?? outer.code ?? ''
47
50
  const message = redactDetail ? '' : (inner.message ?? outer.message ?? '')
48
- const detail = [code, message].filter((part) => part !== '').join(': ')
49
- return new ZeropsApiError(`zerops: ${label} failed (${status})${detail === '' ? '' : ` — ${detail.slice(0, 300)}`}`, status, code)
51
+ const listed = [...inner.meta, ...outer.meta].flatMap((entry) => entry.code === undefined ? [] : [entry.code])
52
+ const detail = [code, ...listed, message].filter((part) => part !== '').join(': ')
53
+ return new ZeropsApiError(`zerops: ${label} failed (${status})${detail === '' ? '' : ` — ${detail.slice(0, 300)}`}`, status, code, listed)
50
54
  }
@@ -3,6 +3,8 @@ import { withoutSensitiveContent } from './service-env-response'
3
3
  import type {
4
4
  ZeropsAppVersion,
5
5
  ZeropsAppVersionStatus,
6
+ ZeropsBackupConfig,
7
+ ZeropsBackupRetentionPolicy,
6
8
  ZeropsImportResult,
7
9
  ZeropsIntegrationToken,
8
10
  ZeropsLogAccess,
@@ -170,6 +172,33 @@ export const serviceSchema = z.object({
170
172
  currentAutoscaling: optional(serviceAutoscalingSchema),
171
173
  }).transform(({ activeAppVersion, ...service }): ZeropsService => ({ ...service, activeAppVersionId: activeAppVersion?.id }))
172
174
 
175
+ const backupCountSchema = z.number().int().nonnegative()
176
+
177
+ /** Strict like the custom autoscaling, for the same reason: it is sent back whole, so no field may read as absent. */
178
+ const backupRetentionPolicySchema = z.object({
179
+ maxTotalFiles: backupCountSchema,
180
+ maxTotalGiB: backupCountSchema,
181
+ // A Go API may serialise an empty list as null; read as the empty list it is.
182
+ protectedTags: z.array(z.string()).nullable().transform((tags) => tags ?? []),
183
+ minDaily: backupCountSchema,
184
+ maxDaily: backupCountSchema,
185
+ minWeekly: backupCountSchema,
186
+ maxWeekly: backupCountSchema,
187
+ minMonthly: backupCountSchema,
188
+ maxMonthly: backupCountSchema,
189
+ }) satisfies z.ZodType<ZeropsBackupRetentionPolicy, z.ZodTypeDef, unknown>
190
+
191
+ /** A service's own retention that does not parse fails the whole read: reading it as absent would send the default over it. */
192
+ export const backupConfigSchema = z.object({
193
+ backupPeriod: z.string(),
194
+ defaultRetentionPolicy: backupRetentionPolicySchema,
195
+ retentionPolicy: backupRetentionPolicySchema.nullish(),
196
+ }).transform(({ backupPeriod, defaultRetentionPolicy, retentionPolicy }): ZeropsBackupConfig => ({
197
+ backupPeriod,
198
+ defaultRetentionPolicy,
199
+ ...(retentionPolicy === null || retentionPolicy === undefined ? {} : { retentionPolicy }),
200
+ }))
201
+
173
202
  export const projectSchema = z.object({
174
203
  id: idSchema,
175
204
  name: z.string(),
package/src/api/types.ts CHANGED
@@ -196,6 +196,34 @@ export interface ZeropsServiceAutoscaling {
196
196
  }
197
197
  }
198
198
 
199
+ /**
200
+ * How many backups of a managed service the platform keeps. VERIFIED AS A SHAPE: `OutDtoBackupRetentionPolicy` and
201
+ * `InDtoBodyBackupRetentionPolicy` carry these nine fields, all required. The `min*`/`max*` counts are per backup TAG
202
+ * (`daily`, `weekly`, `monthly`); UNVERIFIED: which tags an hourly automatic backup gets.
203
+ */
204
+ export interface ZeropsBackupRetentionPolicy {
205
+ maxTotalFiles: number
206
+ maxTotalGiB: number
207
+ /** Backups with one of these tags are never deleted automatically. */
208
+ protectedTags: string[]
209
+ minDaily: number
210
+ maxDaily: number
211
+ minWeekly: number
212
+ maxWeekly: number
213
+ minMonthly: number
214
+ maxMonthly: number
215
+ }
216
+
217
+ /** A managed service's backup schedule and retention. VERIFIED AS A SHAPE: `ResponseServiceStackBackupFileList`, without its `files`. */
218
+ export interface ZeropsBackupConfig {
219
+ /** UNVERIFIED: the format. Zerops' GUI documentation describes a 5-field cron (`min hour dom mon dow`). */
220
+ backupPeriod: string
221
+ /** What the platform applies to a service with no retention of its own. UNVERIFIED: that it is what applies then. */
222
+ defaultRetentionPolicy: ZeropsBackupRetentionPolicy
223
+ /** The service's own retention; absent when none was set. */
224
+ retentionPolicy?: ZeropsBackupRetentionPolicy
225
+ }
226
+
199
227
  /** One service. VERIFIED: `ResponseServiceStack` (narrowed to the fields fabrika reads). */
200
228
  export interface ZeropsService {
201
229
  id: string
@@ -506,6 +534,30 @@ export interface ZeropsApi {
506
534
  */
507
535
  configureCustomAutoscaling(input: { serviceId: string; autoscaling: ZeropsServiceAutoscaling; signal: AbortSignal }): Promise<ZeropsProcess | null>
508
536
 
537
+ // ── service-stack: backups ────────────────────────────────────────────────────
538
+
539
+ /**
540
+ * A managed service's backup schedule and retention. VERIFIED AS A SHAPE: `GET /service-stack/{id}/backup`
541
+ * (`ListBackups`), response `ResponseServiceStackBackupFileList`; the backup files it also lists are not read.
542
+ */
543
+ getBackupConfig(input: { serviceId: string; signal: AbortSignal }): Promise<ZeropsBackupConfig>
544
+
545
+ /**
546
+ * Set a managed service's backup schedule and retention. VERIFIED AS A SHAPE: `PUT /service-stack/{id}/backup-config`
547
+ * (`ConfigureBackup`), body `RequestServiceStackBackupConfig`, response `ResponseProcessNil`. The platform stores the
548
+ * period as the service's `BACKUP_PERIOD` variable and may start a user-data sync, whose process this answers.
549
+ *
550
+ * `retentionPolicy` is required here although the body makes it optional. UNVERIFIED: whether a request without one
551
+ * resets the service's retention; a PUT elsewhere on this API resets every field it leaves out, so the caller sends
552
+ * the retention it read, whole.
553
+ */
554
+ configureBackup(input: {
555
+ serviceId: string
556
+ backupPeriod: string
557
+ retentionPolicy: ZeropsBackupRetentionPolicy
558
+ signal: AbortSignal
559
+ }): Promise<ZeropsProcess | null>
560
+
509
561
  // ── service-stack / project: reading state ────────────────────────────────────
510
562
 
511
563
  /** One service by id. VERIFIED: `GET /service-stack/{id}`. */
package/src/api.ts CHANGED
@@ -19,6 +19,8 @@ export {
19
19
  type ZeropsAppVersion,
20
20
  type ZeropsAppVersionStatus,
21
21
  type ZeropsAppVersionUpload,
22
+ type ZeropsBackupConfig,
23
+ type ZeropsBackupRetentionPolicy,
22
24
  type ZeropsImportedService,
23
25
  type ZeropsImportResult,
24
26
  type ZeropsIntegrationToken,
package/src/cli.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env bun
2
+ import type { AppCli } from '@fabrika/provider-contract/app-cli'
2
3
  import { constants } from 'node:fs'
3
4
  import { open } from 'node:fs/promises'
4
5
  import { resolve } from 'node:path'
@@ -12,6 +13,7 @@ import {
12
13
  manifestServiceHostnames,
13
14
  ZEROPS_SOURCE_DESCRIPTOR_MAX_BYTES,
14
15
  } from './manifest'
16
+ import { zeropsNamespaceCli } from './namespace-cli'
15
17
  import type { ZeropsAppConfig } from './types'
16
18
 
17
19
  const USAGE = `Zerops app tools
@@ -106,6 +108,15 @@ export const runZeropsCli = async (argv: readonly string[]): Promise<void> => {
106
108
  console.info(`wrote ${output} (${manifestServiceHostnames(manifest).length} service(s))`)
107
109
  }
108
110
 
111
+ /** What `fabrika app build`, `app register` and `fabrika namespace` run for an application on Zerops. */
112
+ export const appCli: AppCli = {
113
+ provider: 'zerops',
114
+ entryRuntime: 'bun',
115
+ build: (argv) => runZeropsCli(['build', ...argv]),
116
+ registrationManifest: buildZeropsManifestText,
117
+ namespaces: zeropsNamespaceCli,
118
+ }
119
+
109
120
  if (import.meta.main) {
110
121
  await runZeropsCli(process.argv.slice(2)).catch((error: unknown) => {
111
122
  console.error(error instanceof Error ? error.message : String(error))
@@ -1,5 +1,3 @@
1
- import { reconcileSchema } from '@fabrika/auth'
2
- import type { SchemaReconciler } from '@fabrika/provider-contract'
3
1
  import { createZeropsApi, type ZeropsApi } from './api'
4
2
  import { type ExposureAlerter, sendExposureAlert } from './exposure'
5
3
  import type { ZeropsSourcePort } from './source/port'
@@ -28,7 +26,6 @@ export interface ZeropsCollaborators {
28
26
  api: ZeropsApi
29
27
  /** Injected by the Zerops control composition; dry runs do not require it. */
30
28
  source?: ZeropsSourcePort
31
- reconcileSchema: SchemaReconciler
32
29
  /** Raises the Operations alert for a refused activation; best-effort. */
33
30
  alertExposure: ExposureAlerter
34
31
  sleep: Sleeper
@@ -36,19 +33,8 @@ export interface ZeropsCollaborators {
36
33
 
37
34
  export type ZeropsCollaboratorFactory = (target: ZeropsRuntimeTarget) => ZeropsCollaborators
38
35
 
39
- const defaultReconcileSchema: SchemaReconciler = (input) =>
40
- reconcileSchema({
41
- url: input.url,
42
- app: input.app,
43
- schema: input.schema,
44
- ...(input.returnOrigins === undefined ? {} : { returnOrigins: input.returnOrigins }),
45
- adminKey: input.adminKey,
46
- signal: input.signal,
47
- })
48
-
49
36
  export const defaultZeropsCollaborators: ZeropsCollaboratorFactory = (target) => ({
50
37
  api: createZeropsApi({ token: target.accessToken, baseUrl: target.apiBaseUrl }),
51
- reconcileSchema: defaultReconcileSchema,
52
38
  alertExposure: sendExposureAlert,
53
39
  sleep: defaultSleep,
54
40
  })
package/src/compile.ts CHANGED
@@ -23,7 +23,7 @@ import type { ZeropsImportProject, ZeropsImportService } from './schema.generate
23
23
  import type { ZeropsProjectSpec, ZeropsResourceContext, ZeropsServiceSpec, ZeropsSourceTarget } from './types'
24
24
 
25
25
  /** The ONLY value fabrika ever writes for `envIsolation`, at either level. Not a default — an assertion. */
26
- export const ENV_ISOLATION: 'service' = 'service'
26
+ export const ENV_ISOLATION = 'service'
27
27
 
28
28
  /**
29
29
  * The ONLY value fabrika ever writes for `override`, on EVERY service class including managed ones.