Processes, env vars and build secrets
Run processes as containers, set limits and ports, and pass secrets to your image build
Updated
On a Dockerfile cluster each of your app's processes runs as a container from the app's image, and env vars are handed to every container.
Processes
A process's command runs in place of the image's CMD, with the image's entrypoint, so bundle exec sidekiq or bin/jobs work as they do with the Rails Dockerfile. Leave the command blank to run the image's own command, which is what the server process Hatchbox detects does.
The process named server with the web role (or the first web-role process) is the one Caddy sends traffic to.
Each process also has:
- Stop timeout, 30 seconds by default: how long a container gets to finish its work after SIGTERM before it's killed on a deploy or restart. Give a worker that runs long jobs more.
- Memory limit in megabytes, holding each of the process's containers to that much. A container that runs out of memory is killed and restarted.
- CPU limit, like
0.5or2. A limit above what a server has gives the container all of that server's CPUs.
None of the limits are set by default. Changing one replaces the process's containers.
Ports
Hatchbox doesn't set PORT on Dockerfile clusters. The web container listens on the port your Dockerfile's last EXPOSE names, read on every deploy, or 80 without one (where the Rails Dockerfile's Thruster listens). To change the port, change the EXPOSE.
Env vars
Env vars are written to /home/deploy/<app>/env on each server and handed to every container, including the pre-deploy command, cron jobs and bin/run. Containers only read them when they're created, so changing env vars replaces the containers, without dropping requests.
A database URL that points at localhost reaches the container itself, not the server. The env vars Hatchbox writes for its own databases already use addresses containers can reach.
Build secrets
Every env var is also available as a BuildKit secret during the image build. A build step that needs one, like RAILS_MASTER_KEY for asset precompilation or BUNDLE_GITHUB__COM for private gems, mounts it by name:
RUN --mount=type=secret,id=RAILS_MASTER_KEY \
RAILS_MASTER_KEY="$(cat /run/secrets/RAILS_MASTER_KEY)" bin/rails assets:precompile
Secrets your Dockerfile doesn't mount aren't visible to the build, and nothing lands in the image, its history or the layer cache.
Container settings
The app's settings, under Deploys, hold the Dockerfile path, the health check timeout, the command to run before each deploy, volumes and the assets path. Changes apply on the next deploy.
The API has them too:
GETandPATCH /api/v1/apps/:app_id/containerreads and updates the app's container settings. An update changes only what it names;volumesis an array, andcontainer_portis read-only, from the Dockerfile'sEXPOSE.PATCH /api/v1/apps/:app_id/processes/:idtakescontainer: {stop_timeout, memory_mb, cpus}.