Donkeyfile

Keep a project's build commands, file rules and SSH commands in its repository, versioned with the code they deploy.

A Donkeyfile at the root of a repository keeps the deployment settings of a project in the code, next to what it deploys, the way a Jenkinsfile does for a pipeline. Changes to it are reviewed, versioned and rolled back with the code.

The file is read from the commit being deployed (the end commit), so a deployment of an old release uses that release's settings.

Example
version: 1

variables:
  APP_ENV: production
  RELEASE: "%end_commit_ref%"

build:
  image: node:18-alpine            # default Docker image of the build steps
  steps:
    - npm ci
    - name: Production bundle
      run: npm run build -- --mode=%APP_ENV%
    - name: Docs
      run: npm run docs
      image: node:20-alpine        # a step can use its own image
      when:
        branch: [master, release/*]
  cache:
    - node_modules/**

files:
  include: [dist/**, public/**]
  exclude: ["**/*.map", Donkeyfile]

before:
  - php artisan down

after:
  - run: php artisan migrate --force
    when:
      branch: master
  - php artisan up

failOnCommandError: true

servers:
  staging:                         # server id, matched without case
    variables:
      APP_ENV: staging
    after:
      - php artisan up
How it combines with the project's settings

Every section is optional. A section the Donkeyfile sets replaces the matching settings sent with the deployment (from the project's settings, the deploy form or the API); a section it leaves out keeps them. An empty section clears them: before: [] runs no before commands even if the project has some.

DonkeyfileReplaces
build.steps + build.imageBuild commands
build.cacheCache follow rules
files.include / files.excludeInclude and exclude build file rules
beforeSSH commands run before the deployment
afterSSH commands run after the deployment
failOnCommandErrorFail deployments if SSH commands fail

build and files are replaced as a whole: setting build without cache clears the project's cache rules.

Without a Donkeyfile nothing changes.

The deployment's output has a Donkeyfile step listing the sections that were applied, the warnings and the errors.

Sections

version

Optional, 1 is the only version.

variables

Names of letters, digits and underscores. %NAME% is replaced in every run command. Values can refer to other variables and to the built-in ones.

Donkeyfile variables are replaced first; the built-in variables (%branch%, %end_commit_ref%, %path%, ...) are then replaced in before/after commands as they always have been. A Donkeyfile variable with the name of a built-in hides it. Anything else between % signs, like date +%Y-%m-%d, is left as it is.

build

Runs in Docker on our servers, with the checked-out commit mounted at /source.

  • image: the image of steps that do not set one. Every build step needs an image from one of the two.
  • steps: commands, run in order.
  • cache: wildcard patterns of files kept between deployments (node_modules/**).

A stack deployment builds once for all its servers, so build steps can only be conditioned on the branch.

files

Wildcard patterns of the files to upload (include, everything by default) and to leave out (exclude).

before / after

Commands run over SSH in the server directory, before and after the upload. On protocols without SSH (FTP, S3, ...) they are skipped, as today.

failOnCommandError

true fails the deployment when a before/after command fails; false carries on.

servers

Settings for one server, keyed by its id. A server can set variables (merged over the top-level ones), files, before, after and failOnCommandError; each replaces the top-level section for that server. A server id the project does not have is reported in the deployment's output, since it is most likely a typo.

Steps

A step is either a command:

- npm ci

or a mapping:

- name: Migrate            # optional label
  run: |                   # required; can span several lines
    cd current
    php artisan migrate --force
  image: php:8.2-cli       # build steps only
  when:                    # optional; the step runs when every condition it sets matches
    branch: [master, release/*]
    server: [production, prod-*]   # before/after steps only

Patterns use * within a path segment (release/* matches release/1.2, not release/1.2/fix), ** across segments and ? for one character. Branches are matched with case, servers without.

Errors

A Donkeyfile that can not be read fails the deployment with error 4004 Invalid Donkeyfile and says what is wrong, for example unknown key 'befor' or build.steps[1] has no Docker image. It does not fall back to the project's settings, which could upload files or run commands the repository no longer asks for. Fix the Donkeyfile in your repository and deploy again.

A build section with steps fails the deployment with error 4005 Build commands are disabled on this server where Donkey's deploy server does not run builds, before anything is uploaded. "This server" is Donkey's, not yours: remove the build section to deploy without building.

Limits: 64 KiB (error 5009), one YAML document, no aliases (*name). The file only declares commands: it can not run code on Donkey itself.

Still need help?

Tell us what you are trying to do and we will reply by e-mail.

Contact support