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 outline of the steps, for those two and for any provider that gives you Ubuntu over SSH.
Each step here costs money or modifies infrastructure. Confirm the tier, the size and the provider's price with the user before creating anything, and confirm again before anything destructive.
1. Tier and Size
Choose the tier: prototype for a test, production for real users. Production puts the database on the provider's managed Postgres from the first deploy. Start at the small size. 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 machine 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). When several machines use the
same database, every feature works across all of those machines.
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 server.domain as env!("DOMAIN"), with
DOMAIN=example.com in production.env and DOMAIN=localhost in
development.env, and an A record at the registrar pointing at the
machine's public IP. www.example.com is served as a redirect to it with no
config:
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 server.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", }, server: { domain: env!("DOMAIN"), }, deploy: { 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.envDOMAIN=example.com DB_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 build server connects directly to the deploy machine's build server over the SSH tunnel and sends it the changed files, an incremental build runs on the deployment machine, and typical incremental deploys complete in under a second.
7. Confirm the Release Is Live
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