fontana_client_support 0.5.7 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/fontana.rb +8 -9
- data/lib/fontana/command_utils.rb +27 -0
- data/lib/fontana_client_support/tasks/app_mode.rake +25 -0
- data/lib/fontana_client_support/tasks/deploy/scm.rake +3 -0
- data/lib/fontana_client_support/tasks/deploy/sync.rake +3 -0
- data/lib/fontana_client_support/tasks/server.rake +145 -15
- data/lib/fontana_client_support/tasks/spec.rake +10 -10
- data/lib/fontana_client_support/tasks/vendor_fontana.rake +11 -11
- data/lib/fontana_client_support/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDBlMGI3YjhjYjljODhjN2IzNTUxZDkxMDA2M2QwOGYwOTlmNzBhZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGZlMDU4YTQzZDFmZTc1ZWQyMTA5YzdlZWQxODMxZTUxOTViZTQ1MQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODVkYWNlMzMxOGZkYzAzZTRhMjA5MjQ3MzM4MTI2MzI4MWUwMDhlYjkyNDRm
|
10
|
+
YTRlZDNmOGU4MjYxMjE2YTIxYzAxNmJiZWUwZWZjOTVjYmNkZTQ5MmQyN2Y2
|
11
|
+
NzcyZmU3ZTU3OTJkODgxZDRkNTgyNmQzYzFkYWQ3MTRjOGNhODM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzQzZWMyZjhiMDc1ODc5ODU2N2I4NzM2NTE0MzRlYTIzMWE4YjdkM2M1ZWEz
|
14
|
+
YmVjOTZlM2VkNDJjNzc3ODIwZjRjOGFjODliZWZiMjUyOTI5NTcyMDllZjc1
|
15
|
+
ZmY1OTc1Mjc0NzI3NWQ0MWY3MzA0ZTgxNTIwN2RiZjI2NmJlMjI=
|
data/lib/fontana.rb
CHANGED
@@ -29,15 +29,14 @@ module Fontana
|
|
29
29
|
@env ||= (ENV["FONTANA_ENV"] || "DEVELOPMENT").to_sym
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@version
|
32
|
+
# これは fontanaの Fontana.app_mode と同じ動きをすることが期待されています。
|
33
|
+
# https://github.com/tengine/fontana/blob/master/config/application.rb#L47
|
34
|
+
def app_mode
|
35
|
+
(ENV["FONTANA_APP_MODE"] || "development").to_sym # production development test
|
36
|
+
end
|
37
|
+
|
38
|
+
def app_mode=(value)
|
39
|
+
ENV["FONTANA_APP_MODE"] = value
|
41
40
|
end
|
42
41
|
|
43
42
|
end
|
@@ -1,10 +1,37 @@
|
|
1
1
|
require 'fontana'
|
2
|
+
require 'fileutils'
|
3
|
+
require "shellwords"
|
2
4
|
|
3
5
|
module Fontana
|
4
6
|
module CommandUtils
|
5
7
|
|
6
8
|
module_function
|
7
9
|
|
10
|
+
def system_at_vendor_fontana!(cmd, &block)
|
11
|
+
FileUtils::Verbose.chdir(FontanaClientSupport.vendor_fontana) do
|
12
|
+
return system!(cmd, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def spawn_at_vendor_fontana(env, cmd, options = {})
|
17
|
+
options = { chdir: FontanaClientSupport.vendor_fontana }.update(options)
|
18
|
+
env = env.each_with_object({}){|(k,v), d| d[k.to_s] = v.to_s }
|
19
|
+
puts "now spawning:\n env: #{env.inspect}\n cmd: #{cmd.inspect}\n options: #{options.inspect}"
|
20
|
+
pid = spawn(env, cmd, options)
|
21
|
+
puts "spawning suceeded pid: #{pid.inspect}"
|
22
|
+
Process.detach(pid)
|
23
|
+
return pid
|
24
|
+
end
|
25
|
+
|
26
|
+
def spawn_at_vendor_fontana_with_sweeper(*args)
|
27
|
+
pid = spawn_at_vendor_fontana(*args)
|
28
|
+
at_exit{
|
29
|
+
puts "Now killing #{pid}"
|
30
|
+
Process.kill("INT", pid)
|
31
|
+
}
|
32
|
+
pid
|
33
|
+
end
|
34
|
+
|
8
35
|
def system!(cmd)
|
9
36
|
puts "now executing: #{cmd}"
|
10
37
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'fontana_client_support'
|
3
|
+
|
4
|
+
namespace :app_mode do
|
5
|
+
|
6
|
+
desc "show app_mode"
|
7
|
+
task :show do
|
8
|
+
puts Fontana.app_mode.inspect
|
9
|
+
end
|
10
|
+
|
11
|
+
# 以下に:productionがありませんが、rakeタスクでproductionに設定することは想定できないので、敢えて作っていません。
|
12
|
+
|
13
|
+
desc "set app_mode test"
|
14
|
+
task :test do
|
15
|
+
Fontana.app_mode = "test"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "set app_mode development"
|
19
|
+
task :development do
|
20
|
+
Fontana.app_mode = "development"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
task :app_model => :"app_mode:show"
|
@@ -1,27 +1,157 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'fontana_client_support'
|
2
|
-
include Fontana::ServerRake
|
3
3
|
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
include Fontana::CommandUtils
|
4
7
|
extend Fontana::RakeUtils
|
5
8
|
|
6
|
-
|
9
|
+
def build_env_str(env)
|
10
|
+
env.each_with_object([]){|(k,v), d|
|
11
|
+
d << "#{k.to_s}=#{v.to_s}"
|
12
|
+
}.join(" ")
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
development: {http_port: 3000, https_port: 3001 },
|
17
|
+
test: {http_port: 4000, https_port: 4001 },
|
18
|
+
}.each do |app_mode, config|
|
19
|
+
namespace app_mode.to_sym do
|
20
|
+
|
21
|
+
pid_dir = File.join(FontanaClientSupport.vendor_fontana, "tmp/pids")
|
22
|
+
|
23
|
+
namespace :server do
|
24
|
+
http_env = {FONTANA_APP_MODE: app_mode, BUNDLE_GEMFILE: "Gemfile-LibgssTest" }
|
25
|
+
https_env = http_env.merge(HTTPS_PORT: config[:https_port])
|
26
|
+
|
27
|
+
http_env_str = build_env_str(http_env)
|
28
|
+
https_env_str = build_env_str(https_env)
|
29
|
+
|
30
|
+
desc "update VersionSet entries' versions and copy collections"
|
31
|
+
task(:update_version_set_entries) do
|
32
|
+
if ENV["GSS_VERSION_SET_FIXTURE_FILEPATH"]
|
33
|
+
system_at_vendor_fontana!(http_env_str + " rake version_set:update_entry_versions")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
http_base_cmd = "bundle exec rails server -p #{config[:http_port]}"
|
38
|
+
http_fg_cmd = "#{http_env_str} #{http_base_cmd}"
|
39
|
+
http_bg_cmd = "#{http_env_str} #{http_base_cmd} -d -P #{pid_dir}/#{app_mode}_http_server.pid"
|
40
|
+
|
41
|
+
# HTTPSのポートは script/secure_rails の内部で ENV['HTTPS_PORT'] を参照しています
|
42
|
+
https_base_cmd = "bundle exec script/secure_rails server webrick"
|
43
|
+
https_fg_cmd = "#{https_env_str} #{https_base_cmd}"
|
44
|
+
https_bg_cmd = "#{https_env_str} #{https_base_cmd} -d -P #{pid_dir}/#{app_mode}_https_server.pid"
|
45
|
+
|
46
|
+
{
|
47
|
+
launch_http_server: http_fg_cmd,
|
48
|
+
launch_http_server_daemon: http_bg_cmd,
|
49
|
+
launch_https_server: https_fg_cmd,
|
50
|
+
launch_https_server_daemon: https_bg_cmd,
|
51
|
+
}.each do |name, cmd|
|
52
|
+
task(name){ system_at_vendor_fontana!(cmd) }
|
53
|
+
end
|
54
|
+
|
55
|
+
task_sequential :launch_server_daemons, [
|
56
|
+
:"#{app_mode}:server:update_version_set_entries",
|
57
|
+
:"#{app_mode}:server:launch_http_server_daemon",
|
58
|
+
:"#{app_mode}:server:launch_https_server_daemon"
|
59
|
+
]
|
60
|
+
|
61
|
+
spawn_env = {FONTANA_APP_MODE: app_mode, BUNDLE_GEMFILE: "Gemfile-LibgssTest" }
|
62
|
+
task(:spawn_http_server){ spawn_at_vendor_fontana_with_sweeper(http_env, http_base_cmd, out: "/dev/null") }
|
63
|
+
task(:spawn_https_server){ spawn_at_vendor_fontana_with_sweeper(https_env, https_base_cmd, out: "/dev/null") }
|
64
|
+
|
65
|
+
task_sequential :spawn_servers, [
|
66
|
+
:"#{app_mode}:server:update_version_set_entries",
|
67
|
+
:"#{app_mode}:server:spawn_http_server",
|
68
|
+
:"#{app_mode}:server:spawn_https_server"
|
69
|
+
]
|
70
|
+
|
71
|
+
{
|
72
|
+
http: config[:http_port],
|
73
|
+
https: config[:https_port],
|
74
|
+
}.each do |name, port|
|
75
|
+
|
76
|
+
task(:"error_on_#{name}_listened") do
|
77
|
+
lsof = `lsof -i:#{port}`
|
78
|
+
if lsof =~ /LISTEN/
|
79
|
+
raise "\e[31mAnother server is already running on #{port}. Stop it in order to run new server.\n#{lsof}\e[0m"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
task(:"wait_to_listen_#{name}") do
|
84
|
+
timeout((ENV["WAIT_TO_LISTEN"] || 120).to_i) do
|
85
|
+
while true
|
86
|
+
break if `lsof -i:#{port}` =~ /LISTEN/
|
87
|
+
sleep(0.2)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
desc "error on ports listened by some server"
|
94
|
+
task :error_on_ports_listened => [
|
95
|
+
:error_on_http_listened,
|
96
|
+
:error_on_https_listened,
|
97
|
+
]
|
98
|
+
|
99
|
+
desc "wait to listen ports"
|
100
|
+
task :wait_to_listen_ports => [
|
101
|
+
:wait_to_listen_http,
|
102
|
+
:wait_to_listen_https,
|
103
|
+
]
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
namespace :servers do
|
108
|
+
desc "start #{app_mode} HTTP+HTTPS server daemons" if app_mode == :test
|
109
|
+
task :start => :"#{app_mode}:server:launch_server_daemons"
|
110
|
+
|
111
|
+
desc "stop #{app_mode} HTTP+HTTPS server daemons" if app_mode == :test
|
112
|
+
task :stop => :"#{app_mode}:servers:shutdown_server_daemons"
|
113
|
+
|
114
|
+
desc "stop #{app_mode} HTTP+HTTPS server daemons when process exit" if app_mode == :test
|
115
|
+
task :stop_on_exit do
|
116
|
+
at_exit{ Rake::Task["test:servers:stop"].execute }
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "restart #{app_mode} HTTP+HTTPS server daemons" if app_mode == :test
|
120
|
+
task_sequential(:restart, [:"#{app_mode}:servers:stop", :"#{app_mode}:servers:start"])
|
121
|
+
|
122
|
+
# desc "shutdown server daemons"
|
123
|
+
task :shutdown_server_daemons do
|
124
|
+
Dir.glob(File.join(pid_dir, "#{app_mode}_*.pid")) do |pid_path|
|
125
|
+
pid = `cat #{pid_path}`.strip
|
126
|
+
system!("kill -INT #{pid}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
desc "check #{app_mode} daemon alive"
|
131
|
+
task :check_daemon_alive do
|
132
|
+
pids = Dir.glob(File.join(pid_dir, "#{app_mode}_*.pid")).to_a
|
133
|
+
unless pids.empty?
|
134
|
+
msg = "\e[31mdaemons seems to be still alive! #{pids.inspect}\n"
|
135
|
+
cmd = "ps " + pids.map{|pid| "-p `cat #{pid}`" }.join(" ")
|
136
|
+
msg << `#{cmd}`
|
137
|
+
msg << "\n You can stop these daemons by using `rake test:servers:stop`"
|
138
|
+
msg << "\e[0m"
|
139
|
+
raise msg
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
7
143
|
|
8
|
-
|
9
|
-
fontana_task :launch_http_server_daemon
|
10
|
-
fontana_task :launch_https_server
|
11
|
-
fontana_task :launch_https_server_daemon
|
12
|
-
fontana_task :launch_server_daemons
|
13
|
-
fontana_task :shutdown_server_daemons
|
14
|
-
fontana_task :check_daemon_alive
|
144
|
+
end
|
15
145
|
end
|
16
146
|
|
17
147
|
|
18
148
|
namespace :servers do
|
19
|
-
desc "start HTTP+HTTPS server daemons"
|
20
|
-
task :start => :"
|
149
|
+
desc "start development HTTP+HTTPS server daemons"
|
150
|
+
task :start => :"development:servers:start"
|
21
151
|
|
22
|
-
desc "stop HTTP+HTTPS server daemons"
|
23
|
-
task :stop => :"
|
152
|
+
desc "stop development HTTP+HTTPS server daemons"
|
153
|
+
task :stop => :"development:servers:stop"
|
24
154
|
|
25
|
-
desc "restart HTTP+HTTPS server daemons"
|
26
|
-
|
155
|
+
desc "restart development HTTP+HTTPS server daemons"
|
156
|
+
task :restart => :"development:servers:restart"
|
27
157
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'fontana_client_support'
|
3
|
-
|
3
|
+
|
4
|
+
extend Fontana::RakeUtils
|
4
5
|
|
5
6
|
desc "Run RSpec with server_daemons"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
7
|
+
task_sequential :spec_with_server_daemons, [
|
8
|
+
:"app_mode:test",
|
9
|
+
:"test:server:error_on_ports_listened",
|
10
|
+
:"vendor:fontana:prepare",
|
11
|
+
:"test:server:spawn_servers",
|
12
|
+
:"test:server:wait_to_listen_ports",
|
13
|
+
:spec
|
14
|
+
]
|
@@ -15,12 +15,13 @@ namespace :vendor do
|
|
15
15
|
fileutils.rm_rf(d) if Dir.exist?(d)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
case FontanaClientSupport.deploy_strategy
|
19
|
+
when :scm then
|
20
|
+
task :deploy_reset => :"deploy:scm:reset"
|
21
|
+
task :deploy_update => :"deploy:scm:update"
|
22
|
+
when :sync then
|
23
|
+
task :deploy_reset => :"deploy:sync:reset"
|
24
|
+
task :deploy_update => :"deploy:sync:update"
|
24
25
|
end
|
25
26
|
|
26
27
|
task_sequential :setup, [
|
@@ -37,11 +38,7 @@ namespace :vendor do
|
|
37
38
|
system!("git clone #{Fontana.repo_url} vendor/fontana")
|
38
39
|
end
|
39
40
|
fileutils.chdir(FontanaClientSupport.vendor_fontana) do
|
40
|
-
|
41
|
-
system!("git checkout master && git reset --hard #{Fontana.version}")
|
42
|
-
else
|
43
|
-
system!("git checkout #{Fontana.branch}")
|
44
|
-
end
|
41
|
+
system!("git checkout #{Fontana.branch}")
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
@@ -68,6 +65,7 @@ namespace :vendor do
|
|
68
65
|
|
69
66
|
task_sequential :update, [
|
70
67
|
:"vendor:fontana:fetch_and_checkout",
|
68
|
+
:"vendor:fontana:configs",
|
71
69
|
:"vendor:fontana:bundle_install",
|
72
70
|
:"vendor:fontana:db_drop",
|
73
71
|
:"vendor:fontana:deploy_update",
|
@@ -93,6 +91,8 @@ namespace :vendor do
|
|
93
91
|
name = Dir.exist?(FontanaClientSupport.vendor_fontana) ? "update" : "reset"
|
94
92
|
Rake::Task["vendor:fontana:#{name}"].delegate
|
95
93
|
end
|
94
|
+
|
95
|
+
|
96
96
|
end
|
97
97
|
|
98
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontana_client_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/fontana_client_support.rb
|
107
107
|
- lib/fontana_client_support/config_server.rb
|
108
108
|
- lib/fontana_client_support/tasks.rb
|
109
|
+
- lib/fontana_client_support/tasks/app_mode.rake
|
109
110
|
- lib/fontana_client_support/tasks/config_server.rake
|
110
111
|
- lib/fontana_client_support/tasks/deploy/scm.rake
|
111
112
|
- lib/fontana_client_support/tasks/deploy/sync.rake
|