Class: Fanforce::Factory
- Inherits:
-
Object
- Object
- Fanforce::Factory
- Includes:
- Utils
- Defined in:
- lib/fanforce/factory/version.rb,
lib/fanforce/factory/commands.rb,
lib/fanforce/factory/commands_support.rb,
lib/fanforce/factory/_base.rb
Defined Under Namespace
Modules: DeveloperConfig, Help, Run, Utils Classes: Addon, Addons, Env, Files
Constant Summary collapse
- VERSION =
'0.7.1'
Instance Method Summary collapse
- #auth_heroku(environment) ⇒ Object
- #capture_stdout ⇒ Object
- #convert_hash_to_ruby_env(hash) ⇒ Object
- #convert_hash_to_shell_env(hash) ⇒ Object
- #count ⇒ Object
- #create_addon(addon_type, addon_id, plugin_type = nil) ⇒ Object
- #delete_addon(addon_type, addon_id) ⇒ Object
- #delete_all_iron_workers(environment) ⇒ Object
- #destroy_counter(counter_id) ⇒ Object
- #get_heroku_app_name(addon, environment) ⇒ Object
- #get_heroku_app_qa_name(addon, environment) ⇒ Object
- #incr_counter(counter_id) ⇒ Object
- #init_counter(counter_id) ⇒ Object
-
#initialize(executable) ⇒ Factory
constructor
A new instance of Factory.
- #parse_addons_filter ⇒ Object
- #parse_command ⇒ Object
- #postprocess_git_overview ⇒ Object
- #preprocess_git_overview ⇒ Object
- #push_env_to(environment, addon, vars, create_worker_env = true) ⇒ Object
- #remove_single_worker(code_name, iron_worker, environment) ⇒ Object
- #restart(addon, environment) ⇒ Object
- #run(method, *args) ⇒ Object
- #run_bundle(addon_dir, processed_count, total_count, arg, extra_args) ⇒ Object
- #run_cleanorgs(addon_dir, processed_count, total_count, environment, supercore_api_key) ⇒ Object
- #run_forked(method, *args) ⇒ Object
- #run_git(addon_dir, processed_count, total_count, extra_args) ⇒ Object
- #run_git_overview(addon_dir, processed_count, total_count, length) ⇒ Object
- #run_iron(addon_dir, processed_count, total_count, command, environment) ⇒ Object
- #run_multiple(method, *args) ⇒ Object
- #run_push(addon_dir, processed_count, total_count, environment, command, subcommand) ⇒ Object
- #run_restart(addon_dir, processed_count, total_count, environment) ⇒ Object
- #run_setup(addon_dir, processed_count, total_count, scope, environment = :all) ⇒ Object
- #run_update(addon_dir, processed_count, total_count, scope, environment) ⇒ Object
- #run_upgrade(addon_dir, processed_count, total_count) ⇒ Object
- #setup_addon(addon_type, addon_id, plugin_type = nil) ⇒ Object
- #setup_bitbucket(addon) ⇒ Object
- #setup_config ⇒ Object
- #setup_envs(addon, environment) ⇒ Object
- #setup_files(addon) ⇒ Object
- #setup_heroku(addon, environment) ⇒ Object
- #setup_pow(addon) ⇒ Object
- #start(options) ⇒ Object
- #upload_iron(addon, command, environments) ⇒ Object
- #upload_iron_worker(addon, iron_worker, code, filename, environment) ⇒ Object
Methods included from Utils
#confirm, #error, #format, #format_config, #unknown
Constructor Details
#initialize(executable) ⇒ Factory
Returns a new instance of Factory.
15 16 17 18 |
# File 'lib/fanforce/factory/_base.rb', line 15 def initialize(executable) @executable = executable $HomeDir = Shell.new.pwd end |
Instance Method Details
#auth_heroku(environment) ⇒ Object
100 101 102 103 |
# File 'lib/fanforce/factory/commands_support.rb', line 100 def auth_heroku(environment) @heroku ||= {} @heroku[environment] ||= Heroku::API.new(:username => $Config[:heroku][environment][:user], :password => $Config[:heroku][environment][:password]) end |
#capture_stdout ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/fanforce/factory/_base.rb', line 276 def capture_stdout previous_stdout, previous_stderr = $stdout, $stderr io = StringIO.new $stdout = io $stderr = io IronCore::Logger.logger = ::Logger.new(io) IronCore::Logger.logger.level = ::Logger::INFO yield io.string ensure $stdout = previous_stdout $stderr = previous_stderr end |
#convert_hash_to_ruby_env(hash) ⇒ Object
181 182 183 |
# File 'lib/fanforce/factory/commands_support.rb', line 181 def convert_hash_to_ruby_env(hash) hash.inject('') {|script, (k,v)| script += "ENV['#{k}']=#{v.to_s.to_json}\n" } end |
#convert_hash_to_shell_env(hash) ⇒ Object
177 178 179 |
# File 'lib/fanforce/factory/commands_support.rb', line 177 def convert_hash_to_shell_env(hash) hash.inject('') {|script, (k,v)| script += "export #{k}=#{v.to_s.to_json}\n" } end |
#count ⇒ Object
319 320 321 322 323 324 |
# File 'lib/fanforce/factory/commands.rb', line 319 def count puts '---------------------------------------------------------------------------------------------------------------' puts "#{Addons.count} #{(($Filter.blank? or $Filter[:type].blank?) ? 'addons' : $Filter[:type]).to_s.pluralize}".format(:bold,:green) + ' were found in this directory.' puts '---------------------------------------------------------------------------------------------------------------' puts '' end |
#create_addon(addon_type, addon_id, plugin_type = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fanforce/factory/commands.rb', line 4 def create_addon(addon_type, addon_id, plugin_type=nil) dir_name = "#{addon_type}-#{addon_id}" dir = "#{$HomeDir}/#{dir_name}" if File.exists?("#{dir}/config.ru") puts '---------------------------------------------------------------------------------------------------------------' puts 'ERROR... '.format(:red,:bold) + "#{addon_type}-#{addon_id} already exists. You should run: ".format(:red) + "factory setup #{dir_name}".format(:green) puts '---------------------------------------------------------------------------------------------------------------' return end puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING FILES...' Dir.mkdir(dir) if !File.directory?(dir) Dir.chdir(dir) puts "#{'Created'.format(:bold, :green)} #{dir_name}/" addon = Addon.load(dir, plugin_type) setup_files(addon) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'RUNNING BUNDLER...' Run.bundle_install(addon.dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING POW DOMAINS...' setup_pow(addon) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING LOCAL GIT REPOSITORY...' Run.git_init and puts '- git init' Run.git_add and puts '- git add .' Run.git_first_commit and puts '- git commit -m "initial factory commit"' puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING BITBUCKET REPOSITORY...' setup_bitbucket addon puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING HEROKU APPS...' setup_heroku addon, :staging setup_heroku addon, :production puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING ENV VARIABLES...' setup_envs(addon, :all) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{'DONE!'.format(:bold,:green)} Paste the following JSON into your Developer Configuration for #{addon._id.format(:bold)}:" puts '---------------------------------------------------------------------------------------------------------------' puts DeveloperConfig.method(addon.type).call(addon).format(:magenta) puts '---------------------------------------------------------------------------------------------------------------' puts "\n" end |
#delete_addon(addon_type, addon_id) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/fanforce/factory/commands.rb', line 114 def delete_addon(addon_type, addon_id) dir_name = "#{addon_type}-#{addon_id}" dir = "#{$HomeDir}/#{dir_name}" if !File.directory?("#{dir}") puts '---------------------------------------------------------------------------------------------------------------' puts 'OOPS... '.format(:red,:bold) + "#{addon_type}-#{addon_id} does not exist and therefore cannot be deleted!" puts '---------------------------------------------------------------------------------------------------------------' return end addon = Addon.load(dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DELETING HEROKU APPS...' [:staging,:production].each do |environment| next if $Config[:heroku].blank? or $Config[:heroku][environment].blank? heroku = auth_heroku(environment) heroku_app_name = get_heroku_app_name(addon, environment) #begin heroku.delete_app(heroku_app_name) puts "#{'Removed '.format(:green,:bold)}" + " #{heroku_app_name}" #rescue # puts "#{'Already Removed'.format(:green,:bold)}" + " #{heroku_app_name}" #end end puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DELETING BITBUCKET REPOSITORY...' if $Config[:bitbucket].present? bitbucket = BitBucket.new(login: $Config[:bitbucket][:user], password: $Config[:bitbucket][:password]) begin repo = bitbucket.repos.find($Config[:bitbucket][:user], addon.dir_name) RestClient.delete("https://#{$Config[:bitbucket][:user]}:#{$Config[:bitbucket][:password]}@api.bitbucket.org/1.0/repositories/#{$Config[:bitbucket][:user]}/#{addon.dir_name}") puts "#{'Removed'.format(:green,:bold)}" + " #{addon.dir_name}" rescue puts "#{'Already Removed'.format(:green,:bold)}" + " #{addon.dir_name}" end end puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DELETING POW DOMAINS...' Run.pow_destroy(addon, addon.root_domain) Run.pow_destroy(addon, $SMARTURL_DOMAIN) if addon.plugin_type == :behavior puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DELETING FILES...' if File.directory?(dir) FileUtils.rm_rf(dir) puts "#{'Removed'.format(:bold, :green)} #{dir_name}/" else puts "#{'Already Removed'.format(:bold, :green)} #{dir_name}/" end puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DONE! (note: iron workers were not deleted' puts '---------------------------------------------------------------------------------------------------------------' end |
#delete_all_iron_workers(environment) ⇒ Object
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/fanforce/factory/commands.rb', line 528 def delete_all_iron_workers(environment) puts '' environments = environment == :all ? [:development, :staging, :production] : [environment] iron_auths = {} Addons.each do |addon, cur_count, total| environments.each do |environment| vars = Env.vars_by_addon(environment)[addon.dir_name] iron_auths[environment] ||= {} iron_auths[environment][vars['IRON_PROJECT_ID']] = vars['IRON_TOKEN'] if vars['IRON_PROJECT_ID'].present? end end environments.each do |environment| puts '---------------------------------------------------------------------------------------------------------------' puts "REMOVING WORKERS IN #{environment.to_s.upcase}..." workers_found = false iron_auths[environment].each do |iron_project_id, iron_token| iron_worker = IronWorkerNG::Client.new(:token => iron_token, :project_id => iron_project_id) iron_worker.codes.list.each do |code| workers_found = true iron_worker.codes.delete(code.id) puts "#{'Removed'.format(:red,:bold)} #{code.name}" end end puts 'No workers were found' if !workers_found end puts '---------------------------------------------------------------------------------------------------------------' end |
#destroy_counter(counter_id) ⇒ Object
307 308 309 |
# File 'lib/fanforce/factory/_base.rb', line 307 def destroy_counter(counter_id) File.delete("#{$HomeDir}/.forked-counter-#{counter_id}") end |
#get_heroku_app_name(addon, environment) ⇒ Object
3 4 5 6 |
# File 'lib/fanforce/factory/commands_support.rb', line 3 def get_heroku_app_name(addon, environment) heroku_app_name = "#{environment==:production ? 'prd' : 'stg'}-#{addon.dir_name}" heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name end |
#get_heroku_app_qa_name(addon, environment) ⇒ Object
561 562 563 564 |
# File 'lib/fanforce/factory/commands.rb', line 561 def get_heroku_app_qa_name(addon, environment) heroku_app_name = "#{environment==:production ? 'prd' : 'qa'}-#{addon.dir_name}" heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name end |
#incr_counter(counter_id) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/fanforce/factory/_base.rb', line 294 def incr_counter(counter_id) new_count = nil File.open("#{$HomeDir}/.forked-counter-#{counter_id}", File::RDWR|File::CREAT, 0644) do |f| f.flock(File::LOCK_EX) new_count = f.read.to_i + 1 f.rewind f.write("#{new_count}\n") f.flush f.truncate(f.pos) end new_count end |
#init_counter(counter_id) ⇒ Object
290 291 292 |
# File 'lib/fanforce/factory/_base.rb', line 290 def init_counter(counter_id) File.open("#{$HomeDir}/.forked-counter-#{counter_id}", 'w') {|f| f.write('0') } end |
#parse_addons_filter ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fanforce/factory/_base.rb', line 35 def parse_addons_filter if ARGV[0] =~ /^:(apps?|widgets?|plugins?)(:(data_connectors?|data_processors?|broadcasters?|identifiers?|behaviors?))?$/ $Filter = {type: $1.singularize.to_sym} $Filter[:plugin_type] = $3.singularize.to_sym if $3.present? and $Filter[:type] == :plugin ARGV.shift elsif ARGV[0] =~ /^:((app|widget|plugin)-(.+))$/ $Filter = {dir_name: $1} ARGV.shift end end |
#parse_command ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/fanforce/factory/_base.rb', line 48 def parse_command ################################################################# if ARGV.length == 0 or !@allowed_commands.include?(ARGV[0].to_sym) puts Fanforce::Factory::Help.intro(@executable, @runtype) puts Fanforce::Factory::Help.commands(@allowed_commands) ################################################################# elsif ARGV[0] == 'create' ARGV[1] =~ /^(plugin|widget|app)-(.+)$/ || error('You supplied an invalid create command.', :create) addon_type = $1 addon_id = $2 if addon_type =~ /app|widget/ create_addon(addon_type, addon_id) else if ARGV[2].nil? error('You failed to supply a valid plugin type for create.', :create) elsif ![:data_connector, :data_processor, :broadcaster, :identifier, :behavior].include?(ARGV[2].to_sym) error('You supplied an invalid plugin type.', :create) else create_addon(addon_type, addon_id, ARGV[2]) end end ################################################################# elsif ARGV[0] == 'setup' ARGV[1] =~ /^(plugin|widget|app)-(.+)$/ || error('You supplied an invalid setup command.', :setup) addon_type = $1 addon_id = $2 if addon_type =~ /app|widget/ setup_addon(addon_type, addon_id) else if ARGV[2].nil? error('You failed to supply a valid plugin type for setup.', :setup) elsif ![:data_connector, :data_processor, :broadcaster, :identifier, :behavior].include?(ARGV[2].to_sym) error('You supplied an invalid plugin type.', :setup) else setup_addon(addon_type, addon_id, ARGV[2]) end end ################################################################# elsif ARGV[0] == 'delete' ARGV[1] =~ /^(plugin|widget|app)-(.+)$/ || error('You supplied an invalid delete command.', :delete) confirm("Are you sure you want to delete all files, repositories, and other items for #{ARGV[1]}?") delete_addon($1, $2) ################################################################# elsif ARGV[0] == 'update' ARGV[1] =~ /^(all|files?|envs?(:all|:development|:staging|:production)?|pows?|bitbuckets?|herokus?(:all|:staging|:production)?)$/ || error('You supplied an invalid update command.', :update) tmp_str = $1 if tmp_str =~ /^envs?|herokus?/ command, environment = tmp_str.split(':').map {|d| d.singularize.to_sym } environment = :all if !environment confirm('Are you sure you want to setup all environments?') if environment == :all else command = tmp_str.singularize.to_sym environment = command == :all ? :all : nil end confirm('Are you sure you want to setup everything in all environments?') if command == :all run(:update, command, environment) ################################################################# elsif ARGV[0] == 'restart' if ARGV[1].present? ARGV[1] =~ /^(development|staging|production|all)?$/ || error('You supplied an invalid restart command.', :restart) environment = $1.to_sym else environment = :development end confirm('Are you sure you want to restart all environments?') if environment == :all run(:restart, environment) ################################################################# elsif ARGV[0] == 'push' ARGV[1] =~ /^(development|staging|production)(:all|:heroku|:irons?(:upload|:nuclear)?|bitbuckets?)?$/ || error('You supplied an invalid push command.', :push) environment = $1.to_sym tmp_str = $2 || 'all' if tmp_str =~ /^irons?/ command, subcommand = tmp_str.split(':').map {|d| d.singularize.to_sym } subcommand = :upload if !subcommand else command = tmp_str.gsub(':','').singularize.to_sym subcommand = nil end confirm("Are you sure you want to push to all services on #{environment}") if command == :all run(:push, environment, command, subcommand) ################################################################# elsif ARGV[0] == 'count' count ################################################################# elsif ARGV[0] == 'bundle' ARGV[1] =~ /^(install|update)$/ || error('You supplied an invalid bundle command.', :bundle) run(:bundle, $1.to_sym, ARGV[3..-1] || []) ################################################################# elsif ARGV[0] == 'git' and ARGV[1] == 'status:overview' run(:git_overview) elsif ARGV[0] == 'git' run(:git, ARGV[1..-1] || []) ################################################################# elsif ARGV[0] == 'iron' ARGV[1] =~ /^(upload|reset|delete)(:all|:development|:staging|:production)?$/ || error('You supplied an invalid iron command.', :iron) command = $1.to_sym environment = ($2.present?) ? $2.gsub(':','').to_sym : :all confirm("Are you sure you want to #{command} workers in all environments?") if environment == :all if command == :delete delete_all_iron_workers(environment) else run(:iron, command, environment) end ################################################################# elsif ARGV[0] == 'cleanorgs' ARGV[1] =~ /^(development|staging|production)$/ || error('You supplied an invalid cleanorgs command.', :cleanorgs) environment = $1.to_sym supercore_api_key = ARGV[2] || error('You supplied an invalid cleanorgs command.', :cleanorgs) run(:cleanorgs, environment, supercore_api_key) ################################################################# elsif ARGV[0] == 'version' puts '---------------------------------------------------------------------------------------------------------------' puts "You are using version #{Fanforce::Factory::VERSION} of Fanforce Factory " puts '---------------------------------------------------------------------------------------------------------------' elsif ARGV[0] == 'config' puts '---------------------------------------------------------------------------------------------------------------' if !File.exists?("#{$HomeDir}/.factoryconfig") puts 'Oops'.format(:red,:bold) + '... no ".factoryconfig" file was found in this directory.'.format(:red) else puts $Config end puts '---------------------------------------------------------------------------------------------------------------' elsif ARGV[0] == 'upgrade' run(:upgrade) end end |
#postprocess_git_overview ⇒ Object
430 431 432 433 |
# File 'lib/fanforce/factory/commands.rb', line 430 def postprocess_git_overview puts '------------------------------------------------------------------------' puts 'DONE' end |
#preprocess_git_overview ⇒ Object
423 424 425 426 427 428 |
# File 'lib/fanforce/factory/commands.rb', line 423 def preprocess_git_overview puts '' length = Addons.dir_names.inject(0) {|length, dir_name| dir_name.length > length ? dir_name.length : length } puts sprintf("%-#{length+3}s %-20s %s", 'Directory', 'Plugin Type', 'Status').format(:bold) length end |
#push_env_to(environment, addon, vars, create_worker_env = true) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/fanforce/factory/commands_support.rb', line 160 def push_env_to(environment, addon, vars, create_worker_env=true) File.delete("#{addon.dir}/workers/.#{addon.type}env.rb") if File.exists?("#{addon.dir}/workers/.#{addon.type}env.rb") File.delete("#{addon.dir}/workers/.prebuildgems") if File.exists?("#{addon.dir}/workers/.prebuildgems") vars.each {|k,v| puts " - #{k}" } File.open("#{addon.dir}/workers/.#{environment}env.rb", 'w') {|f| f.write convert_hash_to_ruby_env(vars) } if create_worker_env and File.directory?("#{addon.dir}/workers") and vars['IRON_PROJECT_ID'] if environment == :development addon.update_file(:powenv) File.open("#{addon.dir}/.#{addon.type}env", 'w') {|f| f.write convert_hash_to_shell_env(vars) } else return if $Config[:heroku][environment].blank? heroku = auth_heroku(environment) heroku_app_name = get_heroku_app_name(addon, environment) heroku.put_config_vars(heroku_app_name, vars) end restart(addon, environment) end |
#remove_single_worker(code_name, iron_worker, environment) ⇒ Object
517 518 519 520 521 522 523 524 |
# File 'lib/fanforce/factory/commands.rb', line 517 def remove_single_worker(code_name, iron_worker, environment) iron_worker.codes.list.each do |code| next if code.name != code_name iron_worker.codes.delete(code.id) puts "#{'Removing '.format(:green,:bold)} #{code_name} from #{environment.to_s.titleize}..." return true end end |
#restart(addon, environment) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/fanforce/factory/commands.rb', line 344 def restart(addon, environment) if environment == :development File.mkdir("#{addon.dir}/tmp") if !File.directory?("#{addon.dir}/tmp") FileUtils.touch("#{addon.dir}/tmp/restart.txt") elsif [:production, :staging].include?(environment) if $Config[:heroku].blank? or $Config[:heroku][environment].blank? puts "#{'OOPS...'.format(:red,:bold)} #{environment} has not been setup on heroku" return false end heroku = auth_heroku(environment) heroku.post_ps_restart get_heroku_app_name(addon, environment) end return true end |
#run(method, *args) ⇒ Object
224 225 226 |
# File 'lib/fanforce/factory/_base.rb', line 224 def run(method, *args) (@runtype == :forked) ? run_forked(method, *args) : run_multiple(method, *args) end |
#run_bundle(addon_dir, processed_count, total_count, arg, extra_args) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/fanforce/factory/commands.rb', line 361 def run_bundle(addon_dir, processed_count, total_count, arg, extra_args) addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " Dir.chdir(addon_dir) do if Gem::Specification::find_all_by_name('bundler').empty? puts 'Installing Bundler... ' `gem install bundler` puts 'DONE' end addon.update_file(:gemfile) Run.command("bundle #{arg} #{extra_args.join(' ')}") restart(addon, :development) puts 'DONE'.format(:green) end end |
#run_cleanorgs(addon_dir, processed_count, total_count, environment, supercore_api_key) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/fanforce/factory/commands.rb', line 382 def run_cleanorgs(addon_dir, processed_count, total_count, environment, supercore_api_key) ENV['RACK_ENV'] = environment.to_s addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " require 'redis' require 'fanforce/api' ff = Fanforce::API.new(supercore_api_key) Dir.chdir(addon_dir) do addon = Addon.load(addon_dir) vars = Env.vars_by_addon(environment)[addon.dir_name] || {} redis = Redis.new(url: vars['REDIS_URL']) installs = redis.keys("installed:#{addon.dir_name}:*") organizations = {} redis.multi do organizations = installs.inject({}) do |result, key| next result if key !~ /^(installed:#{addon.dir_name}:(.+))$/ result.update $2 => redis.get($1) end end puts "#{organizations.size} installs found..." processed_count = 0 organizations.each do |organization_id, api_key| print "- checking organization #{processed_count+=1}... " if ff.get("/organizations/#{organization_id}", fields: '_id') puts 'VALID' else print 'INVALID... ' redis.del("installed:#{addon.dir_name}:#{organization_id}") puts 'UNINSTALLED' end end end end |
#run_forked(method, *args) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/fanforce/factory/_base.rb', line 251 def run_forked(method, *args) counter_id = Process.pid processes = [] dirs = Addons.dirs puts "\n---------------------------------------------------------------------------------------------------------------" dirs.each_with_index do |addon_dir, i| puts "#{'Forking'.format(:white,:bold)} #{addon_dir}" end dirs.each_with_index do |addon_dir, i| processes << fork do response = capture_stdout do self.method(:"run_#{method}").call(addon_dir, 'PROCESSED_ADDONS_COUNT', dirs.size, *args) end puts response.gsub('PROCESSED_ADDONS_COUNT', incr_counter(counter_id).to_s) end sleep(0.25) end processes.each { |pid| Process.waitpid(pid) } puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DONE!' puts '---------------------------------------------------------------------------------------------------------------' end |
#run_git(addon_dir, processed_count, total_count, extra_args) ⇒ Object
444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/fanforce/factory/commands.rb', line 444 def run_git(addon_dir, processed_count, total_count, extra_args) addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " extra_args = extra_args.map {|c| c.include?(' ') ? c.to_json : c }.join(' ') extra_args = '--no-pager ' + extra_args if extra_args !~ /--no-pager/ Dir.chdir(addon_dir) do Run.command("git #{extra_args}") puts 'DONE'.format(:green) end end |
#run_git_overview(addon_dir, processed_count, total_count, length) ⇒ Object
435 436 437 438 439 440 441 442 |
# File 'lib/fanforce/factory/commands.rb', line 435 def run_git_overview(addon_dir, processed_count, total_count, length) addon = Addon.load(addon_dir) puts '------------------------------------------------------------------------' Dir.chdir(addon_dir) do committed = `git status`.include?('nothing to commit') ? true : false printf "%-#{length+3}s %-20s %s\n", addon.dir_name, addon.type==:plugin ? addon.plugin_type : 'n/a', committed ? 'Committed'.format(:green) : 'Uncommitted'.format(:red) end end |
#run_iron(addon_dir, processed_count, total_count, command, environment) ⇒ Object
460 461 462 463 464 465 466 467 |
# File 'lib/fanforce/factory/commands.rb', line 460 def run_iron(addon_dir, processed_count, total_count, command, environment) environments = environment == :all ? [:development, :staging, :production] : [environment] addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " upload_iron(addon, command, environments) end |
#run_multiple(method, *args) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/fanforce/factory/_base.rb', line 228 def run_multiple(method, *args) if (dirs = Addons.dirs).size == 0 puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{'Oops'.format(:bold)}... no factory addons #{$Filter.length > 0 ? 'matching your filter was' : 'were'} found in this directory." puts "---------------------------------------------------------------------------------------------------------------\n" return end if self.respond_to?(:"preprocess_#{method}") args << self.method(:"preprocess_#{method}").call end Addons.each do |addon, processed_count, total_count| self.method(:"run_#{method}").call(addon.dir, processed_count, total_count, *args) end if self.respond_to?(:"postprocess_#{method}") self.method(:"postprocess_#{method}").call else puts "\n---------------------------------------------------------------------------------------------------------------" puts 'DONE!' puts '---------------------------------------------------------------------------------------------------------------' end end |
#run_push(addon_dir, processed_count, total_count, environment, command, subcommand) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/fanforce/factory/commands.rb', line 287 def run_push(addon_dir, processed_count, total_count, environment, command, subcommand) addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " Dir.chdir(addon_dir) do if [:all,:bitbucket].include?(command) and $Config[:bitbucket].present? puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Bitbucket (#{$Config[:bitbucket][:user]})..." Run.command("git push bitbucket --all") end if [:all,:heroku].include?(command) and environment != :development vars = Env.vars_by_addon(environment)[addon.dir_name] || {} puts "\n#{"Updating Env Vars".format(:green,:bold)} on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..." push_env_to(environment, addon, vars) remote_name = "#{environment==:staging ? 'stg' : 'prd'}-heroku" puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{remote_name})..." Run.command("git push #{remote_name} master") end if [:all,:iron].include?(command) puts '' upload_iron(addon, command, [environment]) end end end |
#run_restart(addon_dir, processed_count, total_count, environment) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/fanforce/factory/commands.rb', line 328 def run_restart(addon_dir, processed_count, total_count, environment) addon = Addon.load(addon_dir) puts "---------------------------------------------------------------------------------------------------------------" Dir.chdir(addon_dir) do if [:all, :development].include?(environment) puts "#{'DEVELOPMENT '.format(:bold)}#{addon.dir_name.format(:green)} restarted" if restart(addon, :development) end if [:all, :staging].include?(environment) puts "#{'STAGING '.format(:bold)}#{addon.dir_name.format(:green)} restarted" if restart(addon, :staging) end if [:all, :production].include?(environment) puts "#{'PRODUCTION '.format(:bold)}#{addon.dir_name.format(:green)} restarted" if restart(addon, :production) end end end |
#run_setup(addon_dir, processed_count, total_count, scope, environment = :all) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/fanforce/factory/commands.rb', line 176 def run_setup(addon_dir, processed_count, total_count, scope, environment=:all) addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " Dir.chdir(addon_dir) do if [:all, :file].include?(scope) puts '' puts 'SETTING UP FILES...' setup_files addon end if [:all, :pow].include?(scope) puts '' puts 'SETTING UP POW DOMAINS...' setup_pow addon end if [:all, :bitbucket, :heroku].include?(scope) puts '' print 'ENSURING LOCAL GIT REPOSITORY EXISTS... ' if `git status`.include?('Not a git repository') puts '' Run.git_init and puts '- git init' Run.git_add and puts '- git add .' Run.git_first_commit and puts '- git commit -m "initial factory commit"' puts '' else puts 'Found' end end if [:all, :bitbucket].include?(scope) puts '' puts 'SETTING UP BITBUCKET REPOSITORY...' setup_bitbucket addon end if [:all, :heroku].include?(scope) puts '' puts 'SETTING UP HEROKU APPS...' setup_heroku addon, :staging if [:all,:staging].include?(environment) setup_heroku addon, :production if [:all,:production].include?(environment) end if [:all, :env].include?(scope) puts '' puts 'SETTING UP ENV VARIABLES...' setup_envs addon, environment end end end |
#run_update(addon_dir, processed_count, total_count, scope, environment) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/fanforce/factory/commands.rb', line 232 def run_update(addon_dir, processed_count, total_count, scope, environment) addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " Dir.chdir(addon_dir) do if [:all, :file].include?(scope) puts '' puts 'UPDATING FILES...' setup_files addon end if [:all, :pow].include?(scope) puts '' puts 'UPDATING POW DOMAINS...' setup_pow addon end if [:all, :bitbucket, :heroku].include?(scope) puts '' print 'ENSURING LOCAL GIT REPOSITORY EXISTS... ' if `git status`.include?('Not a git repository') puts '' Run.git_init and puts '- git init' Run.git_add and puts '- git add .' Run.git_first_commit and puts '- git commit -m "initial factory commit"' puts '' else puts 'Found' end end if [:all, :bitbucket].include?(scope) puts '' puts 'UPDATING BITBUCKET REPOSITORY...' setup_bitbucket addon end if [:all, :heroku].include?(scope) puts '' puts 'UPDATING HEROKU APPS...' setup_heroku addon, :staging if [:all,:staging].include?(environment) setup_heroku addon, :production if [:all,:production].include?(environment) end if [:all, :env].include?(scope) puts '' puts 'UPDATING ENV VARIABLES...' setup_envs addon, environment end end end |
#run_upgrade(addon_dir, processed_count, total_count) ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/fanforce/factory/commands.rb', line 566 def run_upgrade(addon_dir, processed_count, total_count) environment = :qa addon = Addon.load(addon_dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " #heroku = auth_heroku(:staging) #heroku_app_name = get_heroku_app_qa_name(addon, environment) #begin # heroku.delete_app(heroku_app_name) # puts "#{'Deleted '.format(:green,:bold)}" + "#{environment} app on heroku (#{heroku_app_name})" #rescue # heroku.post_app(name: heroku_app_name) # puts "#{'Not Found '.format(:green,:bold)}" + "#{environment} on heroku (#{heroku_app_name})" #end if (`git remote`).split(/\r?\n/).include?($Config[:bitbucket][:user]) puts "#{'Removed '.format(:red,:bold)}" + "git remote for #{$Config[:bitbucket][:user]}" `git remote rm #{$Config[:bitbucket][:user]}` end if (`git remote`).split(/\r?\n/).include?('qa-heroku') puts "#{'Removed '.format(:red,:bold)}" + "git remote for qa-heroku" `git remote rm qa-heroku` end if (`git remote`).split(/\r?\n/).include?('bitbucket') puts "#{'Updated '.format(:green,:bold)}" + "git remote for bitbucket" `git remote rm bitbucket` `git remote add bitbucket [email protected]:#{$Config[:bitbucket][:user]}/#{addon.dir_name}.git` else `git remote add bitbucket [email protected]:#{$Config[:bitbucket][:user]}/#{addon.dir_name}.git` puts "#{'Created '.format(:green,:bold)}" + "git remote for bitbucket" end `git config --remove-section branch.master` `git push --set-upstream bitbucket master` end |
#setup_addon(addon_type, addon_id, plugin_type = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fanforce/factory/commands.rb', line 58 def setup_addon(addon_type, addon_id, plugin_type=nil) dir_name = "#{addon_type}-#{addon_id}" dir = "#{$HomeDir}/#{dir_name}" if !File.exists?("#{dir}/config.ru") puts '---------------------------------------------------------------------------------------------------------------' puts 'ERROR... '.format(:red,:bold) + "#{addon_type}-#{addon_id} does not exist. You should run: ".format(:red) + "factory create #{dir_name}".format(:green) puts '---------------------------------------------------------------------------------------------------------------' return end puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING FILES...' Dir.mkdir(dir) if !File.directory?(dir) Dir.chdir(dir) puts "#{'Created'.format(:bold, :green)} #{dir_name}/" addon = Addon.load(dir, plugin_type) setup_files(addon) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'RUNNING BUNDLER...' Run.bundle_install(addon.dir) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING POW DOMAINS...' setup_pow(addon) puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING LOCAL GIT REPOSITORY...' Run.git_init and puts '- git init' Run.git_add and puts '- git add .' Run.git_first_commit and puts '- git commit -m "initial factory commit"' puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING BITBUCKET REPOSITORY...' setup_bitbucket addon puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING HEROKU APPS...' setup_heroku addon, :staging setup_heroku addon, :production puts "\n---------------------------------------------------------------------------------------------------------------" puts 'CREATING ENV VARIABLES...' setup_envs(addon, :all) puts "\n---------------------------------------------------------------------------------------------------------------" puts "#{'DONE!'.format(:bold,:green)} Paste the following JSON into your Developer Configuration for #{addon._id.format(:bold)}:" puts '---------------------------------------------------------------------------------------------------------------' puts DeveloperConfig.method(addon.type).call(addon).format(:magenta) puts '---------------------------------------------------------------------------------------------------------------' puts "\n" end |
#setup_bitbucket(addon) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fanforce/factory/commands_support.rb', line 74 def setup_bitbucket(addon) bitbucket = BitBucket.new(login: $Config[:bitbucket][:user], password: $Config[:bitbucket][:password]) begin bitbucket.repos.find($Config[:bitbucket][:user], addon.dir_name) "#{'Found '.format(:green,:bold)}" + "#{addon.dir_name} repository already exists on bitbucket" rescue bitbucket.repos.create(name: addon.dir_name, is_private: true) puts "#{'Created '.format(:green,:bold)}" + "#{addon.dir_name} repository on bitbucket" end if (`git remote`).split(/\r?\n/).include?($Config[:bitbucket][:user]) puts "#{'Updated '.format(:green,:bold)}" + "git remote for #{$Config[:bitbucket][:user]}" `git remote rm #{$Config[:bitbucket][:user]}` elsif (`git remote`).split(/\r?\n/).include?('bitbucket') `git remote rm bitbucket` puts "#{'Removed '.format(:red,:bold)}" + "git remote for #{$Config[:bitbucket][:user]}" puts "#{'Created '.format(:green,:bold)}" + "git remote for bitbucket" else puts "#{'Created '.format(:green,:bold)}" + "git remote for bitbucket" end `git remote add bitbucket [email protected]:#{$Config[:bitbucket][:user]}/#{addon.dir_name}.git` puts "#{'Pushing '.format(:green,:bold)}" + "latest commit to #{$Config[:bitbucket][:user]}..." Run.command("git push bitbucket --all") end |
#setup_config ⇒ Object
30 31 32 33 |
# File 'lib/fanforce/factory/_base.rb', line 30 def setup_config puts 'ERROR: Fanforce Factory could not find the required config file.'.format(:red) if !File.exists?("#{$HomeDir}/.factoryconfig") $Config = format_config(YAML.load_file("#{$HomeDir}/.factoryconfig")) end |
#setup_envs(addon, environment) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fanforce/factory/commands_support.rb', line 51 def setup_envs(addon, environment) environments = environment == :all ? [:development, :staging, :production] : [environment] if !File.exists?("#{$HomeDir}/.env/_bind.yml") return puts "#{'Oops'.format(:bold)}... you must setup .env/_bind.yml before trying to update env variables." end environments.each do |environment| vars = Env.vars_by_addon(environment)[addon.dir_name] has_workers = File.directory?("#{addon.dir}/workers") ? true : false next puts "#{'Skipped'.format(:bold)} #{environment.to_s.titleize} has 0 env variables" if vars.blank? or vars.size == 0 puts "#{'Updated'.format(:green,:bold)} #{environment.to_s.titleize}#{has_workers ? '... and workers have' : ' has'} #{vars.size} env variables" push_env_to(environment, addon, vars) end end |
#setup_files(addon) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fanforce/factory/commands_support.rb', line 8 def setup_files(addon) if File.directory?("#{addon.dir}/tmp") puts "#{'Found '.format(:green,:bold)} #{addon.dir_name}/tmp/" else Dir.mkdir("#{addon.dir}/tmp") puts "#{'Created'.format(:green,:bold)} #{addon.dir_name}/tmp/" end if File.exists?("#{addon.dir}/config.ru") addon.update_file(:config_ru) puts "#{'Updated'.format(:green,:bold)} #{addon.dir_name}/config.ru" else addon.create_file(:config_ru) puts "#{'Created'.format(:green,:bold)} #{addon.dir_name}/config.ru" end if File.exists?("#{addon.dir}/.gitignore") addon.update_file(:gitignore) puts "#{'Updated'.format(:green,:bold)} #{addon.dir_name}/.gitignore" else addon.create_file(:gitignore) puts "#{'Created'.format(:green,:bold)} #{addon.dir_name}/.gitignore" end if File.exists?("#{addon.dir}/Gemfile") addon.update_file(:gemfile) puts "#{'Updated'.format(:green,:bold)} #{addon.dir_name}/Gemfile" else addon.create_file(:gemfile) puts "#{'Created'.format(:green,:bold)} #{addon.dir_name}/Gemfile" end if File.exists?("#{addon.dir}/Rakefile") addon.update_file(:rakefile) puts "#{'Updated'.format(:green,:bold)} #{addon.dir_name}/Rakefile" else addon.create_file(:rakefile) puts "#{'Created'.format(:green,:bold)} #{addon.dir_name}/Rakefile" end restart(addon, :development) end |
#setup_heroku(addon, environment) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/fanforce/factory/commands_support.rb', line 105 def setup_heroku(addon, environment) return puts "OOPS... #{environment.to_s.upcase}".format(:red,:bold) + ' has not been setup for Heroku' if $Config[:heroku].blank? or $Config[:heroku][environment].blank? heroku = auth_heroku(environment) heroku_app_name = get_heroku_app_name(addon, environment) begin heroku.get_app(heroku_app_name) puts "#{'Found '.format(:green,:bold)}" + "#{environment} app on heroku (#{heroku_app_name})" rescue heroku.post_app(name: heroku_app_name) puts "#{'Created '.format(:green,:bold)}" + "#{environment} on heroku (#{heroku_app_name})" end vars = Env.vars_by_addon(environment)[addon.dir_name] heroku.put_config_vars(heroku_app_name, vars) # Setup standard plugin domain if $Config[:heroku][environment][:"#{addon.type}_domain"] domain = "#{addon._id}.#{$Config[:heroku][environment][:"#{addon.type}_domain"]}" domain_found = heroku.get_domains(heroku_app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false } if domain_found puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}" else heroku.post_domain(heroku_app_name, domain) puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}" end end # Setup standard plugin domain if addon.type == :plugin and addon.plugin_type == :behavior and $Config[:heroku][environment][:smarturl_domain] domain = "#{addon._id}.#{$Config[:heroku][environment][:smarturl_domain]}" domain_found = heroku.get_domains(heroku_app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false } if domain_found puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}" else heroku.post_domain(heroku_app_name, domain) puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}" end end remote_name = "#{environment==:staging ? 'stg' : 'prd'}-heroku" if (`git remote`).split(/\r?\n/).include?(remote_name) puts "#{'Updated '.format(:green,:bold)}" + "git remote for #{remote_name}" `git remote rm #{remote_name}` else puts "#{'Created '.format(:green,:bold)}" + "git remote for #{remote_name}" end `git remote add #{remote_name} git@#{$Config[:heroku][environment][:git_ssh_domain] || 'heroku.com'}:#{heroku_app_name}.git` puts "#{'Pushing '.format(:green,:bold)}" + "latest commit to #{remote_name}..." Run.command("git push #{remote_name} master") end |
#setup_pow(addon) ⇒ Object
69 70 71 72 |
# File 'lib/fanforce/factory/commands_support.rb', line 69 def setup_pow(addon) Run.pow_create(addon, addon.root_domain) Run.pow_create(addon, $SMARTURL_DOMAIN) if addon.plugin_type == :behavior end |
#start(options) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/fanforce/factory/_base.rb', line 20 def start() @allowed_commands = [:allowed] @runtype = [:runtype] setup_config init_counter(Process.pid) if @runtype == :forked parse_addons_filter parse_command destroy_counter(Process.pid) if @runtype == :forked end |
#upload_iron(addon, command, environments) ⇒ Object
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/fanforce/factory/commands.rb', line 469 def upload_iron(addon, command, environments) if !File.directory?("#{addon.dir}/workers") return puts "#{'Skipped '.format(:bold)} no workers folder was found" end environments.each do |environment| vars = Env.vars_by_addon(environment)[addon.dir_name] || {} next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} is missing IRON_TOKEN and/or IRON_PROJECT_ID env variables" if vars['IRON_TOKEN'].blank? or vars['IRON_PROJECT_ID'].blank? puts "#{'Updating Env'.format(:green,:bold)} #{environment.to_s.titleize}... and workers have #{vars.size} env variables" push_env_to(environment, addon, vars, true) iron_worker = IronWorkerNG::Client.new(:token => vars['IRON_TOKEN'], :project_id => vars['IRON_PROJECT_ID']) Dir.chdir("#{addon.dir}/workers") do workers = Dir['*.worker'] next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} has 0 workers" if workers.size == 0 upload_processes = [] workers.each do |filename| code_name = "#{addon._id}-#{filename.gsub('.worker', '')}" remove_single_worker(code_name, iron_worker, environment) if command == :reset puts "#{'Uploading'.format(:green,:bold)} #{addon._id}-#{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..." code = IronWorkerNG::Code::Base.new(:workerfile => "#{addon.dir}/workers/#{filename}") code.remote code.name = code_name code.file("#{addon.dir}/workers/.#{environment}env.rb") upload_processes << upload_iron_worker(addon, iron_worker, code, filename, environment) end upload_processes.each { |pid| Process.waitpid(pid) } end end end |
#upload_iron_worker(addon, iron_worker, code, filename, environment) ⇒ Object
504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/fanforce/factory/commands.rb', line 504 def upload_iron_worker(addon, iron_worker, code, filename, environment) fork do begin iron_worker.codes.create(code, max_concurrency: 5) rescue Exception => e puts "#{'Aborted '.format(:red,:bold)} upload of #{addon._id}-#{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..." puts e. puts e.backtrace puts '' end end end |