Customising a Remote Deployment

Waddle's remote deployment is plain shell scripts in your project, so you can add any custom step, like a cache warmup or a migration, for a specific server.

Sometimes a project needs an extra step at a specific moment of a remote deploy: warm a cache, notify a service, run a one-off migration, mount something, set a vendor-specific variable. Waddle does not try to provide a setting for every such case. Instead, the whole deployment is plain shell scripts that live in your project, so you can make it do anything.

The recommended pattern is two parts:

  1. Make the environment identify itself with an environment variable on the remote.
  2. Branch on that variable inside the relevant script in the deploy chain.

1. Identify the environment

When Waddle deploys, it runs (over SSH, non-interactively) the same command on every remote, whether it’s prod, stage, or anything else:

cd <project_path> && sh bin/deploy/run --remote

--remote is a plain boolean flag, it takes no value and never tells the script which remote it’s running on. All it does is switch the chain from local to remote behavior: it skips steps that only make sense on a dev machine (git branch/stash bookkeeping, generating a self-signed SSL certificate, and rebuilding Docker images, since the code and images are already in place from the push), while still running service startup, database init/setup, and a Redis flush the same way on every remote. Because that behavior is identical everywhere out of the box, telling prod apart from stage is entirely up to you.

To do that, give each server a stable identifier the deploy can read, any environment variable name you like works; it does not need a WADDLE_ prefix, since that is reserved for the variables Waddle’s own set-env script sets. Any of these mechanisms works:

  • /etc/environment, e.g. DEPLOY_TARGET=acme-prod. Loaded by PAM for SSH sessions, so it is visible to the deploy command.
  • Hostname, detected inside the script with $(hostname) / $(hostname -f). No setup needed.
  • A marker file in the project directory (e.g. .deploy-target) that the script reads. Useful when the same host runs several environments.

2. Branch in the deploy chain

These scripts run, in order, on every remote push. Pick the one whose timing fits, copy your identifying check into it, and guard your custom commands with it:

Script Runs… Good for
bin/deploy/set-env First, sourced by run to set the WADDLE_* variables Overriding/adding environment variables for the rest of the deploy
bin/deploy/run The main deploy, builds/starts each service in turn Steps before/after a specific service starts
<service>/script/run.sh Each time that service’s container starts Per-container setup (e.g. an extra step only the php container needs)
after_project_update.sh Last, after all services are up Post-deploy application steps (migrations, cache warmup, notifications)

Example guard inside bin/deploy/run:

# Custom: only on the production box, prime the CDN after the web service is up.
if [ "${DEPLOY_TARGET:-}" = "acme-prod" ]; then
    echo "[CUSTOM] Priming CDN."
    curl -fsS https://cdn.example.com/prime || true
fi

Guidelines

  • Keep it idempotent. Every step may run again on the next push.
  • Fail soft for non-critical extras (|| true) so a side task never aborts the deploy; let genuinely required steps fail loudly.
  • Prefer after_project_update.sh for post-deploy work; it is the purpose-built hook and the least disruptive place to add logic. Reach for set-env / run / a service run.sh only when you need to inject logic between certain steps.

See also