luban 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/luban +3 -0
- data/lib/luban/deployment/cli/application/authenticator.rb +106 -0
- data/lib/luban/deployment/cli/application/base.rb +179 -0
- data/lib/luban/deployment/cli/application/builder.rb +67 -0
- data/lib/luban/deployment/cli/application/publisher.rb +215 -0
- data/lib/luban/deployment/cli/application/repository.rb +175 -0
- data/lib/luban/deployment/cli/application/scm/git.rb +49 -0
- data/lib/luban/deployment/cli/application/scm/rsync.rb +47 -0
- data/lib/luban/deployment/cli/application.rb +5 -0
- data/lib/luban/deployment/cli/command.rb +360 -0
- data/lib/luban/deployment/cli/package/binary.rb +241 -0
- data/lib/luban/deployment/cli/package/dependency.rb +49 -0
- data/lib/luban/deployment/cli/package/dependency_set.rb +71 -0
- data/lib/luban/deployment/cli/package/installer/core.rb +98 -0
- data/lib/luban/deployment/cli/package/installer/install.rb +330 -0
- data/lib/luban/deployment/cli/package/installer/paths.rb +81 -0
- data/lib/luban/deployment/cli/package/installer.rb +3 -0
- data/lib/luban/deployment/cli/package/service.rb +17 -0
- data/lib/luban/deployment/cli/package/worker.rb +43 -0
- data/lib/luban/deployment/cli/package.rb +6 -0
- data/lib/luban/deployment/cli/project.rb +94 -0
- data/lib/luban/deployment/cli.rb +4 -0
- data/lib/luban/deployment/configuration/core.rb +67 -0
- data/lib/luban/deployment/configuration/filter.rb +54 -0
- data/lib/luban/deployment/configuration/question.rb +38 -0
- data/lib/luban/deployment/configuration/server.rb +70 -0
- data/lib/luban/deployment/configuration/server_set.rb +86 -0
- data/lib/luban/deployment/configuration.rb +5 -0
- data/lib/luban/deployment/error.rb +5 -0
- data/lib/luban/deployment/helpers/configuration.rb +159 -0
- data/lib/luban/deployment/helpers/utils.rb +180 -0
- data/lib/luban/deployment/helpers.rb +2 -0
- data/lib/luban/deployment/packages/bundler.rb +81 -0
- data/lib/luban/deployment/packages/git.rb +37 -0
- data/lib/luban/deployment/packages/openssl.rb +59 -0
- data/lib/luban/deployment/packages/ruby.rb +125 -0
- data/lib/luban/deployment/packages/rubygems.rb +89 -0
- data/lib/luban/deployment/packages/yaml.rb +33 -0
- data/lib/luban/deployment/parameters.rb +160 -0
- data/lib/luban/deployment/runner.rb +99 -0
- data/lib/luban/deployment/templates/envrc.erb +30 -0
- data/lib/luban/deployment/templates/unset_envrc.erb +28 -0
- data/lib/luban/deployment/version.rb +5 -0
- data/lib/luban/deployment/worker/base.rb +71 -0
- data/lib/luban/deployment/worker/controller.rb +11 -0
- data/lib/luban/deployment/worker/local.rb +19 -0
- data/lib/luban/deployment/worker/remote.rb +55 -0
- data/lib/luban/deployment/worker/task.rb +25 -0
- data/lib/luban/deployment/worker.rb +4 -0
- data/lib/luban/deployment.rb +8 -0
- data/lib/luban.rb +4 -0
- data/luban.gemspec +29 -0
- metadata +174 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Openssl < Luban::Deployment::Package::Binary
|
5
|
+
class Installer < Luban::Deployment::Package::Installer
|
6
|
+
OSXArchArgs = {
|
7
|
+
x86_64: %w(darwin64-x86_64-cc enable-ec_nistp_64_gcc_128),
|
8
|
+
i386: %w(darwin-i386-cc)
|
9
|
+
}
|
10
|
+
|
11
|
+
def configure_executable
|
12
|
+
@configure_executable = osx? ? './Configure' : './config'
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def openssl_executable
|
17
|
+
@openssl_executable ||= bin_path.join('openssl')
|
18
|
+
end
|
19
|
+
|
20
|
+
def source_repo
|
21
|
+
#@source_repo ||= "https://www.openssl.org"
|
22
|
+
@source_repo ||= "http://www.openssl.org"
|
23
|
+
end
|
24
|
+
|
25
|
+
def source_url_root
|
26
|
+
@source_url_root ||= "source"
|
27
|
+
end
|
28
|
+
|
29
|
+
def installed?
|
30
|
+
return false unless file?(openssl_executable)
|
31
|
+
match?("#{openssl_executable} version", package_version)
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_configure_opts
|
35
|
+
@default_configure_opts ||= %w(no-ssl2 zlib-dynamic shared enable-cms)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def configure_build_options
|
41
|
+
super
|
42
|
+
@configure_opts.unshift(OSXArchArgs[hardware_name.to_sym]) if osx?
|
43
|
+
end
|
44
|
+
|
45
|
+
def make_package!
|
46
|
+
super and test(:make, "depend >> #{install_log_file_path} 2>&1")
|
47
|
+
end
|
48
|
+
|
49
|
+
def cleanup_temp!
|
50
|
+
super
|
51
|
+
# Clean up man pages
|
52
|
+
manpages_path = install_path.join('ssl/man')
|
53
|
+
rmdir(manpages_path) if directory?(manpages_path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Ruby < Luban::Deployment::Package::Binary
|
5
|
+
apply_to '1.8.6' do
|
6
|
+
after_install do
|
7
|
+
depend_on 'rubygems', version: '1.3.7'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
apply_to '1.8.7' do
|
12
|
+
after_install do
|
13
|
+
depend_on 'rubygems', version: '1.6.2'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
apply_to '1.9.1' do
|
18
|
+
before_install do
|
19
|
+
depend_on 'yaml', version: '0.1.6'
|
20
|
+
end
|
21
|
+
after_install do
|
22
|
+
depend_on 'rubygems', version: '1.3.7'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
apply_to '1.9.2' do
|
27
|
+
before_install do
|
28
|
+
depend_on 'yaml', version: '0.1.6'
|
29
|
+
end
|
30
|
+
after_install do
|
31
|
+
depend_on 'rubygems', version: '1.8.23'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
apply_to [">= 1.9.3", "< 2.1.2"] do
|
36
|
+
before_install do
|
37
|
+
depend_on 'yaml', version: '0.1.6'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
apply_to '>= 1.9.3' do
|
42
|
+
before_install do
|
43
|
+
depend_on 'openssl', version: '1.0.2g'
|
44
|
+
#depend_on 'yaml', version: '0.1.6'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
apply_to :all do
|
49
|
+
after_install do
|
50
|
+
depend_on 'bundler', version: '1.11.2'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
def setup_install_tasks
|
57
|
+
super
|
58
|
+
commands[:install].switch :install_doc, "Install Ruby document"
|
59
|
+
commands[:install].option :bundler, "Bundler version"
|
60
|
+
end
|
61
|
+
|
62
|
+
def decompose_version(version)
|
63
|
+
major_version, patch_level = version.split('-')
|
64
|
+
patch_level = '' if patch_level.nil?
|
65
|
+
patch_level = $1 if patch_level.match(/^p(\d+)$/)
|
66
|
+
{ major_version: major_version, patch_level: patch_level }
|
67
|
+
end
|
68
|
+
|
69
|
+
class Installer < Luban::Deployment::Package::Installer
|
70
|
+
attr_reader :opt_dirs
|
71
|
+
|
72
|
+
def install_doc?
|
73
|
+
task.opts.install_doc
|
74
|
+
end
|
75
|
+
|
76
|
+
def ruby_executable
|
77
|
+
@ruby_executable ||= bin_path.join('ruby')
|
78
|
+
end
|
79
|
+
|
80
|
+
def gem_executable
|
81
|
+
@gem_executable ||= bin_path.join('gem')
|
82
|
+
end
|
83
|
+
|
84
|
+
def source_repo
|
85
|
+
@source_repo ||= "https://cache.ruby-lang.org"
|
86
|
+
end
|
87
|
+
|
88
|
+
def source_url_root
|
89
|
+
@source_url_root ||= "pub/ruby/#{package_major_version.gsub(/\.\d+$/, '')}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def installed?
|
93
|
+
return false unless file?(ruby_executable)
|
94
|
+
pattern = Regexp.escape(package_major_version)
|
95
|
+
unless package_patch_level.empty?
|
96
|
+
pattern += ".*#{Regexp.escape(package_patch_level)}"
|
97
|
+
end
|
98
|
+
match?("#{ruby_executable} -v", Regexp.new(pattern))
|
99
|
+
end
|
100
|
+
|
101
|
+
def with_opt_dir(dir)
|
102
|
+
@opt_dirs << dir
|
103
|
+
end
|
104
|
+
alias_method :with_openssl_dir, :with_opt_dir
|
105
|
+
alias_method :with_yaml_dir, :with_opt_dir
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
def configure_build_options
|
110
|
+
super
|
111
|
+
unless install_doc?
|
112
|
+
@configure_opts.unshift("--disable-install-doc")
|
113
|
+
end
|
114
|
+
@opt_dirs = []
|
115
|
+
end
|
116
|
+
|
117
|
+
def compose_build_options
|
118
|
+
@configure_opts << "--with-opt-dir=#{@opt_dirs.join(':')}"
|
119
|
+
super
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Rubygems < Luban::Deployment::Package::Binary
|
5
|
+
protected
|
6
|
+
|
7
|
+
def setup_install_tasks
|
8
|
+
super
|
9
|
+
commands[:install].switch :install_doc, "Install Rubygems document"
|
10
|
+
end
|
11
|
+
|
12
|
+
class Installer < Luban::Deployment::Package::Installer
|
13
|
+
def install_doc?
|
14
|
+
task.opts.install_doc
|
15
|
+
end
|
16
|
+
|
17
|
+
def package_path
|
18
|
+
parent.package_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def install_path
|
22
|
+
parent.install_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def rubygems_executable
|
26
|
+
@rubygems_executable ||= bin_path.join('gem')
|
27
|
+
end
|
28
|
+
|
29
|
+
def ruby_executable
|
30
|
+
parent.ruby_executable
|
31
|
+
end
|
32
|
+
|
33
|
+
def src_file_extname
|
34
|
+
@src_file_extname ||= 'tgz'
|
35
|
+
end
|
36
|
+
|
37
|
+
def source_repo
|
38
|
+
#@source_repo ||= "http://production.cf.rubygems.org"
|
39
|
+
@source_repo ||= "https://rubygems.org"
|
40
|
+
end
|
41
|
+
|
42
|
+
def source_url_root
|
43
|
+
@source_url_root ||= "rubygems"
|
44
|
+
end
|
45
|
+
|
46
|
+
def installed?
|
47
|
+
return false unless file?(rubygems_executable)
|
48
|
+
match?("#{rubygems_executable} -v", package_version)
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def configure_build_options
|
54
|
+
super
|
55
|
+
unless install_doc?
|
56
|
+
@configure_opts.push('--no-rdoc', '--no-ri')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate
|
61
|
+
if parent.nil?
|
62
|
+
abort "Aborted! Parent package for Rubygems MUST be provided."
|
63
|
+
end
|
64
|
+
unless parent.is_a?(Ruby::Installer)
|
65
|
+
abort "Aborted! Parent package for Rubygems MUST be an instance of #{Ruby::Installer.name}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def configure_package!
|
70
|
+
test(ruby_executable,
|
71
|
+
"setup.rb config #{configure_opts.reject(&:empty?).join(' ')} >> #{install_log_file_path} 2>&1")
|
72
|
+
end
|
73
|
+
|
74
|
+
def make_package!
|
75
|
+
test(ruby_executable,
|
76
|
+
"setup.rb setup >> #{install_log_file_path} 2>&1")
|
77
|
+
end
|
78
|
+
|
79
|
+
def install_package!
|
80
|
+
test(ruby_executable,
|
81
|
+
"setup.rb install >> #{install_log_file_path} 2>&1")
|
82
|
+
end
|
83
|
+
|
84
|
+
def update_binstubs!; end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Yaml < Luban::Deployment::Package::Binary
|
5
|
+
class Installer < Luban::Deployment::Package::Installer
|
6
|
+
def header_file
|
7
|
+
@header_file ||= include_path.join('yaml.h')
|
8
|
+
end
|
9
|
+
|
10
|
+
def shared_obj_file
|
11
|
+
@shared_obj_file ||= lib_path.join("libyaml.#{lib_extension}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def source_repo
|
15
|
+
@source_repo ||= "http://pyyaml.org"
|
16
|
+
end
|
17
|
+
|
18
|
+
def source_url_root
|
19
|
+
@source_url_root ||= "download/libyaml"
|
20
|
+
end
|
21
|
+
|
22
|
+
def installed?
|
23
|
+
file?(header_file) and file?(shared_obj_file)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def update_binstubs!; end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Parameters
|
4
|
+
module Base
|
5
|
+
def parameter(*params)
|
6
|
+
params.each do |param|
|
7
|
+
define_method(param) do |value = nil|
|
8
|
+
value.nil? ? fetch(__method__) : set(__method__, value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module General
|
15
|
+
extend Base
|
16
|
+
|
17
|
+
DefaultLubanRootPath = Pathname.new('/opt/luban')
|
18
|
+
|
19
|
+
def self.included(mod)
|
20
|
+
mod.extend(Base)
|
21
|
+
end
|
22
|
+
|
23
|
+
parameter :luban_roles
|
24
|
+
parameter :luban_root_path
|
25
|
+
|
26
|
+
parameter :stages
|
27
|
+
parameter :production_stages
|
28
|
+
parameter :applications
|
29
|
+
|
30
|
+
parameter :work_dir
|
31
|
+
parameter :apps_path
|
32
|
+
parameter :project
|
33
|
+
parameter :user
|
34
|
+
parameter :config_finder
|
35
|
+
|
36
|
+
def production_stage?(stage)
|
37
|
+
production_stages.include?(stage)
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def set_default_general_parameters
|
43
|
+
set_default :luban_roles, %i(app)
|
44
|
+
set_default :luban_root_path, DefaultLubanRootPath
|
45
|
+
set_default :user, ENV['USER']
|
46
|
+
set_default :config_finder, {}
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_general_parameters
|
50
|
+
if user != ENV['USER']
|
51
|
+
abort "Aborted! Given deployment user (#{user.inspect}) is NOT the current user #{ENV['USER'].inspect}" +
|
52
|
+
"Please switch to the deployment user before any deployments."
|
53
|
+
end
|
54
|
+
if project.nil?
|
55
|
+
abort "Aborted! Please specify the project name: project 'project name'"
|
56
|
+
end
|
57
|
+
if luban_root_path.is_a?(String)
|
58
|
+
luban_root_path Pathname.new(luban_root_path)
|
59
|
+
end
|
60
|
+
unless luban_root_path.is_a?(Pathname)
|
61
|
+
abort "Aborted! Luban root path should be a String or a Pathname: luban_root_path Pathname.new('/opt/luban')"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Project
|
67
|
+
extend Base
|
68
|
+
|
69
|
+
parameter :stage
|
70
|
+
|
71
|
+
parameter :process_monitor
|
72
|
+
parameter :process_monitor_env
|
73
|
+
parameter :lubhub_protocol
|
74
|
+
parameter :lubhub_host
|
75
|
+
parameter :lubhub_port
|
76
|
+
|
77
|
+
parameter :sshkit_backend
|
78
|
+
parameter :authen_key_type
|
79
|
+
parameter :default_env
|
80
|
+
parameter :log_format
|
81
|
+
parameter :log_level
|
82
|
+
parameter :pty
|
83
|
+
parameter :connection_timeout
|
84
|
+
parameter :ssh_options
|
85
|
+
parameter :shell_setup
|
86
|
+
parameter :use_sudo
|
87
|
+
|
88
|
+
# To download all package sources directly from the package providers,
|
89
|
+
# Just do NOT set any Lubpack related variables.
|
90
|
+
#
|
91
|
+
# To specify the Lubpack of your own, you can
|
92
|
+
# lubhub_protocol 'http'
|
93
|
+
# lubhub_host 'your.lubhub.com'
|
94
|
+
# lubhub_port 8080
|
95
|
+
def lubhub
|
96
|
+
lubhub_host.nil? ? nil : "#{lubhub_protocol}://#{lubhub_host}:#{lubhub_port}"
|
97
|
+
end
|
98
|
+
alias_method :lubhub_repo, :lubhub
|
99
|
+
|
100
|
+
protected
|
101
|
+
|
102
|
+
def set_default_project_parameters
|
103
|
+
set_default :lubhub_protocol, 'http'
|
104
|
+
set_default :lubhub_port, 8080
|
105
|
+
set_default :sshkit_backend, SSHKit::Backend::Netssh
|
106
|
+
set_default :authen_key_type, 'rsa'
|
107
|
+
set_default :default_env, { path: '$PATH:/usr/local/bin' }
|
108
|
+
set_default :log_format, :pretty
|
109
|
+
set_default :log_level, :info
|
110
|
+
set_default :pty, false
|
111
|
+
set_default :connection_timeout, 30 # second
|
112
|
+
set_default :ssh_options, {}
|
113
|
+
set_default :shell_setup, 'bash -l' # Use Bash interactive shell by default
|
114
|
+
set_default :use_sudo, false # Turn off sudo by default
|
115
|
+
|
116
|
+
setup_default_project_config_finder
|
117
|
+
end
|
118
|
+
|
119
|
+
def setup_default_project_config_finder
|
120
|
+
config_finder[:project] ||=
|
121
|
+
Luban::Deployment::Helpers::Configuration::Finder.project(self)
|
122
|
+
end
|
123
|
+
|
124
|
+
def validate_project_parameters; end
|
125
|
+
end
|
126
|
+
|
127
|
+
module Application
|
128
|
+
extend Base
|
129
|
+
|
130
|
+
parameter :application
|
131
|
+
parameter :scm_role
|
132
|
+
parameter :keep_releases
|
133
|
+
parameter :linked_dirs
|
134
|
+
parameter :linked_files
|
135
|
+
|
136
|
+
protected
|
137
|
+
|
138
|
+
def set_default_application_parameters
|
139
|
+
set_default :scm_role, :scm
|
140
|
+
set_default :keep_releases, 3
|
141
|
+
set_default :linked_dirs, []
|
142
|
+
set_default :linked_files, []
|
143
|
+
|
144
|
+
setup_default_application_config_finder
|
145
|
+
end
|
146
|
+
|
147
|
+
def setup_default_application_config_finder
|
148
|
+
config_finder[:application] ||=
|
149
|
+
Luban::Deployment::Helpers::Configuration::Finder.application(self)
|
150
|
+
end
|
151
|
+
|
152
|
+
def validate_application_parameters
|
153
|
+
if application.nil?
|
154
|
+
abort "Aborted! Please specify the application name - application 'app name'"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'luban/cli'
|
2
|
+
|
3
|
+
module Luban
|
4
|
+
module Deployment
|
5
|
+
class Runner < Luban::CLI::Application
|
6
|
+
using Luban::CLI::CoreRefinements
|
7
|
+
include Luban::Deployment::Helpers::Configuration
|
8
|
+
include Luban::Deployment::Parameters::General
|
9
|
+
|
10
|
+
def default_rc
|
11
|
+
@default_rc ||= { 'luban_roles' => %i(app),
|
12
|
+
'luban_root_path' => Parameters::General::DefaultLubanRootPath,
|
13
|
+
'stages' => %w(development staging production),
|
14
|
+
'production_stages' => %w(production)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def lubanfile; @lubanfile ||= 'Lubanfile.rb'; end
|
19
|
+
|
20
|
+
def config_file
|
21
|
+
@config_file ||= work_dir.join(lubanfile)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def on_configure
|
27
|
+
super
|
28
|
+
set_work_dir
|
29
|
+
load_configuration_file(config_file)
|
30
|
+
set_default_parameters
|
31
|
+
load_libraries
|
32
|
+
setup_cli
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_default_parameters
|
36
|
+
%i(luban_roles luban_root_path
|
37
|
+
stages production_stages).each { |p| set_default p, rc[p.to_s] }
|
38
|
+
|
39
|
+
set_default :applications, find_applications
|
40
|
+
set_default :project, File.basename(work_dir)
|
41
|
+
set_default :user, (rc['user'] || ENV['USER'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_applications
|
45
|
+
apps_path.children.select(&:directory?).map(&:basename).map(&:to_s)
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_work_dir
|
49
|
+
project_root = find_lubanfile
|
50
|
+
if project_root.nil?
|
51
|
+
abort "Aborted! NOT a Luban project (or any of the parent directories): #{lubanfile} is NOT found."
|
52
|
+
else
|
53
|
+
work_dir Pathname.new(project_root)
|
54
|
+
apps_path work_dir.join('apps')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def find_lubanfile
|
59
|
+
original = current = Dir.pwd
|
60
|
+
until File.exist?(lubanfile)
|
61
|
+
Dir.chdir('..')
|
62
|
+
return nil if Dir.pwd == current
|
63
|
+
current = Dir.pwd
|
64
|
+
end
|
65
|
+
current
|
66
|
+
ensure
|
67
|
+
Dir.chdir(original)
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_libraries
|
71
|
+
require "#{work_dir}/lib/project"
|
72
|
+
end
|
73
|
+
|
74
|
+
def project_base_class
|
75
|
+
Object.const_get(project.camelcase)
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup_cli
|
79
|
+
version Luban::Deployment::VERSION
|
80
|
+
desc "Manage the deployment of project #{project.camelcase}"
|
81
|
+
setup_projects
|
82
|
+
end
|
83
|
+
|
84
|
+
def setup_projects
|
85
|
+
stages.each { |stg| setup_project(stg) }
|
86
|
+
end
|
87
|
+
|
88
|
+
def setup_project(stg)
|
89
|
+
stg = stg.to_sym
|
90
|
+
commands[stg] = project_class(stg).new(self, stg)
|
91
|
+
end
|
92
|
+
|
93
|
+
def project_class(stg)
|
94
|
+
mod = Object.const_set(stg.camelcase, Module.new)
|
95
|
+
mod.const_set(project.camelcase, Class.new(project_base_class))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Project environment activation resource file for <%= stage %>.<%= project %>/<%= application %>
|
2
|
+
# Revision: <%= revision %>
|
3
|
+
# Created at <%= Time.now().strftime("%d/%m/%Y %H:%M:%S") %>
|
4
|
+
|
5
|
+
echo_line() {
|
6
|
+
if [ "$PS1" ]; then
|
7
|
+
printf "$1\n"
|
8
|
+
fi
|
9
|
+
}
|
10
|
+
|
11
|
+
if [ -n "${LUBAN_ROOT:+x}" ]; then
|
12
|
+
if [[ "$LUBAN_ROOT" == "<%= app_path %>" ]]; then
|
13
|
+
echo_line "Project environment for <%= project %> has ALREADY been activated!"
|
14
|
+
else
|
15
|
+
local current_env=${LUBAN_ROOT##*env/}
|
16
|
+
echo_line "Project environment $current_env is STILL active!"
|
17
|
+
echo_line "Please de-activate it first:"
|
18
|
+
echo_line "\tunset_lubenv $current_env"
|
19
|
+
echo_line "\t\tor"
|
20
|
+
echo_line "\tsource $LUBAN_ROOT/.unset_envrc"
|
21
|
+
fi
|
22
|
+
else
|
23
|
+
LUBAN_ROOT="<%= app_path %>"
|
24
|
+
PATH="$LUBAN_ROOT/bin:$PATH"
|
25
|
+
export LUBAN_ROOT
|
26
|
+
export PATH
|
27
|
+
|
28
|
+
echo_line "Project environment <%= stage %>.<%= project %>/<%= application %> is activated!"
|
29
|
+
fi
|
30
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Project environment de-activation resource file for <%= stage %>.<%= project %>/<%= application %>
|
2
|
+
# Revision: <%= revision %>
|
3
|
+
# Created at <%= Time.now().strftime("%d/%m/%Y %H:%M:%S") %>
|
4
|
+
|
5
|
+
echo_line() {
|
6
|
+
if [ "$PS1" ]; then
|
7
|
+
printf "$1\n"
|
8
|
+
fi
|
9
|
+
}
|
10
|
+
|
11
|
+
if [ -n "${LUBAN_ROOT:+x}" ]; then
|
12
|
+
if [[ "$LUBAN_ROOT" =~ "<%= app_path %>" ]]; then
|
13
|
+
PATH=${PATH//$LUBAN_ROOT\/bin:/}
|
14
|
+
unset LUBAN_ROOT
|
15
|
+
export PATH
|
16
|
+
echo_line "Project environment <%= stage %>.<%= project %>/<%= application %> is de-activated!"
|
17
|
+
else
|
18
|
+
local current_env=${LUBAN_ROOT##*env/}
|
19
|
+
echo_line "ACTUALLY, project environment $curent_env is active!"
|
20
|
+
echo_line "Please run the following command instead to de-activate it:"
|
21
|
+
echo_line "\tunset_lubenv $current_env"
|
22
|
+
echo_line "\t\tor"
|
23
|
+
echo_line "\tsource $LUBAN_ROOT/.unset_envrc"
|
24
|
+
fi
|
25
|
+
else
|
26
|
+
echo_line "Project environment <%= stage %>.<%= project %>/<%= application %> has ALREADY been de-activated!"
|
27
|
+
fi
|
28
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Worker
|
4
|
+
class Base
|
5
|
+
include Luban::Deployment::Helpers::Configuration
|
6
|
+
include Luban::Deployment::Helpers::Utils
|
7
|
+
include Luban::Deployment::Parameters::General
|
8
|
+
include Luban::Deployment::Parameters::Project
|
9
|
+
include Luban::Deployment::Parameters::Application
|
10
|
+
|
11
|
+
attr_reader :task
|
12
|
+
|
13
|
+
def initialize(config:, backend:, **task, &blk)
|
14
|
+
@config = config
|
15
|
+
@backend = backend
|
16
|
+
@run_blk = blk
|
17
|
+
@task = create_task(task)
|
18
|
+
init
|
19
|
+
validate
|
20
|
+
end
|
21
|
+
|
22
|
+
def force?; task.opts.force; end
|
23
|
+
def dry_run?; task.opts.dry_run; end
|
24
|
+
|
25
|
+
def osx?; os_name == 'Darwin'; end
|
26
|
+
def linux?; os_name == 'Linux'; end
|
27
|
+
|
28
|
+
def run
|
29
|
+
update_result(__return__: @run_blk ? run_with_block : run_with_command).to_h
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def create_task(task)
|
35
|
+
Task.new(task).tap { |t| t.result.hostname = hostname }
|
36
|
+
end
|
37
|
+
|
38
|
+
def init; end
|
39
|
+
def validate; end
|
40
|
+
def before_run; end
|
41
|
+
def after_run; end
|
42
|
+
|
43
|
+
def run_with_block
|
44
|
+
before_run
|
45
|
+
r = instance_eval &@run_blk
|
46
|
+
after_run
|
47
|
+
r
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_with_command
|
51
|
+
before_run
|
52
|
+
send("before_#{task.cmd}") if respond_to?("before_#{task.cmd}", true)
|
53
|
+
r = send(task.cmd)
|
54
|
+
send("after_#{task.cmd}") if respond_to?("after_#{task.cmd}", true)
|
55
|
+
after_run
|
56
|
+
r
|
57
|
+
end
|
58
|
+
|
59
|
+
def update_result(message = nil, status: :succeeded, level: :info, **attrs)
|
60
|
+
task.result.tap do |r|
|
61
|
+
r.status = status
|
62
|
+
r.level = level
|
63
|
+
r.message = message unless message.nil?
|
64
|
+
attrs.each_pair { |k, v| r.send("#{k}=", v) }
|
65
|
+
send(level, message) unless message.nil? or message.empty?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|