Sha256: 7be7b15e95d667d996f97da2b629b9b134efa86af87d15604a640c21874c0799

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

require 'larrow/runner/manifest/base_loader'
require 'larrow/runner/manifest/configuration'

module Larrow
  module Runner
    # support multiple manifest style, such as travis, larrow, etc...
    module Manifest
      # Adapters is a set of class to adapt different manifest style.
      # There isn't Adapter module, these classes are under Manifest module.
      autoload :Travis, 'larrow/runner/manifest/adapter/travis'
      autoload :Larrow, 'larrow/runner/manifest/adapter/larrow'
      autoload :Blank,  'larrow/runner/manifest/adapter/blank'

      extend self

      # options:
      #   :ignore_larrow : do not try to use larrow adapter
      #   :ignore_base_scripts : do not merge base scripts
      def configuration source_accessor, options={}
        adapters = [Travis, Blank]
        adapters.unshift Larrow unless options[:ignore_larrow]

        configuration = adapters.each do |clazz|
          c = clazz.new(source_accessor).load
          break c if c
        end
      
        unless options[:ignore_base_scripts]
          add_base_scripts(configuration, source_accessor)
        end
        configuration
      end

      def add_base_scripts configuration,source_accessor
        configuration.add_source_sync source_accessor
        unless configuration.image
          lines = <<-EOF
#{package_update}
#{bashrc_cleanup}
          EOF
          scripts = lines.split(/\n/).map{|s| Script.new s}
          configuration.insert_to_step :init, scripts
        end
      end

      def package_update
        <<-EOF
apt-get update -qq
apt-get install git libssl-dev build-essential curl libncurses5-dev -y -qq
        EOF
      end

      # remove PS1 check, for user to make ssh connection without tty
      def bashrc_cleanup
        "sed '/$PS1/ d' -i /root/.bashrc"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
larrow-runner-0.0.3 lib/larrow/runner/manifest.rb
larrow-runner-0.0.2 lib/larrow/runner/manifest.rb