Sha256: 21128acaad877d800d2cb64e98b5a0e9c882dc66d698c2de8decf012f38e5e50

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'thor'
require 'bundler'

module LLT
  class CLI < Thor
    include Thor::Actions

    BASE_DIR = File.expand_path('../../..', __FILE__)

    desc 'deploy', 'deploys llt as war after updating all llt gems'
    method_option :tomcat, aliases: '-t',
      desc: 'path to Tomcat directory to copy the war file to'
    method_option :restart_server, type: :boolean, aliases: '-r',
      desc: 'Works only when -t is given'
    method_option :seed, aliases: '-s',
     desc: 'Reseeds the prometheus stem database'
    def deploy
      inside BASE_DIR do
        update_gems(llt_gems)
        run_warbler
        deploy_to_tomcat(options)
        reseed_prometheus_stems(options)
      end
    end

    no_commands do
      def llt_gems
        File.read('Gemfile').each_line.with_object([]) do |line, arr|
          arr << $1 if line.match(/^gem '(llt-.*?)'/)
        end
      end

      def update_gems(gems)
        say_status('updating', '')
        gem_list = `gem list`
        to_update, to_install = gems.partition { |gem| gem_list.match(/#{gem}/)}
        system "gem install #{to_install.join(' ')}" if to_install.any?
        system "gem update #{to_update.join(' ')}"
      end

      def run_warbler
        say_status('warbling', '')
        Bundler.with_clean_env { system 'warble' }
      end

      def deploy_to_tomcat(options)
        if tomcat = options[:tomcat]
          app_dir = File.join(tomcat, 'webapps')
          say_status(:copying, "llt.war => #{app_dir}")
          system("cp llt.war #{app_dir}")
          restart(tomcat) if options[:restart_server]
        end
      end

      def restart(tomcat)
        bin_dir = File.join(tomcat, 'bin')
        say_status(:restarting, '')
        system("#{bin_dir}/shutdown.sh")
        system("#{bin_dir}/startup.sh")
      end

      def reseed_prometheus_stems(options)
        if options[:seed]
          say_status(:seeding, 'Prometheus stem database')
          system('rake db:prometheus:seed')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
llt-0.0.3 lib/llt/cli.rb