Deploy script

Every project keeps the same deploy file in its root and runs it on the server in the project directory:
The script adapts to the project, the same file works in every one of them. Settings of a single project belong to deploy.conf next to it, the deploy file itself is never edited. Current version: 1.0.0. Check the version of a project with:
The version is also printed at the start and at the end of every deploy.

Installation

The script ships with CrudAdmin, every version of it is committed in crudadmin/crudadmin. Publish it into the root of the project and commit it:
After a CrudAdmin update which brings a new version of the script, publish it again with --force. deploy.conf of the project stays untouched. Projects on CrudAdmin 5 and older copy the file from a project which has it.

Steps

A failed step stops the deploy, except the steps below. The deploy goes on without them, lists them at the end and exits with 1:
  • optimize fails, usually on a closure in a config file. The script caches only the routes, views and events then.
  • The project calls env() outside of the config files. The script removes the cached config, env() would return null with it.
  • Restarting a queue, Horizon, Reverb or Pulse fails.

Queue workers

queue:restart only asks the running workers to stop after their current job. A process monitor starts them again with the new code, Supervisor on our servers. Keep its config in the project, e.g. project-supervisor.conf, and run the workers with the PHP version of the project:
project-supervisor.conf

Octane

The script reloads the workers of Laravel Octane when the project requires laravel/octane and the server runs. When it does not run, the deploy says so and goes on.

Project settings

deploy.conf in the project root is a bash file read before the first step. Commit it with the project. It is optional, most projects need none. Hooks are bash functions defined in deploy.conf: deploy_before runs before git pull, deploy_before_npm and deploy_after_npm around the frontend build, deploy_after at the end.
deploy.conf
A project on Laravel Mix:
deploy.conf
Environment variables override the defaults for one run, settings in deploy.conf win over them:

Versions

Raise the version in src/Resources/deploy/deploy of crudadmin and add a row here with every change of the script.

php artisan optimize

CrudAdmin 6 supports php artisan optimize; projects on older versions deployed without it. Without the caches every request loads all config files and route files and discovers the admin models again. A cached config has two rules, the whole list is in Config cache:
  • Config files contain no closures, config:cache fails on them.
  • env() is called only in config files. The .env file is not loaded with a cached config, so env() returns null everywhere else.
Websites with localizedRoutes() cache their routes too, they are registered once for every language. Run optimize again after a language is added. php artisan admin:upgrade:cache of crudadmin/upgrade lists both in a project. Change the .env file on the server only together with a new php artisan optimize, the cached config keeps the old values until then.