Environments
elements man deploy/environmentsNaming and targeting environments, running tests before a deploy, and pointing a command at a deploy machine with -remote.
An environment is a named set of config: the name selects both the env file
(config/env/<name>.env) and the deploy target (deploy.env.<name>). An
environment name is any name you choose. development is the default locally, production is the
default for elements deploy, and any other name (staging, demo, a
client's name) works the same way.
The environment says which config applies, not where the app runs. Any
environment can run locally (ENV=demo elements start) or on a deploy machine.
Behavior that differs between a local run and a deploy machine, such as the
error page with a stack trace and opening the browser, depends on where the
app runs and not on the environment's name:
isDeployMachine() from @elements/app is true on a deploy machine and false
locally, whatever the environment is named.
Hosts differ per environment through the env file, not through deploy.
server.domain reads them with env!(), so each environment's file supplies
its own (elements man config):
config.jsocserver: { domain: env!("DOMAIN"), },
config/env/development.envDOMAIN=localhost
config/env/staging.envDOMAIN=staging.example.com
config/env/production.envDOMAIN=example.com
deploy.env is a map of environment names to per-environment overrides.
config.jsocdeploy: { ssh: { user: "ubuntu", ... }, // shared default env: { production: { machines: [...], }, staging: { machines: [...], }, }, }
elements deploy defaults to production. elements deploy <env> targets a
named environment.
Per-environment overrides: port, address, ssl, tlsCerts,
ignoreStaleMigrations, license, ssh, services, packages,
machines.
port and address resolve deploy.env.<name> first, then deploy, then the
top-level server block, then the defaults (4000 and 127.0.0.1). Set them
under server to change the port or address the app listens on. Set them
under deploy.env.<name> when one deployed environment needs a different
port or address.
Timeout
A deploy fails if it runs longer than -timeout (default 30m). Raise it for a
first deploy to a slow machine, where provisioning takes most of the time:
Terminalelements deploy -timeout=1h
Tests
Tests run as part of every deploy, against the target environment's test
database. There is no test environment to switch to in Elements. Each deploy
environment has both an app database (<app>) and a test database
(<app>_test), and tests for that environment run against the test database
before the release goes live. A failing test aborts the deploy and the previous
release continues serving traffic.
If you want an environment dedicated to verifying changes before production,
configure a staging environment. Tests run there on every deploy the same way
they run on production, against that environment's test database.
Connecting to Deploy Machines
Most commands accept -remote=<env>[#<machine>] to run against a deployed
machine instead of the local project.
Terminalelements build -remote=production -json elements db -remote=production#production1 elements test -remote=staging -json elements ssh -remote=production elements ssh -remote=production#production2
-remote without a value uses the first machine in production.
Use -remote to answer a specific question about a running deploy, such as
what a table holds or what the build state is on a machine. Do not use
-remote to investigate a failed elements deploy: the deploy's diagnostics
already report what happened on the machine. See
Operations (opens in a new tab).