gowalk-cicd 1.0.219 → 1.0.221

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/README.md CHANGED
@@ -318,6 +318,8 @@ Requirements on the consumer repo:
318
318
  `backend-preview` deploy ends with a `backend_origin_unbound` notice.
319
319
  - Repo **variable** `BACKEND_DEPLOY_HOST`: the bound SSH destination (DNS name or IPv4 address),
320
320
  required for a bound backend; no panel host or historical address is used as a fallback.
321
+ - Repo **variable** `BACKEND_DIAGNOSTIC_HOST` (optional): local IPv4 address or DNS name expected by network diagnostics.
322
+ For a VM behind NAT, use its private address; SSH still uses `BACKEND_DEPLOY_HOST` and its pinned key.
321
323
  - Repo **variable** `BACKEND_DEPLOY_SSH_PORT` (optional, default `22`): the SSH port, from 1 to 65535.
322
324
  Non-default ports require `[host]:port` in the trusted host key, for example
323
325
  `[backend.example.com]:22101 ssh-ed25519 AAAA...`. Deployment and diagnostics share this port.
@@ -1437,6 +1439,10 @@ Identity failure logs and source Compose files do not establish this applied sta
1437
1439
 
1438
1440
  ### Read-only bridge and VPN prerequisite diagnostics
1439
1441
 
1442
+ The optional `diagnostic-host` input (repo variable `BACKEND_DIAGNOSTIC_HOST`) selects the local binding
1443
+ checked by network diagnostics. Empty uses the SSH host. It accepts IPv4 or DNS names, not IPv6 literals.
1444
+ This local observation does not prove public NAT or ingress reachability; verify the public endpoint separately.
1445
+
1440
1446
  Backend Deploy also offers `operation: network-diagnostics`, with an exact `diagnostic-service`, deployed
1441
1447
  `diagnostic-build-sha`, owned `diagnostic-network`, proposed namespace-only private IPv4 `/24` or IPv6 ULA `/64` in
1442
1448
  `diagnostic-pool`, exact `diagnostic-vpn-service`, and optional `diagnostic-provider: digitalocean`.
@@ -22,6 +22,10 @@ inputs:
22
22
  description: Fixed metadata corroboration for network-diagnostics (none or digitalocean); allocates nothing.
23
23
  required: false
24
24
  default: none
25
+ diagnostic-host:
26
+ description: Expected local IPv4 address or DNS name for network checks; empty uses the SSH host.
27
+ required: false
28
+ default: ""
25
29
  diagnostic-network:
26
30
  description: Exact owned Compose bridge network key for network-diagnostics.
27
31
  required: false
@@ -347,6 +351,7 @@ runs:
347
351
  DIAGNOSTIC_USER: ${{ inputs.ssh-user }}
348
352
  DIAGNOSTIC_PORT: ${{ inputs.ssh-port }}
349
353
  DIAGNOSTIC_BUILD: ${{ inputs.expected-build-sha }}
354
+ DIAGNOSTIC_BOUND_HOST: ${{ inputs.diagnostic-host }}
350
355
  DIAGNOSTIC_NETWORK: ${{ inputs.diagnostic-network }}
351
356
  DIAGNOSTIC_POOL: ${{ inputs.diagnostic-pool }}
352
357
  DIAGNOSTIC_VPN_SERVICE: ${{ inputs.diagnostic-vpn-service }}
@@ -359,6 +364,7 @@ runs:
359
364
  --app "$DIAGNOSTIC_APP" --service "$DIAGNOSTIC_SERVICE" --expected-build-sha "$DIAGNOSTIC_BUILD" \
360
365
  --network "$DIAGNOSTIC_NETWORK" --pool "$DIAGNOSTIC_POOL" --vpn-service "$DIAGNOSTIC_VPN_SERVICE" \
361
366
  --host "$DIAGNOSTIC_HOST" --user "$DIAGNOSTIC_USER" --port "$DIAGNOSTIC_PORT" \
