Docker Hooks

Hook Generator

To generator a starter hook:

$ ufo new hook docker
      create  .ufo/config/hooks/docker.rb

Docker Hooks

Hook Description
build When ufo builds Docker image.
push When ufo pushes the Docker image.

Here are some examples of running custom hooks before and after the docker commands.

Build Hooks


  execute: "echo 'docker build before hook'",

  execute: "echo 'docker build after hook'",

Results in:

$ ufo docker build
Running docker before build hook.
=> echo 'docker build before hook'
docker build before hook
=> docker build -t -f Dockerfile .
Running docker after build hook.
=> echo 'docker build after hook'
docker build after hook

Push Hooks

  execute: "echo 'docker push before hook'",

  execute: "echo 'docker push after hook'",

Results in:

$ ufo docker push
Running docker before push hook.
=> echo 'docker push before hook'
docker push before hook
=> docker push
Running docker after push hook.
=> echo 'docker push after hook'
docker push after hook

exit_on_fail option

By default, if the hook commands fail, then ufo will exit with the original hook error code. You can change this behavior with the exit_on_fail option.

  execute: "/command/will/fail/but/will/continue",
  exit_on_fail: false,

General Form


The command name corresponds to the docker commands: build, push, etc.

Hook Options

Name Description
label A human-friendly label so you can see what hooks is being run.
execute The script or command to run. IE: path/to/some/
exit_on_fail Whether or not to continue process if the script returns an failed exit code.

Ruby Hooks

Instead of using a script for the hook execute option, you can also use a Ruby object. This provides some more control over the current process. See: Ruby Hooks