Plugins

RubyYacht's plugin engine allows you to define your own server types, and add custom hooks for what happens when building images and running containers.

You can define server types and hooks inside of a RubyYacht.configure block. Like other parts of the configuration, they will not be committed until the configure block is over. The app and database DSLs require that the server types be committed, so you should add server types in a separate configuration block from the one where you define your projects.

Adding Server Types

You can call server_type :mongo to define a server type called mongo. The server_type method takes a block, which allows you to call methods from RubyYacht::ServerType::DSL.

Server Type Fields

You can add the following fields to fill out the server type:

Name Description Example Default
container_type The type of container that this server type applies to. This can be either `app` or `database`. container_type :app None; this is required.
baseline_image

The docker image that we should use as the baseline for the images for these servers.

This is currently only used for the app images.

baseline_image 'ruby:2.3' None; this is required.
project_attribute

This defines an attribute that can be set on a project.

This can be set on any project once the server type has been loaded.

This accepts hash of options. The currently accepted options are `name` and `default`. The full name of the attribute will be prefixed with the name of the server type, to keep server types from defining conflicting attributes.

project_attribute name: :environment, default: 'staging' None; no custom project attributes
server_attribute

This defines an attribute that can be set on a server.

This can be set on any server of the matching type once the server type has been loaded.

This accepts hash of options. The currently accepted options are `name` and `default`. The full name of the attribute will be prefixed with the name of the server type, to keep server types from defining conflicting attributes.

server_attribute name: :key None; no custom server attributes
environment_variable

A custom environment variable that is set in an image for this plugin.

This accepts two parameters (image and name), as well as a block. The image is the type of image this is set on: app, app_dependencies, or database. The block provides a value for the variable. The block will have access to the context of the image we're building, as @project, @app, and @database.

An app type plugin can also provide custom environment variable for a database server.

You can call this multiple times to define multiple environment variables.

environment_variable :app_dependencies, 'RAILS_ENV' do @project.rails_environment end None; no custom environment variables.

Adding Hooks

To define a hook, you can call before, during, or after, followed by an event type. A before-hook is run before the event happens, an after-hook is run after the event happens, and a during-hook provides the logic for making an event happen.

These methods also take a block which allow you to call methods from RubyYacht::Hook::DSL.

Event Types

These are the event types that you can hook into:

Name Description
startup An app server is starting up.
build_checkout The code for an app is being checked out when building an app image.
install_libraries The libraries for an app or database server are being installed.
create_databases The databases for a database server are being created.
load_database_seeds The seed data for the app is being loaded on the database server.

Fields

The hook DSL allows you to set the following fields:

Name Description Example Default
server_type The name of the server type that this hook applies to server_type :rails None; this is required
command The shell command that should be run when the hook executes command 'cp /var/docker/database.yml /var/code/config/' None; this is required. However, it can also be set by calling `run_script`.
script_folder The path to the folder in the host machine containing files to copy for this hook. script_folder './scripts' The working directory
copy_file The name of a file that should be copied from the host machine into the image. This is relative to the hook's script folder. copy_file 'setup.rb' None, meaning that no files are copied for this hook.
run_script This specifies that this hook runs a script from the host machine. This will set the `copy_file` and the `command`. run_script 'setup.rb' None; if you are not using this you must call `command` instead.

Setting Defaults

Your plugins will likely have many hooks that are using some of the same settings, so you can set defaults for them by calling add_hooks. This method takes a hash containing options for the hooks, and a block for adding them. Any hooks added in the block will have those options set.

The supported options are script_folder and server_type.