367
+ --diagnostic-host "$DIAGNOSTIC_BOUND_HOST" \
362
368
  --provider "$DIAGNOSTIC_PROVIDER" --output "$RESULT_DIR/result.json" \
363
369
  --transport-output "$RESULT_DIR/transport.json"
364
370
 
@@ -22,7 +22,7 @@ REQUIRED = (
22
22
  'identity_diagnostics.py',
23
23
  'health_rollout.py', 'health_rollout_engine.py', 'health_rollout_spec.py', 'health_rollout_credit.py',
24
24
  'health_rollout_timing.py',
25
- 'memory_agent.py',
25
+ 'memory_agent.py', 'memory_accounting.py',
26
26
  'runtime_env.py', 'runtime_env_parse.py', 'edge_inputs.py', 'edge_vhost.py', 'edge_health.py',
27
27
  'configure_vhost.py', 'vhost_diagnostics.py', 'remote_deploy.sh', 'deploy_evidence.sh',
28
28
  'ensure_certificate.sh', 'select_certbot_account.sh',
@@ -0,0 +1,19 @@
1
+ """Conservative resident accounting from cgroup v2 type counters, independent of LRU position."""
2
+
3
+
4
+ def working_set(current, stats):
5
+ """Retain pinned/dirty/shared memory and half of potentially reclaimable kernel slab."""
6
+ names = ("anon", "file", "shmem", "kernel", "file_dirty", "file_writeback", "unevictable",
7
+ "slab_reclaimable")
8
+ values = {name: int(stats[name]) for name in names}
9
+ if current < 0 or any(value < 0 for value in values.values()):
10
+ raise ValueError("negative_memory_counter")
11
+ if values["slab_reclaimable"] > values["kernel"] or values["shmem"] > values["file"]:
12
+ raise ValueError("inconsistent_memory_counters")
13
+ # Dirty/writeback may overlap and unevictable may be anonymous: subtracting all is conservative.
14
+ clean_file = max(0, values["file"] - values["shmem"] - values["file_dirty"]
15
+ - values["file_writeback"] - values["unevictable"])
16
+ # The reads are not atomic. Never let a stale current/file pair hide resident type counters.
17
+ resident = max(current - clean_file, values["anon"] + values["shmem"] + values["kernel"])
18
+ # Reclaimable means eligible, not immediately free. Keep at least half even before the 20% margin.
19
+ return resident - values["slab_reclaimable"] // 2
@@ -12,6 +12,7 @@ from concurrent.futures import ThreadPoolExecutor
12
12
  from pathlib import Path
13
13
 
14
14
  from native_profile import running_native
15
+ from memory_accounting import working_set as resident_working_set
15
16
  from runtime_host import AGENT_STATE
16
17
  from runtime_model import MIB
17
18
 
@@ -63,11 +64,10 @@ def cgroup_dir(container):
63
64
  raise FileNotFoundError(container["id"]) # the container's process has exited
64
65
 
65
66
 
66
- def measure(directory, store):
67
- """The working set, anon and pressure; a datastore's working set also leaves out its active file cache."""
67
+ def measure(directory):
68
+ """Resident working set, anonymous memory and pressure from the container's own cgroup."""
68
69
  stat = dict(line.split() for line in (directory / "memory.stat").read_text().splitlines())
69
- cache = int(stat["inactive_file"]) + (int(stat["active_file"]) if store else 0)
70
- working_set = int((directory / "memory.current").read_text()) - cache
70
+ working_set = resident_working_set(int((directory / "memory.current").read_text()), stat)
71
71
  pressure = 0.0
72
72
  for line in (directory / "memory.pressure").read_text().splitlines():
73
73
  if line.startswith("some "):
@@ -142,7 +142,7 @@ def handle(container, now, zswap, dry_run):
142
142
  if now - started < SETTLE_SECONDS: # startup imports have not settled yet
143
143
  return dict(entry, settling=True)
144
144
  directory = cgroup_dir(container)
145
- working_set, anon, pressure = measure(directory, store)
145
+ working_set, anon, pressure = measure(directory)
146
146
  except (FileNotFoundError, ProcessLookupError):
147
147
  return dict(entry, exited=True)
148
148
  except (OSError, ValueError, KeyError):
@@ -13,9 +13,10 @@ from runtime_diagnostics import transport_signals
13
13
 
14
14
  def local(args, transport=None):
15
15
  fields = (args.app, args.service, args.expected_build_sha, args.network, args.pool,
16
- args.vpn_service, args.host, args.provider)
16
+ args.vpn_service, getattr(args, 'diagnostic_host', '') or args.host, args.provider)
17
17
  scope(*fields)
