Walkthrough
elements man deploy/walkthroughFrom zero to a deployed app on a fresh machine.
Walkthrough: From Zero to Deployed
The steps every provider has in common. AWS (opens in a new tab), the provider Elements recommends, and DigitalOcean (opens in a new tab) give the exact commands for each, with the agent doing the work; this page is the shape of it, for those two and for any provider that gives you Ubuntu over SSH.
Each step here costs money or modifies infrastructure. Confirm the shape and the provider's price with the user before creating anything, and confirm again before anything destructive.
1. Tier and Size
A test or real users: prototype or production. Production puts the database on the provider's managed Postgres from day one. Everyone starts small. See Sizing (opens in a new tab).
2. Machine
Create an Ubuntu Linux box at your provider, on the latest Ubuntu release it
offers, at the chosen size. Note the public and private IPs. Make sure your
SSH key is authorized on the machine and that you can ssh ubuntu@<public-ip>
(or root@, depending on the provider). The provider pages make the key per
project so the user never handles one.
3. Database
Prototype: nothing to provision. Elements brings up the bundled Postgres
cluster on the box during the first deploy, and the scaffolded
production.env already sets DB_HOST=127.0.0.1.
Production: create the provider's smallest managed Postgres now, with daily
backups, reachable from the app machine only, and copy its connection values
into production.env as in Setup (opens in a new tab). Every machine that points at the
same database runs every feature across all of them.
4. Domain
Two ways to reach the app. With no domain it is available at
http://<public-ip> over plain HTTP. With a domain, Elements provisions SSL
automatically and serves it at https://<your-domain>.
elements domain gets a generated name under elements.online and writes it
to config.jsoc, so the first deploy is HTTPS with nothing to register (see
Domain (opens in a new tab)). A domain
of your own goes in deploy.domain, as one host (domain: "example.com") or
a list (domain: ["example.com", "www.example.com"]), with an A record at
the registrar pointing at the machine's public IP:
DNS recordA example.com <public-ip>
With multiple machines, point DNS at any one of them or list several records
for DNS-level round-robin and failover. Every machine runs its own load
balancer and round-robins requests to the others, so traffic is distributed
across all of them even with one DNS record. When domain is set, Elements
issues and renews certificates for those hosts via Let's Encrypt; there is no
certificate to provision, no renewal cron, and no HTTPS to configure
elsewhere.
5. Config
config.jsoc{ database: { name: "my_app", host: env("DB_HOST", "127.0.0.1"), port: env<number>("DB_PORT", 5433), user: env("DB_USER", "postgres"), password: env("DB_PASSWORD", ""), }, session: { expires: "30d", }, deploy: { domain: "example.com", ssh: { user: "ubuntu", identityFile: "~/.ssh/id_ed25519" }, env: { production: { machines: [ { name: "production0", publicIp: "<public-ip-from-step-2>", privateIp: "<private-ip-from-step-2>" }, ], }, }, }, }
config/env/production.env (gitignored):
config/env/production.envDB_HOST=127.0.0.1
That is the prototype's database configuration. For production, set
DB_HOST, DB_PORT, DB_USER, DB_PASSWORD and DB_SSL_ROOT_CERT to the
managed database's values instead.
6. Deploy
Terminalelements deploy -json
The first deploy provisions the machine: installs Elements, creates the system user, sets up systemd, brings up the Postgres cluster on a prototype, installs the license, configures the built-in load balancer, and provisions SSL via Let's Encrypt. Subsequent deploys transfer only what changed. The local project server speaks directly to the deploy machine's project server over the SSH tunnel, an incremental build runs on the deployment machine, and typical incremental deploys complete in under a second.
7. Done
The deploy verifies itself. It exits non-zero and prints diagnostics if any
phase failed, and an empty diagnostics array means the release is live.
Open the URL in a browser to see it. There is no health check to run
afterward and no machine to log into; see Machines (opens in a new tab).
Terminalelements db -remote=production # psql against the production db