module FPM::Fry::Plugin::Env

The env plugin sets global environment variables.

@example add something to PATH in a recipe

plugin 'env', 'PATH' => '$PATH:/usr/local/go/bin'

Public Class Methods

apply(builder, env) click to toggle source
# File lib/fpm/fry/plugin/env.rb, line 26
def self.apply(builder, env)
  unless env.kind_of? Hash
    raise FPM::Fry::WithData(
      ArgumentError.new("ENV must be a Hash, got #{env.inspect}"),
      documentation: 'https://github.com/xing/fpm-fry/wiki/Plugin-env'
    )
  end
  env.each do |k,v|
    k = k.to_s if k.kind_of? Symbol
    unless k.kind_of?(String) && k =~ /\A[A-Z][A-Z0-9_]*\z/
      raise FPM::Fry::WithData(
        ArgumentError.new("environment variable names must be strings consisiting of uppercase letters, numbers and underscores, got #{k.inspect}"),
        documentation: 'https://github.com/xing/fpm-fry/wiki/Plugin-env'
      )
    end
  end
  builder.recipe.dockerfile_hooks << AddEnv.new(env.dup.freeze)
end