distillery v2.1.1 Distillery.Releases.Plugin behaviour View Source

This module provides a simple way to add additional processing to phases of the release assembly and archival.

Implementing your own plugin

To create a Distillery plugin, create a new module in which you use Distillery.Releases.Plugin. Then write implementations for the following callbacks:

The default implementation is to pass the original %Release{}. You will only need to implement the functions your plugin requires.

When you use Distillery.Releases.Plugin, the following happens:

  • Your module is marked with @behaviour Distillery.Releases.Plugin.
  • The Distillery.Releases.Release struct is aliased to %Release{}.
  • The functions debug/1, info/1, warn/1, notice/1, and error/1 are imported from Distillery.Releases.Shell. These should be used to present output to the user.

The first four callbacks (before_assembly/2, after_assembly/2, before_package/2, and after_package/2) will each be passed the %Release{} struct and options passed to the plugin. You can return a modified struct, or nil. Any other return value will lead to runtime errors.

after_cleanup/2 is only invoked on mix distillery.release.clean. It will be passed the command line arguments. The return value is not used.

Example

defmodule MyApp.PluginDemo do
  use Distillery.Releases.Plugin

  def before_assembly(%Release{} = release, _opts) do
    info "This is executed just prior to assembling the release"
    release # or nil
  end

  def after_assembly(%Release{} = release, _opts) do
    info "This is executed just after assembling, and just prior to packaging the release"
    release # or nil
  end

  def before_package(%Release{} = release, _opts) do
    info "This is executed just before packaging the release"
    release # or nil
  end

  def after_package(%Release{} = release, _opts) do
    info "This is executed just after packaging the release"
    release # or nil
  end

  def after_cleanup(_args, _opts) do
    info "This is executed just after running cleanup"
    :ok # It doesn't matter what we return here
  end
end

Link to this section Summary

Functions

Run the after_assembly/2 callback of all plugins of release.

Run the after_cleanup/2 callback of all plugins of release.

Run the after_package/2 callback of all plugins of release.

Run the before_assembly/2 callback of all plugins of release.

Run the before_package/2 callback of all plugins of release.

Callbacks

Called after assembling the release.

Called when the user invokes the mix distillery.release.clean task.

Called after packaging the release.

Called before assembling the release.

Called before packaging the release.

Link to this section Functions

Link to this function

after_assembly(release) View Source
after_assembly(Distillery.Releases.Release.t()) ::
  {:ok, Distillery.Releases.Release.t()} | {:error, term()}

Run the after_assembly/2 callback of all plugins of release.

Link to this function

after_cleanup(release, args) View Source
after_cleanup(Distillery.Releases.Release.t(), [String.t()]) ::
  :ok | {:error, term()}

Run the after_cleanup/2 callback of all plugins of release.

Link to this function

after_package(release) View Source
after_package(Distillery.Releases.Release.t()) ::
  {:ok, Distillery.Releases.Release.t()} | {:error, term()}

Run the after_package/2 callback of all plugins of release.

Link to this function

before_assembly(release) View Source
before_assembly(Distillery.Releases.Release.t()) ::
  {:ok, Distillery.Releases.Release.t()} | {:error, term()}

Run the before_assembly/2 callback of all plugins of release.

Link to this function

before_package(release) View Source
before_package(Distillery.Releases.Release.t()) ::
  {:ok, Distillery.Releases.Release.t()} | {:error, term()}

Run the before_package/2 callback of all plugins of release.

Link to this section Callbacks

Called after assembling the release.

Should return a modified %Release{} or nil.

Link to this callback

after_cleanup(list, arg2) View Source
after_cleanup([String.t()], Keyword.t()) :: any()

Called when the user invokes the mix distillery.release.clean task.

The callback will be passed the command line arguments to mix distillery.release.clean. It should clean up the files the plugin created. The return value of this callback is ignored.

Called after packaging the release.

Should return a modified %Release{} or nil.

When in dev_mode, the packaging phase is skipped.

Called before assembling the release.

Should return a modified %Release{} or nil.

Called before packaging the release.

Should return a modified %Release{} or nil.

When in dev_mode, the packaging phase is skipped.