fanforce-plugin-factory 2.0.0.rc10 → 2.0.0.rc11
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 +4 -4
- data/fanforce-plugin-factory.gemspec +1 -1
- data/lib/fanforce/plugin_factory/cli/lib/env.rb +12 -16
- data/lib/fanforce/plugin_factory/cli/lib/heroku.rb +1 -4
- data/lib/fanforce/plugin_factory/cli/lib/iron.rb +56 -50
- data/lib/fanforce/plugin_factory/cli/lib/utils.rb +9 -1
- data/lib/fanforce/plugin_factory/cli/scripts/update.rb +0 -2
- data/lib/fanforce/plugin_factory/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0117f262c7a990283c4cd07fbde01df527070bfe
|
4
|
+
data.tar.gz: ccfab32e2af805e520ea20d04206301b66a9390d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c22b3520fdb235b34005cf8c5b49d892e74d5a2fbb8d745e8ef02421bb871eb9dd0a87c6fc328ba4d0026ae5ab043400d217e759febe9aaaac54cdb8d298a228
|
7
|
+
data.tar.gz: be48557509310eebb08e9fe0028175ab5711ad021e73f2df56a9b252d9845079fe2eb08858d1cfd7e26da7eafeb2e48f79782ccab7ea97d22bfea420483e3929
|
@@ -39,7 +39,7 @@ Gem::Specification.new do |gem|
|
|
39
39
|
|
40
40
|
gem.add_runtime_dependency 'fanforce-base', '>= 2.0.0.rc2'
|
41
41
|
gem.add_runtime_dependency 'fanforce-api', '>= 2.0.0.rc4'
|
42
|
-
gem.add_runtime_dependency 'fanforce-plugin-worker', '>= 2.0.0.
|
42
|
+
gem.add_runtime_dependency 'fanforce-plugin-worker', '>= 2.0.0.rc7'
|
43
43
|
|
44
44
|
gem.add_development_dependency 'fanforce-test', '>= 2.0.0.rc2'
|
45
45
|
end
|
@@ -22,32 +22,18 @@ class Fanforce::PluginFactory::CLI::Env
|
|
22
22
|
log "#{'Updated'.format(:green,:bold)} #{environment.to_s.titleize}#{has_workers ? '... and workers have' : ' has'} #{vars.size} env variables"
|
23
23
|
end
|
24
24
|
|
25
|
-
def push_to(environment, vars
|
25
|
+
def push_to(environment, vars)
|
26
26
|
environment = environment.to_sym
|
27
27
|
vars.each {|k,v| puts " - #{k}" }
|
28
|
-
workers_dir = "#{plugin.dir}/workers"
|
29
|
-
workers_env_dir = "#{workers_dir}/.env"
|
30
|
-
if create_worker_env and File.directory?(workers_dir) and vars['IRON_PROJECT_ID']
|
31
|
-
FileUtils.mkdir_p(workers_env_dir) unless File.directory?(workers_env_dir)
|
32
|
-
File.open("#{workers_env_dir}/#{environment}.rb", 'w') {|f| f.write convert_hash_to_ruby_env(vars) }
|
33
|
-
end
|
34
28
|
if environment == :development
|
35
29
|
update_powenv
|
36
|
-
File.open("#{plugin.dir}/.pluginenv", 'w') {|f| f.write convert_hash_to_shell_env(vars) }
|
30
|
+
File.open("#{plugin.dir}/.pluginenv", 'w') {|f| f.write self.class.convert_hash_to_shell_env(vars) }
|
37
31
|
else
|
38
32
|
error 'could not find heroku in .fanforce-plugin-factory' if config[:heroku][environment].blank?
|
39
33
|
Fanforce::PluginFactory::CLI::Heroku.new(plugin, environment).update_config(vars)
|
40
34
|
end
|
41
35
|
end
|
42
36
|
|
43
|
-
def convert_hash_to_shell_env(hash)
|
44
|
-
hash.inject('') {|script, (k,v)| script += "export #{k}=#{v.to_s.to_json}\n" }
|
45
|
-
end
|
46
|
-
|
47
|
-
def convert_hash_to_ruby_env(hash)
|
48
|
-
hash.inject('') {|script, (k,v)| script += "ENV['#{k}']=#{v.to_s.to_json}\n" }
|
49
|
-
end
|
50
|
-
|
51
37
|
def load_vars(environment)
|
52
38
|
environment = environment.to_sym
|
53
39
|
vars = {'FANFORCE_PLUGIN_ID' => plugin._id}
|
@@ -93,4 +79,14 @@ class Fanforce::PluginFactory::CLI::Env
|
|
93
79
|
['source .pluginenv']
|
94
80
|
end
|
95
81
|
|
82
|
+
# CLASS METHODS #######################################################################
|
83
|
+
|
84
|
+
def self.convert_hash_to_shell_env(hash)
|
85
|
+
hash.inject('') {|script, (k,v)| script += "export #{k}=#{v.to_s.to_json}\n" }
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.convert_hash_to_ruby_env(hash)
|
89
|
+
hash.inject('') {|script, (k,v)| script += "ENV['#{k}']=#{v.to_s.to_json}\n" }
|
90
|
+
end
|
91
|
+
|
96
92
|
end
|
@@ -101,10 +101,7 @@ class Fanforce::PluginFactory::CLI::Heroku
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def env
|
104
|
-
|
105
|
-
when :staging then env = :stg
|
106
|
-
when :production then env = :prd
|
107
|
-
end
|
104
|
+
Fanforce::PluginFactory::CLI::Utils.env(environment)
|
108
105
|
end
|
109
106
|
|
110
107
|
def app_name
|
@@ -10,23 +10,16 @@ class Fanforce::PluginFactory::CLI::Iron
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def workers_dir
|
13
|
-
"#{plugin.dir}/workers"
|
13
|
+
@workers_dir ||= "#{plugin.dir}/workers"
|
14
14
|
end
|
15
15
|
|
16
16
|
def upload(environment, worker_filename=nil)
|
17
17
|
return log "#{'Skipped '.format(:bold)} no workers folder was found" if !File.directory?(workers_dir)
|
18
18
|
|
19
19
|
worker_filename = worker_filename.gsub('.worker', '') if worker_filename
|
20
|
-
|
21
|
-
|
22
|
-
#factory_version = current_factory_version
|
20
|
+
env_vars = Fanforce::PluginFactory::CLI::Env.new(plugin).vars(environment) || {}
|
21
|
+
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?
|
23
22
|
|
24
|
-
return 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?
|
25
|
-
|
26
|
-
# puts "#{'Updating Env'.format(:green,:bold)} #{environment.to_s.titleize}... and workers have #{vars.size} env variables"
|
27
|
-
# env.push_to(environment, vars, true)
|
28
|
-
|
29
|
-
iron_worker = IronWorker::Client.new(:token => vars['IRON_TOKEN'], :project_id => vars['IRON_PROJECT_ID'])
|
30
23
|
Dir.chdir(workers_dir) do
|
31
24
|
workers = Dir['*.rb']
|
32
25
|
return puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} has 0 workers" if workers.size == 0
|
@@ -34,69 +27,72 @@ class Fanforce::PluginFactory::CLI::Iron
|
|
34
27
|
upload_processes = []
|
35
28
|
workers.each do |filename|
|
36
29
|
next if worker_filename and !filename.include?(worker_filename)
|
37
|
-
|
38
|
-
|
30
|
+
zipped_filepath = compile_worker(filename, environment, env_vars)
|
31
|
+
upload_processes << upload_worker(filename, environment, env_vars, zipped_filepath)
|
39
32
|
end
|
40
33
|
upload_processes.each { |pid| Process.waitpid(pid) }
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
44
|
-
def compile_worker(filename, environment)
|
37
|
+
def compile_worker(filename, environment, env_vars)
|
45
38
|
puts "#{'Compiling'.format(:green,:bold)} #{filename.gsub('.rb', '')} to #{environment.to_s.titleize}..."
|
46
39
|
code_name = filename.gsub('.rb', '')
|
47
|
-
absolute_dir = "#{workers_dir}/#{code_name}"
|
48
|
-
relative_dir = "workers/#{code_name}"
|
49
40
|
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
dockerized_dir = "#{workers_dir}/dockerized/#{code_name}"
|
42
|
+
dockerized_dir_relative = "workers/dockerized/#{code_name}"
|
43
|
+
Dir.mkdir("#{workers_dir}/dockerized") if !File.directory?("#{workers_dir}/dockerized")
|
44
|
+
|
45
|
+
zipped_dir = "#{workers_dir}/zipped"
|
46
|
+
zipped_filepath = "#{zipped_dir}/#{code_name}.#{env(environment)}.zip"
|
47
|
+
Dir.mkdir(zipped_dir) if !File.directory?(zipped_dir)
|
48
|
+
|
49
|
+
if !File.directory?(dockerized_dir)
|
50
|
+
puts "Creating #{dockerized_dir_relative}/"
|
51
|
+
Dir.mkdir(dockerized_dir)
|
53
52
|
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
File.open("#{absolute_dir}/Gemfile", 'w') {|f| f.write(contents) }
|
54
|
+
puts "Copying /workers/#{filename} to #{dockerized_dir_relative}/#{filename}"
|
55
|
+
File.open("#{dockerized_dir}/#{filename}", 'w') do |f|
|
56
|
+
f.write File.read("#{plugin.dir}/workers/#{filename}")
|
59
57
|
end
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
puts "Copying /Gemfile to #{dockerized_dir_relative}/Gemfile"
|
60
|
+
File.open("#{dockerized_dir}/Gemfile", 'w') do |f|
|
61
|
+
f.write File.read("#{plugin.dir}/Gemfile").gsub("ruby '2.1.6'", "ruby '2.1.4'")
|
64
62
|
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
puts "Copying /Gemfile.lock to #{dockerized_dir_relative}/Gemfile.lock"
|
65
|
+
File.open("#{dockerized_dir}/Gemfile.lock", 'w') do |f|
|
66
|
+
f.write File.read("#{plugin.dir}/Gemfile.lock")
|
69
67
|
end
|
70
68
|
|
71
|
-
|
72
|
-
|
69
|
+
if File.directory?("#{plugin.dir}/lib") and !File.directory?("#{dockerized_dir}/lib")
|
70
|
+
puts "Copying /lib/ to #{dockerized_dir_relative}/lib/"
|
71
|
+
FileUtils.copy_entry("#{plugin.dir}/lib", "#{dockerized_dir}/lib")
|
72
|
+
end
|
73
73
|
|
74
|
-
|
74
|
+
if File.directory?("#{plugin.dir}/mailers") and !File.directory?("#{dockerized_dir}/mailers")
|
75
|
+
puts "Copying /mailers/ to #{dockerized_dir_relative}/mailers/"
|
76
|
+
FileUtils.copy_entry("#{plugin.dir}/mailers", "#{dockerized_dir}/mailers")
|
77
|
+
end
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
# puts "#{'Uploading'.format(:green,:bold)} #{filename.gsub('.rb', '')} to #{environment.to_s.titleize}..."
|
79
|
-
#
|
80
|
-
# code = IronWorker::Code::Ruby.new(:workerfile => "#{plugin.dir}/workers/#{filename}")
|
81
|
-
# code.gem('fanforce-plugin-factory', factory_version)
|
82
|
-
# code.remote
|
83
|
-
# code.name = code_name
|
84
|
-
# code.file("#{plugin.dir}/workers/.env/#{environment}.rb", '.env')
|
85
|
-
#
|
86
|
-
# upload_processes << upload_iron_worker(iron_worker, code, filename, environment)
|
87
|
-
end
|
79
|
+
puts "Setting up ENV for #{environment.to_s.titleize} (#{env_vars.size} variables)"
|
80
|
+
File.open("#{dockerized_dir}/env.#{env(environment)}.rb", 'w') {|f| f.write Fanforce::PluginFactory::CLI::Env.convert_hash_to_ruby_env(env_vars) }
|
88
81
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
puts "Dockerizing #{File.expand_path(dockerized_dir)}"
|
83
|
+
console_command("docker run --rm -v \"#{File.expand_path(dockerized_dir)}\":/worker -w /worker iron/images:ruby-2.1 sh -c 'bundle install --standalone'", true)
|
84
|
+
console_command("zip -r #{zipped_filepath} #{dockerized_dir}")
|
85
|
+
|
86
|
+
return zipped_filepath
|
94
87
|
end
|
95
88
|
|
96
|
-
def
|
89
|
+
def upload_worker(filename, environment, env_vars, zipped_filepath)
|
90
|
+
code_name = filename.gsub('.rb', '')
|
91
|
+
puts "#{'Uploading'.format(:green,:bold)} #{code_name} to #{environment.to_s.titleize}..."
|
92
|
+
|
97
93
|
fork do
|
98
94
|
begin
|
99
|
-
|
95
|
+
puts console_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 #{filename}")
|
100
96
|
rescue Exception => e
|
101
97
|
puts "#{'Aborted '.format(:red,:bold)} upload of #{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
|
102
98
|
puts e.message
|
@@ -106,4 +102,14 @@ class Fanforce::PluginFactory::CLI::Iron
|
|
106
102
|
end
|
107
103
|
end
|
108
104
|
|
105
|
+
def current_factory_version
|
106
|
+
`bundle list`.lines.each do |line|
|
107
|
+
return $1 if line =~ /fanforce-plugin-factory \(([A-Za-z0-9.-]+)\)/
|
108
|
+
end
|
109
|
+
error 'fanforce-plugin-factory version was not found in `bundle list`'
|
110
|
+
end
|
111
|
+
|
112
|
+
def upload_iron_worker(iron_worker, code, filename, environment)
|
113
|
+
end
|
114
|
+
|
109
115
|
end
|
@@ -14,7 +14,7 @@ module Fanforce::PluginFactory::CLI::Utils
|
|
14
14
|
PTY.spawn(command) do |stdin, stdout, pid|
|
15
15
|
stdin.each { |line| output << line; print line if print_now }
|
16
16
|
end
|
17
|
-
output.join(
|
17
|
+
output.join('')
|
18
18
|
end
|
19
19
|
|
20
20
|
def silence_warnings
|
@@ -54,4 +54,12 @@ module Fanforce::PluginFactory::CLI::Utils
|
|
54
54
|
hash.symbolize_keys!
|
55
55
|
end
|
56
56
|
|
57
|
+
def env(environment)
|
58
|
+
case environment.to_sym
|
59
|
+
when :development then :dev
|
60
|
+
when :staging then :stg
|
61
|
+
when :production then :prd
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
57
65
|
end
|
@@ -9,7 +9,6 @@ class Fanforce::PluginFactory::CLI::Scripts
|
|
9
9
|
|
10
10
|
def update(type)
|
11
11
|
type = type.to_sym
|
12
|
-
|
13
12
|
return update_factory if type == :factory
|
14
13
|
|
15
14
|
if Fanforce::CLI::TYPE == :directory_of_plugins
|
@@ -110,7 +109,6 @@ class Fanforce::PluginFactory::CLI::Scripts
|
|
110
109
|
# end
|
111
110
|
log divider '---------------------------------------------------------------------------------------------------+'
|
112
111
|
|
113
|
-
|
114
112
|
local_path ? install_local_factory_gem(version, local_path) : install_remote_factory_gem(version)
|
115
113
|
puts ''
|
116
114
|
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.
|
4
|
+
version: 2.0.0.rc11
|
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.
|
313
|
+
version: 2.0.0.rc7
|
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.
|
320
|
+
version: 2.0.0.rc7
|
321
321
|
- !ruby/object:Gem::Dependency
|
322
322
|
name: fanforce-test
|
323
323
|
requirement: !ruby/object:Gem::Requirement
|