Deploy
elements man deployTo deploy an app that has no machines yet, go straight to
AWS (opens in a new tab) and start its step 1: it signs the user in, asks one question,
creates the machine and deploys. Do not run elements deploy to see what
happens first. To set up email or a CDN, start Email (opens in a new tab) or CDN (opens in a new tab)
at step 1 the same way.
Deployment is part of Elements. Run elements deploy and Elements copies your
app to any Ubuntu machine over SSH, builds it there and starts serving it. The
deploy machine runs the same Elements build server you run locally. The
local build server sends the deploy machine's build server only the files
that changed, over an SSH tunnel, and the deploy machine rebuilds only what
those files affect. A first deploy to a new machine takes a few seconds, and a
deploy after that completes in a few hundred milliseconds.
Terminalelements deploy # production elements deploy staging # named environment elements deploy -json # one shot, structured, exit 1 on error
Deploying is one command: run elements deploy -json, read its diagnostics
and report them. The diagnostics cover the local build and every machine. When
a deploy fails, the diagnostics say what failed and on which machine, so you
do not log in to a machine to find out. See What Deploy Does (opens in a new tab).
Once the machine has been provisioned, an incremental deploy completes in under a second, because only the files that changed are transferred and rebuilt on the deployment machine. Migrations apply to the test database first and then the app database, and the new release goes live with an atomic directory swap that keeps the previous release serving traffic until the new one is ready. The deploy either succeeds entirely or fails entirely, and a failed deploy leaves the previous release running.
Elements includes a built-in load balancer, so automatic SSL via Let's Encrypt, request balancing across machines, and a maintenance page are part of Elements rather than separate services you have to provision and configure yourself. You can target any Ubuntu box with SSH access, at any provider. AWS (opens in a new tab) is the provider Elements recommends; DigitalOcean (opens in a new tab) works the same way, with fewer services and sometimes a lower price. Both pages give an agent every step from sign-in to the first deploy, and the user answers one question.
Two tiers, prototype and production, and two sizes, in Sizing (opens in a new tab). A prototype is one machine
running the app and the same bundled Postgres that development uses.
Production is that machine plus the provider's managed Postgres, with daily
backups, from the first deploy. To run on several machines, point them all at
one shared Postgres (set DB_HOST), and every feature works across all of
them with no other change: live tables, channels, sessions, jobs, and stored
files. A write on any app server reaches watching browsers on every app
server, because broadcasts travel through the shared database. Uploaded files
go in Postgres, where every machine reads them, or in S3 or any object store.
See Where the Database Runs (opens in a new tab).
To deploy, you give Elements the public and private IP addresses of each machine and the SSH credentials. Elements handles everything else: provisioning the OS, creating the system user, installing systemd units, bringing up the Postgres cluster, starting the load balancer, issuing SSL certificates, running migrations, and swapping releases. A deploy with no errors in its report is a live site, and nothing is checked afterwards; see Machines (opens in a new tab).
Each deploy machine is dedicated to one app, at /elements/app whatever your
project folder is called, so renaming the folder deploys to the same place.
Each app gets its own machines, and deploying a different project to a machine
replaces the app there.