Skip to content

Add host commands for First Draft hosting - #68

Draft
raghubetina wants to merge 1 commit into
mainfrom
hosting-commands
Draft

raghubetina wants to merge 1 commit into
mainfrom
hosting-commands

Conversation

@raghubetina

Copy link
Copy Markdown
Contributor

Summary

Adds the firstdraft host group for First Draft hosting: one application on one DigitalOcean Droplet, operated by the owner's own agent. Draft: the routes follow the service's hosting sketch, which no released API contract includes yet.

  • host create [--region] [--size]: generates an Ed25519 key with ssh-keygen on the owner's computer, sends First Draft only the public line, stores the private key as SSH_PRIVATE_KEY and generates SECRET_KEY_BASE and POSTGRES_PASSWORD (values through gh secret set's standard input, never printed), waits for the Droplet and its cloud-init over ssh, then sets the APP_HOST and DEPLOY_HOST repository variables. Running it again resumes; it never creates a second host, and refuses a host that trusts a key this computer lacks.
  • host status [--wait]: the host, backups, domain, the newest CI run on the default branch (gh run list/view), and /up. Its next sentence tells apart a Droplet still setting itself up, red checks (naming the failed jobs), a running CI, checks that passed before the repository was connected, a failed deploy job, and a live app.
  • host resize --size --yes and host destroy --confirm <environment>: nothing is sent without the confirmation (confirmation_required, exit 2). Destroy also deletes the GitHub variables, the deploy key secret, and the local key.
  • host domain [connect <hostname> | check | disconnect]: bring-your-own domain records; check sets APP_HOST to the domain once its app record is right.
  • host email [connect]: email state and allowance; connect stores new SMTP credentials with gh.

No host command deploys: a push to the default branch deploys when every check passes. The owner's computer needs gh and the OpenSSH client; no Docker, Ruby, or Kamal.

The group lives in src/commands/host-command.js, src/commands/host.js, and src/host-tools.js. src/cli.js gains one import, one help line, and the dispatch, to keep the overlap with #62 small; expect a rebase after it merges.

New handled errors: host_rejected, host_unavailable, invalid_host_response, confirmation_required, deploy_files_missing, tool_unavailable, github_failed, host_key_missing, ssh_failed, host_failed, host_setup_failed.

Depends on, and what a release would need

  • The service's hosting routes (stream E), under a new API-contract version. Then requires.api_contract in release/compatibility.json and API_CONTRACT_RANGE move to it, a version and CHANGELOG.md entry are chosen, and firstdraft/skills updates its CLI pin and packedFileAllowlist (three new files). This PR bumps nothing.
  • Compiled apps' hosted variant (stream D): a deploy job in ci.yml that is skipped until vars.DEPLOY_HOST is set, and config/deploy.yml reading DEPLOY_HOST and APP_HOST (Kamal renders it through ERB), plus the SMTP_* names.
  • The Skill that calls these commands: a separate draft in firstdraft/skills.

Docs: updated docs/commands.md (intro map rows, What the CLI sends, Operate a First Draft host, Service endpoints) and docs/errors.md (Hosting recovery, Error index rows). README.md unchanged: it is at its 6,144-byte budget. CHANGELOG.md unchanged: no version is set here.

Review: not yet run. New command names, flags, and error values need the cross-review AGENTS.md names; held until the hosting package is assembled, as requested.

Validation

  • npm audit: found 0 vulnerabilities
  • npm run check: passes (400 tests, including 17 in test/host.test.js with a stubbed service and a fake gh/ssh-keygen/ssh; typecheck, lint, format, pack check, packed smoke with two host cases)
  • Not run against a real service, GitHub repository, or Droplet.

First Draft hosting runs one application on one DigitalOcean Droplet,
and the owner's own agent operates it. The service never logs in to
the Droplet and never receives a private key, so the steps that need
the key or the person's GitHub login have to run on the owner's
computer: the CLI generates the SSH key with ssh-keygen, sends only
its public line, and stores the private key and the app's generated
secrets as Actions secrets through gh's standard input.

A push to the default branch deploys only when every check passes,
and a freshly compiled app fails its own specs until its Behavior to
write is written. So no host command deploys, and create and status
end with a next sentence that says what stands between the owner and
a live app: a Droplet still setting itself up, red checks, a failed
deploy job, or checks that passed before the repository was
connected. DEPLOY_HOST is set only after cloud-init reports done, so
the deploy job cannot race the Droplet's first boot.

The routes follow the service's hosting sketch, which no released API
contract includes yet. The group lives in its own modules, so cli.js
gains only an import, a help line, and the dispatch.

This branch has not been deployed

No deployments
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