fanforce-plugin-factory 2.0.0.rc19 → 2.0.0.rc21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 882b0203620df4c54e9f07980e911a3fd823e7c0
4
- data.tar.gz: d75fd3da8b48401e2fa36c0a564b435af1a0f28b
3
+ metadata.gz: b34938545968edb9683e0fe8a0497252ff80c6cd
4
+ data.tar.gz: 6e4f825d5557d6b8124f41d27cb985c155b10541
5
5
  SHA512:
6
- metadata.gz: 8fb5e7709dbe743fcad63b62b9d23abbf87114c5ff3e993f6c29a94546c691b56fcc1aa2954e9196717dcdedff5c5d71f105ae78beadf4fd4626216a07a10460
7
- data.tar.gz: ab2c1a06d059784b52be08db56ce3a61092ec9ccfb408bbd6d23f2e05b2c2fb21f3e83904cb2686f77c70e648fee576d15558a3ea1e2948d316ee05b0cf64aa9
6
+ metadata.gz: 6235a31d6069ffad1a0d675acef98d505bd1b43d211c7174bbc9418f211f03a4878c8781015172e8ae59d24e58cf2802ee4ae382c42bdd0b3c95880475d400c6
7
+ data.tar.gz: d054e133b6fc6ba3b5b8de51be7c6a9b1e3f74c37ead3bf7f80b8cfee050d99ca0c06b2979d4db385dfc6b4365c7db4112ccae624d5dd1823555913ae3b98029
@@ -39,7 +39,7 @@ Gem::Specification.new do |gem|
39
39
 
40
40
  gem.add_runtime_dependency 'fanforce-base', '>= 2.0.0.rc3'
41
41
  gem.add_runtime_dependency 'fanforce-api', '>= 2.0.0.rc5'
42
- gem.add_runtime_dependency 'fanforce-plugin-worker', '>= 2.0.0.rc11'
42
+ gem.add_runtime_dependency 'fanforce-plugin-worker', '>= 2.0.0.rc12'
43
43
 
44
44
  gem.add_development_dependency 'fanforce-test', '>= 2.0.0.rc3'
45
45
  end
@@ -15,7 +15,7 @@ class Fanforce::PluginFactory::CLI::Iron
15
15
  @workers_dir ||= "#{plugin.dir}/workers"
16
16
  end
17
17
 
18
- def upload(environment, worker_filename=nil)
18
+ def dockerize(environment, worker_filename=nil)
19
19
  return log "#{'Skipped '.format(:bold)} no workers folder was found" if !File.directory?(workers_dir)
20
20
 
21
21
  worker_filename = worker_filename.gsub('.worker', '') if worker_filename
@@ -29,14 +29,35 @@ class Fanforce::PluginFactory::CLI::Iron
29
29
  upload_processes = []
30
30
  workers.each do |filename|
31
31
  next if worker_filename and !filename.include?(worker_filename)
32
- zipped_filepath = compile_worker(filename, environment, env_vars)
32
+ dockerize_worker(filename, environment, env_vars)
33
+ end
34
+ end
35
+ end
36
+
37
+ def dockerize_and_upload(environment, worker_filename=nil)
38
+ return log "#{'Skipped '.format(:bold)} no workers folder was found" if !File.directory?(workers_dir)
39
+
40
+ worker_filename = worker_filename.gsub('.worker', '') if worker_filename
41
+ env_vars = Fanforce::PluginFactory::CLI::Env.new(plugin).vars(environment) || {}
42
+ return puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} is missing IRON_TOKEN and/or IRON_PROJECT_ID env variables" if env_vars['IRON_TOKEN'].blank? or env_vars['IRON_PROJECT_ID'].blank?
43
+
44
+ Dir.chdir(workers_dir) do
45
+ workers = Dir['*.rb']
46
+ return puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} has 0 workers" if workers.size == 0
47
+
48
+ upload_processes = []
49
+ workers.each do |filename|
50
+ next if worker_filename and !filename.include?(worker_filename)
51
+ zipped_filepath = dockerize_worker(filename, environment, env_vars)
33
52
  upload_processes << upload_worker(filename, environment, env_vars, zipped_filepath)
34
53
  end
35
54
  upload_processes.each { |pid| Process.waitpid(pid) }
36
55
  end
37
56
  end
38
57
 
39
- def compile_worker(filename, environment, env_vars)
58
+ ######################################################################################################################
59
+
60
+ def dockerize_worker(filename, environment, env_vars)
40
61
  puts "#{'Compiling'.format(:green,:bold)} #{filename.gsub('.rb', '')} to #{environment.to_s.titleize}..."
41
62
  code_name = filename.gsub('.rb', '')
42
63
 
@@ -87,7 +108,6 @@ class Fanforce::PluginFactory::CLI::Iron
87
108
  end
88
109
 
89
110
  # lib/
90
-
91
111
  if File.directory?("#{plugin.dir}/lib")
