Sha256: 10df710f7aa524543289e3a341194ded6fde3287948ba89668094f0ecf5c4c2b

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module Catfish
  class CLI::Provision
    attr_reader :options

    def initialize(options)
      @options = options
    end

    def run
      p 'Provisioning to servers using Catfishfile.lock'
      vagrant_version
      vagrant_plugins
      begin
        # Connect to the servers. The --provider=managed is the key here.
        system("vagrant up --provider=#{options[:provider]}")

        # Confirm the connectivity
        status = `vagrant status --machine-readable`
        if status.include? 'not reachable'
          abort 'ERROR DEPLOYING: One or more servers could not be connected to'
        end

        provision

      ensure

        # Disconnect from all of the servers
        system 'vagrant destroy -f'

      end
    end

    private

    def vagrant_version
      vagrant_version = 'Vagrant 1.6'
      fail "#{vagrant_version} or greater is a prerequisite" unless `vagrant --version`.include? vagrant_version
    end

    def vagrant_plugins
      # Make sure that the vagrant-managed-servers plugin is installed
      plugins = ['vagrant-managed-servers']
      plugins.each do |plugin|
        system("vagrant plugin install #{plugin}") unless `vagrant plugin list`.include? plugin
      end
    end

    def provision
      if options[:parallel]
        machines = status.split("\n").collect do |line|
          line.split(',')[1]
        end
        threads = []
        machines.uniq!.each do |machine|
          threads << Thread.new do
            system "vagrant provision #{machine}"
          end
        end

        threads.each(&:join)
      else
        system 'vagrant provision'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
catfish-0.0.3 lib/catfish/cli/provision.rb
catfish-0.0.2 lib/catfish/cli/provision.rb