18
- if not re.fullmatch(r'[a-z_][a-z0-9_-]{0,31}', args.user):
18
+ if (not re.fullmatch(r'[a-z_][a-z0-9_-]{0,31}', args.user)
19
+ or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9.-]{0,252}', args.host)):
19
20
  raise NetworkFailure('invalid_scope')
20
21
  port = str(getattr(args, 'port', '22'))
21
22
  if not re.fullmatch(r'[1-9][0-9]{0,4}', port) or int(port) > 65535:
@@ -55,9 +56,10 @@ def main():
55
56
  parser.add_argument('--' + name, default=default)
56
57
  parser.add_argument('--transport-output', help='Separate closed SSH observation receipt')
57
58
  parser.add_argument('--port', default='22')
59
+ parser.add_argument('--diagnostic-host', default='', help='Expected local IPv4 address or DNS name')
58
60
  args = parser.parse_args()
59
61
  fields = (args.app, args.service, args.expected_build_sha, args.network, args.pool,
60
- args.vpn_service, args.host, args.provider)
62
+ args.vpn_service, getattr(args, 'diagnostic_host', '') or args.host, args.provider)
61
63
  transport = {'schema': 'gowalk-cicd/backend-network-transport.v1', 'exit_status': None, 'signals': []}
62
64
  try:
63
65
  result = local(args, transport)
@@ -4,18 +4,35 @@ Admission counts reservations (64 MiB when unset), not use, within 70% of RAM. I
4
4
  that default and a third of their memory is cold, so a shared host refused stacks with
5
5
  `host_reservations_exhausted` while RAM was still free. `backend-action/memory_agent.py` runs as root every five
6
6
  minutes on eight threads. For each running container under `/opt/gowalk-backends/` (the scope admission counts)
7
- that started at least ten minutes ago, it first measures the working set (`memory.current - inactive_file`), then:
7
+ that started at least ten minutes ago, it measures a resident working set from cgroup v2 type counters, then:
8
8
 
9
9
  - sets the reservation to the working set plus 20%, rounded up to 4 MiB, at least 16 MiB and at most the
10
10
  container's limit (`docker update --memory-reservation`). App containers rise at once and fall by 8 MiB or more.
