Deployment Hooks

Amezmo will run a set of scripts for you before, during, and after your deployment. These scripts are expected to be located in the .amezmo directory of your applications root directory. The scripts are executed as a shell script using Bash. A set of environment variables are given to the script, for your reference. For example, the file after.pull is executed for the event After Pull.

Where are hooks defined in my application's source tree?

In the below sample application directory structure, the .amezmo directory is where you define your "hook" scripts.


# A sample laravel application root directory.
# The `tree -a -L 2 .` command was run inside a Laravel app's root directory.
.
├── .amezmo
│   ├── after.deploy
│   ├── after.pull
│   ├── after.upload
│   ├── before.deploy
│   ├── deploy.failure
│   └── deploy.success
├── app
├── artisan
├── bootstrap
├── composer.json
├── composer.lock
├── config
├── database
├── routes
├── server.php
├── storage
├── vendor
├── node_modules
├── .env

Note that Amezmo will fail your deployment, if any of your hook scripts return a non-zero exit status. However, there is one exception to this rule. The before.pull hook must have its exit status ignored to avoid a repeated cycle of failure.

As part of the deployment process, Amezmo will run a chmod across your target deployment directory. This ensures that any files created from your hooks will have correct and expected permissions. Amezmo ensures the owner/group is www-data:deployer. This allows for expected permissions across all areas of your application.

Hook list

These are the supported deployment hooks. You are not required to have deployment hooks. Every hook listed is optional. Note that for each hook listed, it is expected to be under the directory named .amezmo. This directory should be at the root of your applications directory tree.

Before Pull

The file before.pull is executed before Amezmo fetches the latest updates from your git provider. The exit status of this script is ignored. Relative to your application root directory, the full path of this hook is .amezmo/before.pull.

After Pull

The file after.pull is executed after Amezmo fetches the latest updates from your git provider. This script is where you would want to fetch dependencies from Composer If your script returns a non-zero exit status, the deployment fails. Relative to your application root directory, the full path of this hook is .amezmo/after.pull.

After upload

The file after.upload is executed after uploading your application (if you're not using Git). This script is where you would want to fetch dependencies from Composer If your script returns a non-zero exit status, the deployment fails. Relative to your application root directory, the full path of this hook is .amezmo/after.upload.

Before Deploy

The file before.deploy is executed before Amezmo updates your web server directory. If your script returns a non-zero exit status, the deployment fails. Relative to your application root directory, the full path of this hook is .amezmo/before.deploy.

Success

The file deploy.success is executed after Amezmo successfully deploys your application. This is the last hook that runs. If your script returns a non-zero exit status, the deployment fails. Relative to your application root directory, the full path of this hook is .amezmo/deploy.success.

Failure

The file deploy.failure is executed after Amezmo encounters a non-zero exit status from any of your hooks, or with the deployment process. Relative to your application root directory, the full path of this hook is .amezmo/deploy.failure.

Environment variables

Your hook script will have the following pre-defined environment variables set.

APPLICATION_ROOT

This is where your code is located on the server in the form of /webroot/release/${TIMESTAMP}.${COMMIT_ID}

REPO_NAME

The name of the repository currently being deployed

DEPLOY_BRANCH

The name of the branch currently being deployed

TARGET_HOOK

The name of hook being executed. This will be one of the values listed in the Hook list

RELEASE_NUMBER

The generated release number. If the release is from a Git deployment, then the value will be in the form of ${TIMESTAMP}.${COMMIT_ID}. For application uploads, the form is ${TIMESTAMP}.upload.

UPLOAD_FILE

Only set if you upload your code instead of using Git to deploy. This is the original file name that was provided.

DEPLOYMENT_DIRECTORY

The fully qualified path to the current in progress deployment. This will be in the form of /webroot/release/${TIMESTAMP}.upload for uploads, and ${TIMESTAMP}.${COMMIT_ID} for git deployments. See deployment directories for more information about directories.

Hook Monitoring

On the Deployments tab, you can see a list of your deployments. To view a single deployment click on the link in the status column. Note that, Amezmo will only show the hooks that were executed in the table below.

Limits

  • There is a 5 minute limit on hook execution
Need support?

We're always happy to help with either application or infrastructure questions Always feel free to reach out to us on Twitter, or contact support.

Subscribe