92
112
  puts "Copying /lib/ to #{dockerized_worker_dir_relative}/lib/"
93
113
  FileUtils.rm_r("#{dockerized_worker_dir}/lib") if File.directory?("#{dockerized_worker_dir}/lib")
@@ -105,15 +125,31 @@ class Fanforce::PluginFactory::CLI::Iron
105
125
  puts "Setting up ENV for #{environment.to_s.titleize} (#{env_vars.size} variables)"
106
126
  File.open("#{dockerized_worker_dir}/env.#{env(environment)}.rb", 'w') {|f| f.write Fanforce::PluginFactory::CLI::Env.convert_hash_to_ruby_env(env_vars) }
107
127
 
108
-
128
+ # Bundle
109
129
  puts "Dockerizing #{dockerized_worker_dir_relative}"
110
- console_command("docker run --rm -v \"#{File.expand_path(dockerized_worker_dir)}\":/worker -w /worker iron/images:ruby-2.1 sh -c 'bundle install --standalone'", true)
130
+ bundle_output = console_command("docker run --rm -v \"#{File.expand_path(dockerized_worker_dir)}\":/worker -w /worker iron/images:ruby-2.1 sh -c 'bundle install --standalone'", true)
131
+
132
+ active_gems = {}
133
+ bundle_output.split("\n").each do |line|
134
+ active_gems["#{$2}-#{$3}"] = true if line =~ /^(Using|Installing)\s([^\s]+)\s([^\s]+)/
135
+ end
136
+
137
+ # Cleanup gems
138
+ dockerized_gems_dir = "#{dockerized_worker_dir}/bundle/ruby/2.1.0/gems"
139
+ Dir["#{dockerized_gems_dir}/*"].each do |dir_path|
140
+ dir_name = dir_path.gsub(/^#{dockerized_gems_dir}\//, '')
141
+ next if active_gems[dir_name]
142
+ puts "REMOVING UNUSED GEM #{dir_name}"
143
+ FileUtils.rm_r(dir_path)
144
+ end
111
145
 
112
- puts "Zipping to #{zipped_filepath_relative}"
146
+ print "Zipping to #{zipped_filepath_relative}... "
113
147
  File.delete(zipped_filepath) if File.exists?(zipped_filepath)
114
148
  Dir.chdir(dockerized_worker_dir) do
115
149
  console_command("zip -r #{zipped_filepath} .")
116
150
  end
151
+ zipped_filesize = (File.size(zipped_filepath).to_f / 2**20).round(2)
152
+ puts "#{zipped_filesize} MB"
117
153
 
118
154
  return zipped_filepath
119
155
  end
@@ -132,6 +168,7 @@ class Fanforce::PluginFactory::CLI::Iron
132
168
  # Command format for old versions
133
169
  command = "iron --project-id #{env_vars['IRON_PROJECT_ID']} --token #{env_vars['IRON_TOKEN']} worker upload --stack ruby-2.1 --name #{code_name} #{zipped_filepath} ruby worker.ru"
134
170
  end
171
+ puts command
135
172
  puts console_command(command)
136
173
  rescue Exception => e
137
174
  puts "#{'Aborted '.format(:red,:bold)} upload of #{code_name} to #{environment.to_s.titleize}..."
@@ -54,13 +54,13 @@ class Fanforce::PluginFactory::CLI::Scripts
54
54
 
55
55
  def push_plugin_worker(plugin, environment, filename)
56
56
  Dir.chdir(plugin.dir) do
57
- Fanforce::PluginFactory::CLI::Iron.new(plugin).upload(environment, filename)
57
+ Fanforce::PluginFactory::CLI::Iron.new(plugin).dockerize_and_upload(environment, filename)
58
58
  end
59
59
  end
60
60
 
61
61
  def push_plugin_workers(plugin, environment)
62
62
  Dir.chdir(plugin.dir) do
63
- Fanforce::PluginFactory::CLI::Iron.new(plugin).upload(environment)
63
+ Fanforce::PluginFactory::CLI::Iron.new(plugin).dockerize_and_upload(environment)
64
64
  end
65
65
  end
66
66
 
@@ -7,13 +7,19 @@ class Fanforce::PluginFactory::CLI::Scripts
7
7
  require_relative '../lib/bitbucket'
8
8
  require_relative '../lib/env'
9
9
  require_relative '../lib/uranium'
10
+ require_relative '../lib/iron'
10
11
 
11
12
  ######################################################################################################################
12
13
 
13
- def setup(type=:all)
14
+ def setup(type=:all, environment=nil)
14
15
  plugin = Fanforce::CLI::Plugin.new(Fanforce::CLI::DIR)
15
16
  type = type.to_s.downcase.to_sym
16
- error 'Unknown setup type', :setup if ![:all,:bundler,:pow,:git,:bitbucket,:env,:uranium].include?(type)
17
+ environment = environment.to_sym if environment
18
+
19
+ if (![:all,:bundler,:pow,:git,:bitbucket,:env,:uranium,:workers].include?(type) &&
20
+ !type.to_s.include?('.worker'))
21
+ error 'Unknown setup type', :setup
22
+ end
17
23
 
18
24
  if !File.exists?("#{plugin.dir}/config.ru")
19
25
  error "This does not seem to be a valid plugin directory since it's missing config.ru"
@@ -62,6 +68,15 @@ class Fanforce::PluginFactory::CLI::Scripts
62
68
  Fanforce::PluginFactory::CLI::Uranium.new(plugin).setup
63
69
  end
64
70
 
71
+ if type.to_s.include?('.worker')
72
+ Fanforce::PluginFactory::CLI::Iron.new(plugin).dockerize(environment, type.to_s)
73
+ end
74
+
75
+ if [:workers].include?(type)
76
+ log divider '+---------------------------------------------------------------------------------------------------'
77
+ Fanforce::PluginFactory::CLI::Iron.new(plugin).dockerize(environment)
78
+ end
79
+
65
80
  log divider '+-----------------------------------------------------------------------------------------------------'
66
81
  log 'SUCCESS!'.format(:bold,:green)
67
82
  log divider '----------------------------------------------------------------------------------------------------++'
@@ -14,13 +14,15 @@ class Fanforce::PluginFactory::CLI::Scripts
14
14
  ########################################################################################################################
15
15
 
16
16
  Fanforce::CLI.register(self, :setup,
17
- ['*all/TYPE', 'Setup bundle, pow, git, and env variables'],
18
- ['bundler', 'Ensure bundler is installed then run bundle'],
19
- ['pow', 'Ensure pow domains are setup correctly'],
20
- ['git', 'Ensure git repository is initialized'],
21
- ['bitbucket', 'Setup remote repository on bitbucket'],
22
- ['env', 'Create ENV variables from local .env folder'],
23
- ['uranium', 'Register config.json with uranium and add environ']
17
+ ['*all/TYPE', 'Setup bundle, pow, git, and env variables'],
18
+ ['bundler', 'Ensure bundler is installed then run bundle'],
19
+ ['pow', 'Ensure pow domains are setup correctly'],
20
+ ['git', 'Ensure git repository is initialized'],
21
+ ['bitbucket', 'Setup remote repository on bitbucket'],
22
+ ['env', 'Create ENV variables from local .env folder'],
23
+ ['uranium', 'Register config.json with uranium and add environ'],
24
+ ['workers RACK_ENV', 'Dockerize workers to zipped files ready for iron'],
25
+ ['FILENAME.worker RACK_ENV', 'Dockerize workers to zipped files ready for iron']
24
26
  ) { require_relative 'cli/scripts/setup' }
25
27
 
26
28
  ########################################################################################################################
@@ -29,15 +29,15 @@ class Fanforce::Plugin::CoreConfig
29
29
  @redis_url || ENV['REDIS_URL'] || 'redis://localhost:6379'
30
30
  end
31
31
 
32
- def worker_should_bypass_enqueue
33
- ENV['FANFORCE_WORKER_SHOULD_BYPASS_ENQUEUE'] == 'true'
32
+ def worker_should_run_locally_and_instantly
33
+ ENV['FANFORCE_WORKER_SHOULD_RUN_LOCALLY_AND_INSTANTLY'] == 'true'
34
34
  end
35
35
 
36
- def worker_should_bypass_enqueue=(bool)
36
+ def worker_should_run_locally_and_instantly=(bool)
37
37
  if bool == true
38
- ENV['FANFORCE_WORKER_SHOULD_BYPASS_ENQUEUE'] = 'true'
38
+ ENV['FANFORCE_WORKER_SHOULD_RUN_LOCALLY_AND_INSTANTLY'] = 'true'
39
39
  else
40
- ENV.delete('FANFORCE_WORKER_SHOULD_BYPASS_ENQUEUE')
40
+ ENV.delete('FANFORCE_WORKER_SHOULD_RUN_LOCALLY_AND_INSTANTLY')
41
41
  end
42
42
  end
43
43
 
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  class PluginFactory
3
- VERSION = '2.0.0.rc19'
3
+ VERSION = '2.0.0.rc21'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-plugin-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc19
4
+ version: 2.0.0.rc21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark
@@ -310,14 +310,14 @@ dependencies:
310
310
  requirements:
311
311
  - - ">="
312
312
  - !ruby/object:Gem::Version
313
- version: 2.0.0.rc11
313
+ version: 2.0.0.rc12
314
314
  type: :runtime
315
315
  prerelease: false
316
316
  version_requirements: !ruby/object:Gem::Requirement
317
317
  requirements:
318
318
  - - ">="
319
319
  - !ruby/object:Gem::Version
320
- version: 2.0.0.rc11
320
+ version: 2.0.0.rc12
321
321
  - !ruby/object:Gem::Dependency
322
322
  name: fanforce-test
323
323
  requirement: !ruby/object:Gem::Requirement