Palbase Machines · API
/machinesOpen a machine
Opens a machine, built from a branch of a repository one of the project's installations of Palbase Cloud reaches: the branch's head is built at once, and every push to it after that changes what the machine is built from (its source's context, else its path). With deploy_after_checks a push is built once its commit's checks have passed. The answer's state is building; the machine answers at its url once its first build is up. A project has 5 machines at most; a name is one machine's. Emits machine.created. A machine may be given one of the project's databases (database): it is started with where the database answers, a database that is not the project's is refused (400 database_not_found), and so are its migrations while another machine runs them (409 database_migrated_elsewhere).
Called by your server, with the project's secret key.
Request body
namestring · optionalThe machine's name; `backend`, the project's backend, when left out. Not `github`.portinteger · optionalThe TCP port the machine listens on; requests to its address are sent there. The machine also finds it in PORT. A change of it rolls out as any change does: while both versions serve, each is sent requests at its own port.sizestring · requiredThe machine's size. shared-256 has a fraction of a CPU as its ceiling and is put to sleep when it is idle; a standard size never sleeps — its CPUs are its ceiling, a quarter of them reserved for it, the rest its node's when the other machines there leave them; a dedicated size has whole CPUs of its own and never sleeps. shared-256: 0.2 vCPU, 256 MiB (free); starter: 0.5 vCPU, 512 MiB; standard-1x: 1 vCPU, 2048 MiB; standard-2x: 2 vCPU, 4096 MiB; standard-4x: 4 vCPU, 8192 MiB; standard-8x: 8 vCPU, 16384 MiB; highmem-4x: 4 vCPU, 16384 MiB; highmem-8x: 8 vCPU, 32768 MiB; dedicated-1x: 1 vCPU of its own, 2048 MiB; dedicated-2x: 2 vCPU of its own, 4096 MiB. GET /machines/sizes lists each with its price.envobject · optionalWhat the machine is started with in its environment, besides what the platform sets: PORT (where it listens), PALBASE_URL (its project's address, https://<ref>.<domain>), PALBASE_PROJECT_ID, PALBASE_REPLICAS (how many copies of it run) and, given a database, PALBASE_DB_URL and PALBASE_DB_CONNECTIONS (its sessions' address, and a copy's share of them) and PALBASE_DB_POOLED_URL and PALBASE_DB_POOLED_CONNECTIONS (its transactions' address — the pooled port, a connection held while a transaction runs — and how many a copy keeps open: 12, fewer once the port's clients are all held — what a machine of many copies serves through). PORT is refused here; the others, given here or among the machine's secrets, give way to the platform's. Names are environment variable names; 100 variables and 64 KiB at most. Keep secrets in the project's secrets and start the machine with them (`secrets`).secrets"" | "production" | "development" · optionalThe project's secret environment the machine is started with: each of its secrets is in the machine's environment by name. A name in `env` wins over the same secret. When a secret of it changes, the machine rolls out with the new value beside the version that serves. Empty: none.sourceobject · requiredWhere a machine is built from: a branch of a GitHub repository one of the project's installations of Palbase Cloud reaches (GET /machines/github/repositories), and a directory of it. A push to the branch is built — using the directory's Dockerfile, or automatic runtime detection (Node, Bun, Go, Python, …) when no Dockerfile is present — and rolled out when it changes a file in what the build is given: its context (`context`, else `path`), matched by whole directory names, case-sensitively; a push that changes nothing there leaves the machine as it runs, and does not count against the project's builds for the day. A machine built from the repository's root is built by every push. When what GitHub names of a push may not be all it changed — a forced push, a branch's first push, a push of 2048 commits or more, a commit naming no files (an empty commit among them) or 3000 or more — every machine built from the branch is built.health_pathstring · optionalWhere the machine says it is well, as asked of it: a path from the root on its port (200 characters at most, no query) that answers 2xx while it serves. While it starts it has 90 s to answer there; once it serves, one that stops answering there for about 6 s is started again. Empty, its build says: a Palbase backend's (palbase/backend) is /_palbase/health; a machine that says nowhere is asked only whether it listens on its port.replicasinteger · optionalHow many copies of the machine run while it is awake, up to 100 (one on Free), spread for high availability: a request is routed to one of them, losing a single copy leaves the others serving, and a new version rolls out progressively beside the copies that serve. Every copy is of the machine's size and counts as such against the project's limits and its machine time (a minute in which the number changed is counted at the most it was). What a copy keeps in its own memory or on its own disk the others do not see — a session, a counter, a cache, a timer: a machine with more than one keeps those where every copy reaches them. The machine finds the number in PALBASE_REPLICAS. A long-lived connection (a WebSocket) stays with the copy that took it. With autoscaling, the fewest copies it runs. One when left out.always_onboolean · optionalKeeps it awake (Machine.always_on): open to a project on Pay as you go, refused `always_on_not_available` otherwise.previewsboolean · optionalWhether a pull request opened against its branch is previewed: its head built into a machine of its own, <name>-pr<n>, in this environment, with this environment's settings and secrets, answering at <name>-pr<n>-<ref> until the pull request closes; the pull request is told where in a comment. Any environment previews, production's too: the pull request's code runs with the environment's settings, secrets and users, with a database of its own when the machine runs its database's migrations. A machine read with a platform's tokens (source.access token) previews what its platform puts (PUT /machines/{name}/previews/{pull_request}), no comment written.preview_forksboolean · optionalWhether a pull request from a fork — another repository, which anyone may open — is previewed too. Off by default: its code would run with the environment's secrets.databaseobject · optionalThe database a machine is given: the machine is started with where it answers (PALBASE_DB_URL), by the application's login, and with how many connections to it a copy may hold (PALBASE_DB_CONNECTIONS) — a share of what the database's size allows, the copies of every machine given it counted twice (a new version comes up beside the one that serves) and a migration run's share apart. Copies those would not serve are refused (409 `database_connections_short`); the other machines given it roll out to their new share. A change gives it whole: `migrations` left out is false.deploy_after_checksboolean · optionalA push is built only once its commit's checks on GitHub have passed: those `deploy_checks` names, or else every check run reported on the commit for the machine's branch (GitHub Actions' jobs, and any other app's checks; Palbase's own left out) has ended in success, neutral or skipped, and every GitHub Actions workflow run of it has ended — taken as ended 30 s after the last ended, and no sooner than 30 s after the push's build was made. Until then the build waits (`waiting_checks`, its `reason` naming what it waits for), and the machine runs what it ran; a newer push waits beside it, for its own. The machine moves to the newest commit whose checks passed, never back: the first to pass is built and leaves the older builds behind, waiting or under way, so an older commit whose checks pass after it is not built. A check that ended otherwise (failure, cancelled, timed_out, action_required, stale), no check reported in 10 minutes, or checks not ended in 3 hours (6 hours for named ones), and the build is `skipped` (`reason`); a check run again that passes later does not build it — the next push to the branch is built then, whatever it changed. Commit statuses are not read. False: every push is built at once.deploy_checksstring[] · optionalThe check runs a push waits for (`deploy_after_checks`) instead of every check, by their names as GitHub shows them — a GitHub Actions job's name, e.g. `unit` — from the app `deploy_checks_app` names, on the commit's suites for the machine's branch (a run of the same commit from a tag or another branch does not count, nor another app's run of that name): each is to be reported, to end and to succeed (success or neutral: a named check skipped did not run) — every run of that name, when two workflows name a job alike. While a suite of that app is open on the branch, with runs or not yet, the push waits. No other check is waited for or looked at. A named check that ends otherwise, or that the app's suites on the branch all ended without (cancelled before they ran), and the build is `skipped` at once (`reason`); one not reported in 6 hours, too. 20 names at most, each 1 to 200 characters with no space around it, named once. Empty: every check is waited for.deploy_checks_appstring · optionalThe app named checks (`deploy_checks`) are taken from, by its GitHub App slug — as a required check's expected source is: another app's run of a named check counts for nothing. Empty or left out: github-actions.test_commandstring · optionalWhat each new build of the machine runs before it takes traffic (a pre-deploy test step): once its database's migration has started, the new version comes up beside the one that serves — its own env, secrets and database — and its image runs this command in a shell (so the image has one) against it: `PALBASE_TEST_BASE_URL` is where it answers, `PALBASE_TEST_AUTH_URL` the project's auth. The tests reach what the machine reaches — its database, the project's modules — so they write as it does. They end other than 0 and the build fails, its `reason` naming the tests that failed: the version never takes traffic, the machine runs what it ran, and the migration is taken back. `bun test`, `npm test`. A build is tested as the machine says when it is released. Absent, a build rolls out once built.test_usersstring[] · optionalThe project's test users each test run makes for its tests to act as — `PALBASE_TEST_IDENTITIES` names them, each with its access token (`api.signInAs("alice")`) — and deletes once the run has ended, however it ended. Each a name, once whatever its case: letters, digits, `_` and `-`, 64 at most.openapi_pathstring · optionalWhere the machine's app serves its contract when it is not a palbase/backend app. Empty (the default) for a palbase/backend app.git_access_tokenstring · optionalFor a source read with tokens (`source.access` token), the token its first build reads it with: a GitHub App installation's token (ghs_…) made for the machine's repository alone, read-only (contents: read) — GitHub's POST /app/installations/{id}/access_tokens with `repositories: [name]`. It is checked with GitHub before the machine is made, read once by the build, and kept nowhere: no answer, log or build says it. A person's token (ghp_, github_pat_, gho_, ghu_) is refused. Refused for a machine Palbase Cloud reads.commitstring · optionalFor a source read with tokens, the first build's commit (its full SHA): the branch's head (409 commit_not_head otherwise); the head when left out.environmentstring · optionalThe ref of the environment called, when given: a new machine is bound to the environment whose address it is made at (409 bound_to_environment for another — make it at that environment's address). Its name is the project's one: name_taken when another environment holds a machine of that name.autoscalingobject · optionalHow a machine's copies follow its load: as many run as keep each copy near the share of its size's processor and of its memory given here, from the machine's replicas (the fewest, two at least) to max_replicas, spread for high availability. The platform adds a copy within seconds of copies running above that share, and scales down after five minutes under it. A copy added or taken away starts no other copy anew: what a copy is told (PALBASE_REPLICAS) and its share of a database are of max_replicas. Each copy is paid for while it runs, as any copy; on Pay as you go only (Free runs one copy). Null: the machine runs its replicas, that many always — in a change, it no longer scales. A change of autoscaling, or of replicas while it scales, is no new version and starts no copy anew, but for max_replicas.curl -X POST "https://<your-ref>.palbase.studio/machines" \
-H "apikey: $PALBASE_SECRET_KEY" \
-H "content-type: application/json" \
-d '{"size":"dedicated-1x","source":{"repository":"string","branch":"string"}}'Responses
201The machine, starting
400Validation failed or a required field is missing
401Missing or invalid API key
403Not the project's secret key; or the request requires elevated owner authentication (`owner_only`); or the size is not open to the project (`size_not_available`, its reason as GET /machines/sizes and /databases/sizes say it).
409The project already has a machine of this name, or has as many machines as it may
429Over the project's request limit, or its machine time for this period is used up
503Temporarily unavailable; retrying is safe after Retry-After
defaultAn error: the envelope names it (`error`) and explains it (`error_description`).
Operation CreateMachine of machines's contract.