Contents

Build & Deploy Hooks

The Build & Deploy Process

Build and deploy hooks take place at very specific points in both the build and deploy processes.

Build Hooks

Your app's engine builds and prepares your app's runtime and code. It's possible to include "extra steps" in this process. These are configured in the run.config section of your boxfile.yml.

extra_steps

extra_steps run after your app's runtime is built, but before the runtime is packaged for use.

run.config:
  extra_steps:
    - 'yarn install'
    - 'bower install'

Important Things to Know About Extra Steps

  • Environment variables are not available during the build process.
  • extra_steps do not have access to data services.
  • Code is fully writable.

Deploy Hooks

Deploy hooks run as apps are being deployed either to a dry-run or live app.

extra_steps

extra_steps run locally as your app is prepared and compiled for deploy. Everything is writable, but you do not have access to environment variables or data services. File changes are only made inside the deployable package and will not change your local codebase.

deploy.config:
  extra_steps:
    - mv config-prod.yml config.yml

transform

transform hooks run after your code has been deployed to your live app, but before everything is locked down with read-only permissions and distributed into new containers/servers. Your codebase is fully writable and you have access to environment variables associated with your live app. However, you cannot access live data components.

transform hooks should primarily be used to modify config files or other environment-specific filesystem changes that use environment variables.

deploy.config:
  transform:
    - 'sed -i /HOST/$DATA_DB_HOST/g config/database.xml'
    - 'if [ "$ENV" = "prod" ]; then mv config-prod.yml config.yml; fi'

before_live

before_live hooks run on a new container/server before it starts accepting live requests. These are unique to each component, so Nanobox needs to know on which each will run. In multi-node components, these only run on a single node.

deploy.config:
  before_live:
    web.site:
      - 'bundle exec rake clear-cache'
      - 'echo I\'am ready to go'
    worker.jobs:
      - 'bundle exec check-queue'

before_live_all

before_live_all hooks are the same as before_live hooks, but they run on all new nodes in a multi-node component. These are useful when you need to modify the contents of writable directories.

deploy.config:
  before_live_all:
    web.site:
      - 'bundle exec prime-local-cache'
      - 'bundle exec register-host'

after_live

after_live hooks run on a new container/server after it starts accepting live requests. These are unique to each component, so Nanobox needs to know on which each will run. In multi-node components, these only run on a single node.

deploy.config:
  after_live:
    web.site:
      - 'bundle exec rake prime-cache'
      - 'echo "I am working"'
    worker.jobs:
      - 'bundle exec start-queue'

after_live_all

after_live_all hooks are the same as after_live hooks, but they run on all new nodes in a multi-node component. These are useful when you need to modify the contents of writable directories.

deploy.config:
  after_live_all:
    web.site:
      - 'bundle exec prime-local-cache'
      - 'bundle exec register-host'

Reach out to help@nanobox.io and we'll try to help.