Skip to content

Add secure GHCR-to-VPS deployment with health checks and rollback - #222

Merged
SlimShadyIAm merged 2 commits into
mainfrom
codex/secure-vps-deployment
Oct 24, 2026
Merged

SlimShadyIAm merged 2 commits into
mainfrom
codex/secure-vps-deployment

Conversation

@SlimShadyIAm

Copy link
Copy Markdown
Member

Adds a deployment path for the bot that builds images in GitHub Actions and deploys an immutable GHCR digest over a restricted SSH connection. PRs build and check the image; main publishes releases. VPS deployment remains disabled until the repository variable VPS_DEPLOY_ENABLED=true and the production environment secrets are configured.

The deploy account has no Docker membership or general-purpose sudo access. Its authorized key is restricted to a root-owned forced command, which validates a digest from this repository's fixed GHCR image and uses a root-owned Compose configuration. The server pulls before replacing the bot, serializes deployments with flock, waits for a Discord readiness heartbeat after startup cache loading, and restores the last successful image if the candidate fails readiness. First-deployment failure stops the candidate and requires the documented legacy-service restart. Successful image references are retained for manual rollback.

The runtime uses Python 3.12, a non-root user, a read-only filesystem, dropped capabilities, no-new-privileges, bounded logs, and a writable tmpfs. Secrets/configuration are excluded from images and supplied on the VPS. The legacy local Compose service now loads .env and mounts config.json at runtime to accommodate those exclusions. Host networking is retained for existing localhost MongoDB setups.

See deploy/README.md for VPS installation, the forced SSH key, sudoers rule, verified host keys, optional read-only GHCR authentication, GitHub production environment settings, first-deployment migration, and rollback/operational limitations. Deployment requires manual VPS preparation; this PR does not contact or change the VPS.

Validation:

  • Production Docker image built successfully; dependency imports and secret exclusions verified under non-root/read-only/dropped-capability runtime settings.
  • Python compilation, Bash syntax, ShellCheck, actionlint, YAML checks, Linux Compose configuration validation, and git diff --check passed.
  • Isolated fake-Docker checks exercised successful deployment, previous-image state, rollback, first-release failure, failed pull, rejected command input, invalid saved state, and lock contention.
  • Readiness checks covered missing/corrupt/stale heartbeat, ready/disconnected state, and cancellation cleanup.

Live GHCR publication and SSH deployment require the production credentials and have not been exercised.

@SlimShadyIAm
SlimShadyIAm force-pushed the codex/secure-vps-deployment branch from 4534692 to b630943 Compare October 24, 2026 21:34
@SlimShadyIAm
SlimShadyIAm merged commit 0934862 into main Oct 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant