class Object

Public Instance Methods

cfn(args, &block) click to toggle source
# File lib/panoramix/plugin/cfn.rb, line 184
def cfn(args, &block)
  name = args.keys[0]

  deps = args[name]

  cfn_options = deps.select { |d| d.is_a? Hash }

  # Get cloudformation template file path
  template = cfn_options.empty? ? nil : cfn_options.first[:template]

  # Raise error if :template value is nil
  unless template
    message = I18n.t('errors.cfn.no_template_provided')
    raise(Panoramix::Plugin::DockerUpExceptionError, message)
  end

  # Required by aws cli
  template = File.expand_path template

  # Get cloudformation parameters file path
  parameters = cfn_options.empty? ? nil : cfn_options.first[:parameters]

  # Raise error if :parameters value is nil
  unless parameters
    message = I18n.t('errors.cfn.no_parameters_provided')
    raise(Panoramix::Plugin::DockerUpExceptionError, message)
  end

  # Raise error if the file does not exist
  unless File.exists? parameters
    message = I18n.t('errors.cfn.parameters_not_found', {:path => parameters})
    raise(Panoramix::Plugin::DockerUpExceptionError, message)
  end

  # Get the PANORAMIX_OWNER environment variable
  owner = ENV["PANORAMIX_OWNER"]
  raise "Variable PANORAMIX_OWNER not defined" unless owner

  # Convert name.surname to namesurname
  owner = owner.gsub(".", "")

  descriptions = I18n.t('cfn')
  descriptions = Hash.new if descriptions.class != Hash

  # Merge deps with the cloudformation template file task
  prerequisites = deps.select { |d| ! d.is_a? Hash }
  prerequisites = prerequisites.push(template)

  # Create a task for each version
  ["blue", "green", nil].each do |version|
    # Create a task inside each development stage namespace
    ["pro", "pre", "dev", "test"].each do |stage|
      stage_name = version ? "#{stage}:#{name}:#{version}" : "#{stage}:#{name}"
      instance = Panoramix::Plugin::CloudFormation.new(name, template, parameters, stage, owner, version)
      Panoramix.define_tasks(stage_name, descriptions, instance, prerequisites, block)
    end
  end
end
docker_build(args, &block) click to toggle source
# File lib/panoramix/plugin/docker_build.rb, line 47
def docker_build(args, &block)
  # Get task name
  name = args.keys[0]

  # Get configuration hash
  config = args[name].select { |dep| dep.is_a? Hash }.first

  # Get dockerfile if given
  dockerfile = config.fetch(:dockerfile, nil)

  # Raise error if :dockerfile value is nil
  unless dockerfile
    message = I18n.t('errors.docker_build.no_dockerfile_provided')
    raise message
  end

  # Get context if given
  context = config.fetch(:context, File.dirname(dockerfile))

  # Select the host
  host = config.fetch(:host, nil)

  # Select provided dependencies
  prerequisites = args[name].select { |d| ! d.is_a? Hash }

  # Merge prerequisites with the Dockerfile file_task
  prerequisites = prerequisites.push(dockerfile) unless dockerfile.nil?
  prerequisites.flatten!

  instance = Panoramix::Plugin::DockerBuild.new(name, dockerfile, context, host)

  descriptions = I18n.t('docker_build')
  descriptions = Hash.new if descriptions.class != Hash

  Panoramix.define_tasks(name,descriptions, instance, prerequisites, block)
end
docker_image(args, block=nil) click to toggle source
# File lib/panoramix/plugin/docker_build.rb, line 40
def docker_image(args, block=nil)
  puts "Warning using obsolete docker_image
    \t => #{"docker_image".bold} <image_name> => {dockerfile: <path_dockerfile>}.\n\tchange to:
    \t => #{"docker_build".bold} <image_name> => {dockerfile: <path_dockerfile>}".red
  docker_build(args, block)
end
docker_up(args, &block) click to toggle source
# File lib/panoramix/plugin/docker_up.rb, line 136
def docker_up(args, &block)
        name = args.keys[0]

        deps = args[name]

        compose_params = deps.select { |d| d.is_a? Hash }

        # Get docker-compose file path
        compose = compose_params.first[:compose]

        # Raise error if :compose value is nil
        unless compose
                message = I18n.t('errors.docker_up.no_compose_provided')
                raise(Panoramix::Plugin::DockerUpExceptionError, message)
        end

        # Get flags
        flags = {}

        # Get environment
        environment = parse_env(compose_params.first[:env] || [])

         # Select the host
  host = compose_params[0].fetch(:host, nil)

        # Merge deps with the compose file_task
        prerequisites = deps.select { |d| ! d.is_a? Hash }
        prerequisites = prerequisites.push(compose)

        instance = Panoramix::Plugin::DockerUp.new(name, compose, environment, host)

        descriptions = I18n.t('docker_up')
        descriptions = Hash.new if descriptions.class != Hash

        Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
