Magic Apps
Procfile and start commands
How Dcubix decides what each process runs, where migrations go, and the port your app listens on.
An app runs one or more processes from the same image. Each process has a command, and the app can have a release command that runs once per deploy.
Processes
| Kind | Runs | Instances |
|---|---|---|
web |
The public endpoint | Scales on its own between a minimum and a maximum, in every region |
worker |
Background jobs | A fixed number, in the first region |
scheduler |
Scheduled jobs | Always exactly one, in the first region |
An app has at most one web process. Workers and the scheduler run only in the app’s first region, so a scheduled job never fires twice. See Regions and scaling.
The Procfile
A Procfile at the root of the build is the place to set commands in code. Each line is a process name and its command:
release: python manage.py migrate --noinput
web: gunicorn --bind 0.0.0.0:$PORT --workers 2 mysite.wsgi:application
worker: celery -A mysite workerThe Procfile wins. What it declares applies at every deploy, and the dashboard shows those commands as read-only, marked “Settings from Procfile”. A command set in the dashboard applies only to what the Procfile leaves out. To change a command the Procfile declares, change the Procfile and push.
How a command is chosen
For each process, the first of these that exists is used:
- Its line in the Procfile.
- The command set for it in the dashboard.
- For the web process, the start command Railpack detected.
- For an image built from a Dockerfile, the image’s own
CMD.
If none of these gives the web process a command, the build stops at its first step and says so.
Each deploy’s log says where each command came from, for example web runs: gunicorn app:app (from the Procfile).
Commands run with /bin/sh -c. An image with no /bin/sh can only run its own CMD.
The release command
The release command runs once per deploy, after the build and before any process changes. Database migrations belong here. If it exits with a code other than 0, the deploy stops and the running version keeps serving.
It is chosen in this order:
- The Procfile’s
release:line. - A migration at the start of the Procfile’s
web:line, or of the start command Railpack detected. - The release command set in the dashboard.
Migrations in the start command
Railpack’s start commands for Django, Rails and Laravel run migrations before the server, as in python manage.py migrate && gunicorn …. Left there, every instance would run them on every start, restart and scale-out.
So Dcubix cuts a leading migration off the start command and runs it as the release command instead. It recognises python manage.py migrate &&, rake db:migrate &&, php artisan migrate && and similar, and makes them safe to run unattended: --noinput for Django, and config:clear first and --force for Laravel. Laravel apps get php artisan migrate as their release command even when no migration is in the command.
A migration you write into the web command in the dashboard stays where you put it.
How it runs
- In a container of its own, in the app’s first region, with the app’s runtime variables.
- With no input: a command that asks a question gets end-of-file at once and fails, instead of waiting. Use the command’s non-interactive flag.
- Without the process’s volume. Migrations for a database on a volume, such as SQLite, belong in the process’s start command.
The port
Dcubix sets the PORT environment variable, and the web process must listen on it, on 0.0.0.0. Its value is:
- The port set in the app’s settings, if any.
- Otherwise, the port in the Dockerfile’s single
EXPOSE. - Otherwise,
8080.
The start commands Railpack detects read PORT. If your framework listens on a fixed port, either make it read PORT or set the app’s port to match.
Variables Dcubix sets
| Variable | Value |
|---|---|
PORT |
The port to listen on |
DCUBIX_GIT_SHA |
The commit being run |
Your own variables can’t use these names, or any name starting with DCUBIX_.