11
11
  Datastores (PostgreSQL, PostGIS, TimescaleDB, Redis, Valkey, KeyDB, MySQL, MariaDB, MongoDB or Memcached by
12
- image, service or command, or service `db`/`database`) only rise, and only with memory beyond their file cache;
12
+ image, service or command, or service `db`/`database`) only rise;
13
13
  - only when host `MemAvailable` is below 30% of `MemTotal` (the headroom outside admission's 70% reservation cap),
14
14
  while swap is present, zswap is enabled (`/sys/module/zswap/parameters/enabled` is `Y`) and `memory.pressure`
15
15
  `some avg60` is below 0.5, writes a quarter of an app container's anonymous memory to `memory.reclaim`,
16
16
  compressing cold pages into zswap. Datastores are never reclaimed. With ample host memory, reservation
17
17
  measurement and updates continue without proactive page eviction; reclaim resumes when headroom falls.
18
18
 
19
+ `memory_accounting.py` excludes clean file cache from every container, whether currently active or inactive.
20
+ It retains shared memory (including PostgreSQL shared buffers), dirty/writeback pages, unevictable pages and
21
+ all non-reclaimable kernel allocations. It also retains half of `slab_reclaimable`: eligibility for reclaim
22
+ does not promise immediate availability. Dirty/writeback and unevictable counts may overlap; retaining their
23
+ sum deliberately overestimates this cost. The calculation is
24
+ `max(current - clean_file, anon + shmem + kernel) - floor(slab_reclaimable / 2)`, where
25
+ `clean_file = max(0, file - shmem - file_dirty - file_writeback - unevictable)`.
26
+ The resident type-counter floor guards against skew between non-atomic reads. Missing, negative or inconsistent
27
+ required counters refuse measurement and keep the existing reservation; no low fallback is substituted.
28
+ See the kernel's [memory.stat definitions](https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files).
29
+
30
+ This is a reservation estimate, not a guarantee that cache can immediately be evicted. The 20% margin, 4 MiB
31
+ rounding, 16 MiB floor, 70% host admission cap, available-memory and pressure checks remain unchanged. No cache
32
+ is dropped by this calculation. Existing datastore reservations retain their high-water mark; installing the
33
+ new estimator alone never lowers them. A host migration must separately validate any initial measured
34
+ reservation and preserve the original declaration credits against verified container identities.
35
+
19
36
  Before its first change to a container, the agent records the reservation admission counted (bytes; 64 MiB when
20
37
  unset) in `/var/lib/gowalk-backend-memory/<full container id>` (root-owned, 0644, atomic, fsynced, never
21
38
  overwritten) and never resizes without it; each real run removes only the 64-hex-named records of containers that
@@ -171,6 +171,9 @@ for client compatibility, so prove adoption with the install receipt and the for
171
171
  - `udp_ports` classifies fixed UDP ports `500` and `4500` as `free`, exact `app_vpn`, `foreign` or `unknown`.
172
172
  Reuse requires the exact app/vpn-service/directory binding. A host listener not attributable to Docker's
173
173
  proxy stays unknown. This is a timestamped observation, not a port reservation; actual deployment can race.
174
+ - `diagnostic-host` / `BACKEND_DIAGNOSTIC_HOST` may select the VM private IPv4 address or DNS name behind NAT;
175
+ empty uses the SSH host. SSH transport and its key pin remain bound to the public endpoint.
176
+ This local binding observation does not prove public NAT/ingress reachability.
174
177
  - `host.binding` requires the bound host's IPv4 address(es) to match local host addresses. Optional
175
178
  `diagnostic-provider: digitalocean` corroborates fixed metadata with those live interfaces. Metadata
176
179
  unavailable/unverified states remain explicit; metadata does not establish VPC, firewall or routing authority.
@@ -36,6 +36,7 @@ mobile:
36
36
  backend:
37
37
  host: ${{ vars.BACKEND_DEPLOY_HOST }}
38
38
  ssh-port: ${{ vars.BACKEND_DEPLOY_SSH_PORT || '22' }}
39
+ diagnostic-host: ${{ vars.BACKEND_DIAGNOSTIC_HOST }}
39
40
  runtime-env: ${{ secrets.BACKEND_RUNTIME_ENV }}
40
41
  public-base-url: ${{ vars.BACKEND_PUBLIC_BASE_URL }}
41
42
  public-health-url: ${{ vars.BACKEND_PUBLIC_HEALTH_URL }}
@@ -152,3 +153,9 @@ Set `BACKEND_DEPLOY_SSH_PORT` when multiple deploy VMs share one public address.
152
153
  For a non-default port, `BACKEND_DEPLOY_KNOWN_HOSTS` must pin `[host]:port`,
153
154
  for example `[deploy.example.com]:22101 ssh-ed25519 <public-key>`.
154
155
  Both backend workflow entrypoints and all diagnostic operations use the same port.
156
+
157
+ Backend `diagnostic-host` optionally names the local IPv4 address or DNS host expected by network diagnostics.
158
+ `BACKEND_DIAGNOSTIC_HOST` supplies its default; empty falls back to the SSH `host`.
159
+ It must match `[A-Za-z0-9][A-Za-z0-9.-]{0,252}` (IPv6 literals are unsupported).
160
+ For shared public ingress, use the VM private address here and retain the public address in `host`.
161
+ The reader still verifies local address ownership; public NAT/ingress needs its own acceptance check.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gowalk-cicd",
3
- "version": "1.0.219",
3
+ "version": "1.0.221",
4
4
  "description": "Zero-config GitHub Actions delivery for iOS TestFlight and Android Google Play.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,7 +9,7 @@ const inputs = {
9
9
  ios: ['project', 'workspace', 'scheme', 'configuration', 'bundle-id', 'team-id', 'firebase-app-id',
10
10
  'native-preparation-manifest'],
11
11
  android: ['project-dir', 'module', 'variant', 'firebase-app-id', 'dart-defines'],
12
- backend: ['ssh-key', 'ssh-port', 'host', 'app-name', 'api-domain', 'backend-dir', 'compose-file',
12
+ backend: ['ssh-key', 'ssh-port', 'diagnostic-host', 'host', 'app-name', 'api-domain', 'backend-dir', 'compose-file',
13
13
  'health-path', 'runtime-env',
14
14
  'public-health-url', 'public-base-url', 'expected-build-sha', 'ingress-required', 'ingress-token'],
15
15
  };
@@ -53,11 +53,13 @@ export function applySettings(config, file, workflow, defaults) {
53
53
  }
54
54
  const job = file === 'deploy.yml' ? 'backend-preview' : file === 'deploy-backend.yml' ? 'deploy' : null;
55
55
  if (job) {
56
- const port = config.backend?.['ssh-port'];
57
56
  const action = job === 'deploy' ? 'Deploy backend' : 'Deploy backend from feature branch';
58
- if (port !== undefined) assign(workflow, {
59
- path: ['jobs', job, 'steps', 'items', 'name:' + action, 'with', 'ssh-port'], value: port,
60
- });
57
+ for (const key of ['ssh-port', 'diagnostic-host']) {
58
+ const value = config.backend?.[key];
59
+ if (value !== undefined) assign(workflow, {
60
+ path: ['jobs', job, 'steps', 'items', 'name:' + action, 'with', key], value,
61
+ });
62
+ }
61
63
  for (const [key, output, variable] of [['backend-dir', 'path', 'BACKEND_DIR_INPUT'],
62
64
  ['compose-file', 'compose', 'COMPOSE_FILE_INPUT']]) {
63
65
  const value = config.backend?.[key];
@@ -92,6 +92,7 @@ jobs:
92
92
  known-hosts: ${{ vars.BACKEND_DEPLOY_KNOWN_HOSTS }}
93
93
  host: ${{ vars.BACKEND_DEPLOY_HOST }}
94
94
  ssh-port: ${{ vars.BACKEND_DEPLOY_SSH_PORT || '22' }}
95
+ diagnostic-host: ${{ vars.BACKEND_DIAGNOSTIC_HOST }}
95
96
  app-name: ${{ vars.BACKEND_APP_NAME || github.event.repository.name }}
96
97
  api-domain: ${{ vars.BACKEND_API_DOMAIN }}
97
98
  backend-dir: ${{ steps.dir.outputs.path }}
@@ -853,6 +853,7 @@ jobs:
853
853
  known-hosts: ${{ vars.BACKEND_DEPLOY_KNOWN_HOSTS }}
854
854
  host: ${{ vars.BACKEND_DEPLOY_HOST }}
855
855
  ssh-port: ${{ vars.BACKEND_DEPLOY_SSH_PORT || '22' }}
856
+ diagnostic-host: ${{ vars.BACKEND_DIAGNOSTIC_HOST }}
856
857
  app-name: ${{ vars.BACKEND_APP_NAME || github.event.repository.name }}
857
858
  api-domain: ${{ vars.BACKEND_API_DOMAIN }}
858
859
  backend-dir: ${{ steps.dir.outputs.path }}
Binary file