end
env(args, &block) click to toggle source
# File lib/panoramix/plugin/env.rb, line 48
def env(args, &block)
  name = ""

  deps = []
  # case env "URL"
  if (args.class == String) 
    name = args
    vars = [name]
  else  # case env "some_var" => [{:vars => [......]}]
    name = args.keys[0]
    
    deps = args[name]
    env_options = deps.select { |d| d.is_a? Hash }
    # Get variables array
    vars = env_options.empty? ? nil : env_options.first[:vars]
  end

  descriptions = I18n.t('env')
  descriptions = Hash.new if descriptions.class != Hash

  # Merge deps
  prerequisites = deps.select { |d| ! d.is_a? Hash }

  instance = Panoramix::Plugin::Environment.new(name, vars)

  Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
end
external(dep, &block) click to toggle source
# File lib/panoramix/external.rb, line 7
def external(dep, &block)
  # Provided value can be either array or hash, so we need to make sure the final value is an array
  value = [dep.values[0]].flatten

  # Select the hash with params
  params = value.select { |d| d.is_a? Hash }.first

  # Handle with MPI
  handled_dep = Panoramix::MPI.handle_external(dep.keys[0], params)

  raise "Only a single external dependency supported (received: #{dep.keys})" if handled_dep.length != 1

  # Select provided dependencies
  prerequisites = value.select { |d| ! d.is_a? Hash }

  case handled_dep.values[0].keys[0]
  when :s3
    s3(handled_dep, prerequisites, block)
  when :wget
    wget(handled_dep, prerequisites, block)
  when :git
    git(handled_dep, prerequisites, block)
  when :dockerimage
    external_docker_image(handled_dep, block)
  when :docker
    puts "Warning using obsolete external dependency key
      \t => external <image_name> {#{"docker".bold}: <docker_image_name> }.\n\tchange to:
      \t => external <image_name> {#{"dockerimage".bold}: <docker_image_name> }.".red
    external_docker_image(handled_dep, block)
  else
    raise "Unknown external protocol '#{dep.values[0].keys[0]}'"
  end
end
external_docker_image(args, block) click to toggle source
# File lib/panoramix/plugin/docker_image.rb, line 45
def external_docker_image(args, block)
        name = args.keys[0]
        src = args[name][:dockerimage] || args[name][:docker]

        host = args[name][:host] || nil

        prerequisites = []

        instance = Panoramix::Plugin::DockerImage.new(name, src, host)

        descriptions = I18n.t('docker_image')
        descriptions = Hash.new if descriptions.class != Hash

        Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
end
git(args, prerequisites, block=nil) click to toggle source
# File lib/panoramix/plugin/git.rb, line 81
def git(args, prerequisites, block=nil)
        # Name of the task
        name = args.keys[0]
        # Get :git value from arguments
        src = args.values[0][:git]
        # Get :tag value from arguments
        tag = args.values[0][:tag]

        # Generate a new instance using the provided arguments
        instance = Panoramix::Plugin::Git.new(name, src, tag)

        descriptions = I18n.t('git')
        descriptions = Hash.new if descriptions.class != Hash

        # Define git instance tasks
        Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
end
parse_env(environment) click to toggle source
# File lib/panoramix/plugin/docker_up.rb, line 126
def parse_env environment
  res=Hash.new

  environment.each do |var|
    res[var]=ENV[var]
  end

  res
end
s3(args, prerequisites, block=nil) click to toggle source
# File lib/panoramix/plugin/s3.rb, line 56
def s3(args, prerequisites, block=nil)
        # Task name
        name = args.keys[0]
        # Artifacts url
        src = args.values[0][:s3]
        # Provided flags
        flags = args.values[0][:flags]

        instance=Panoramix::Plugin::S3.new(name, src, flags)

        descriptions = I18n.t('s3')
        descriptions = Hash.new if descriptions.class != Hash

        Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
end
wget(args, prerequisites, block=nil) click to toggle source
# File lib/panoramix/plugin/wget.rb, line 51
def wget(args, prerequisites, block=nil)
        # Task name
        name = args.keys[0]
        # Artifacts url
        src = args.values[0][:wget]
        # Provided flags
        flags = args.values[0][:flags]

        instance=Panoramix::Plugin::Wget.new(name, src, flags)

        descriptions = I18n.t('wget')
        descriptions = Hash.new if descriptions.class != Hash

        Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
end