luban 0.4.4 → 0.5.0
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/CHANGELOG.md +12 -0
- data/lib/luban/deployment/cli/application/base.rb +23 -0
- data/lib/luban/deployment/cli/command.rb +2 -2
- data/lib/luban/deployment/cli/project.rb +23 -2
- data/lib/luban/deployment/cli/service/base.rb +30 -1
- data/lib/luban/deployment/helpers/configuration.rb +3 -3
- data/lib/luban/deployment/helpers/generator.rb +134 -0
- data/lib/luban/deployment/helpers.rb +2 -1
- data/lib/luban/deployment/runner.rb +24 -5
- data/lib/luban/deployment/templates/application/config/deploy/__stage/packages/.gitkeep +0 -0
- data/lib/luban/deployment/templates/application/config/deploy/__stage/profile/.gitkeep +0 -0
- data/lib/luban/deployment/templates/application/config/deploy/__stage/templates/.gitkeep +0 -0
- data/lib/luban/deployment/templates/application/config/deploy/__stage.rb.erb +4 -0
- data/lib/luban/deployment/templates/application/config/deploy.rb.erb +1 -0
- data/lib/luban/deployment/templates/application/config/templates/profile/.gitkeep +0 -0
- data/lib/luban/deployment/templates/application/lib/application.rb.erb +4 -0
- data/lib/luban/deployment/templates/project/CHANGELOG.md.erb +6 -0
- data/lib/luban/deployment/templates/project/Gemfile +3 -0
- data/lib/luban/deployment/templates/project/LICENSE.txt.erb +21 -0
- data/lib/luban/deployment/templates/project/Lubanfile.rb.erb +1 -0
- data/lib/luban/deployment/templates/project/README.md.erb +4 -0
- data/lib/luban/deployment/templates/project/apps/.gitkeep +0 -0
- data/lib/luban/deployment/templates/project/config/deploy/__stage.rb.erb +1 -0
- data/lib/luban/deployment/templates/project/config/deploy.rb.erb +4 -0
- data/lib/luban/deployment/templates/project/config/templates/.gitkeep +0 -0
- data/lib/luban/deployment/templates/project/lib/project.rb.erb +3 -0
- data/lib/luban/deployment/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03a9c57a554704d306e2a27b7e7275d3f40597aa
|
4
|
+
data.tar.gz: 0daf44cc27a95855104af6c961e7fde2955c5e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a7b0b50e21b604f2309086267db37960632dd69783e12aa3f0a844e19417c0825260d1a20cd8b1bb7344f146a3c9313a1641e68e4bf506e2dff1fb5bd9db0c8
|
7
|
+
data.tar.gz: 5af9a462115a938ef504bcd38d78732fa3bd95ea773a2e4e8a8ce900ab472004aacab5802a6fb4652e65ea202738880dcab879d5e683d5761dfdc9b87becc3d7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## Version 0.5.0 (Jun 22, 2016)
|
4
|
+
|
5
|
+
Minor enhancements:
|
6
|
+
* Added a series of subcommands, #init to
|
7
|
+
* Initialize a Luban deployment project
|
8
|
+
* Initialize a Luban deployment application
|
9
|
+
* Initialize a Luban deployment service
|
10
|
+
* Added deployment project and application skeleton and templates
|
11
|
+
|
12
|
+
Bug fixes:
|
13
|
+
* Corrected the checking for profile existence for a deployment application/service
|
14
|
+
|
3
15
|
## Version 0.4.4 (Jun 17, 2016)
|
4
16
|
|
5
17
|
Bug fixes:
|
@@ -116,6 +116,14 @@ module Luban
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
def init_services(args:, opts:)
|
120
|
+
show_app_environment
|
121
|
+
service = args[:service]
|
122
|
+
(service.nil? ? services.values : [services[service]]).each do |s|
|
123
|
+
s.init_service(args: args, opts: opts)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
119
127
|
protected
|
120
128
|
|
121
129
|
def set_parameters
|
@@ -157,6 +165,21 @@ module Luban
|
|
157
165
|
long_desc "Manage the deployment of application #{display_name} in #{parent.class.name}"
|
158
166
|
end
|
159
167
|
|
168
|
+
def setup_tasks
|
169
|
+
setup_init_services
|
170
|
+
super
|
171
|
+
end
|
172
|
+
|
173
|
+
def setup_init_services
|
174
|
+
return unless has_services?
|
175
|
+
service_names = services.keys
|
176
|
+
command :init do
|
177
|
+
desc 'Initialize deployment services'
|
178
|
+
argument :service, 'Service name', within: service_names, required: false, type: :symbol
|
179
|
+
action! :init_services
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
160
183
|
def show_app_environment
|
161
184
|
puts "#{display_name} in #{parent.class.name}"
|
162
185
|
end
|
@@ -57,13 +57,13 @@ module Luban
|
|
57
57
|
|
58
58
|
task :which do
|
59
59
|
desc "Show the real path for the given executable"
|
60
|
-
argument :executable, "Executable to which"
|
60
|
+
argument :executable, "Executable to which"
|
61
61
|
action! :which
|
62
62
|
end
|
63
63
|
|
64
64
|
task :whence do
|
65
65
|
desc "List packages with the given executable"
|
66
|
-
argument :executable, "Executable to whence"
|
66
|
+
argument :executable, "Executable to whence"
|
67
67
|
action! :whence
|
68
68
|
end
|
69
69
|
end
|
@@ -62,6 +62,12 @@ module Luban
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
def init_application(args:, opts:)
|
66
|
+
singleton_class.send(:include, Luban::Deployment::Helpers::Generator::Application)
|
67
|
+
define_singleton_method(:application) { args[:application] }
|
68
|
+
create_application_skeleton
|
69
|
+
end
|
70
|
+
|
65
71
|
protected
|
66
72
|
|
67
73
|
def validate_parameters
|
@@ -80,7 +86,7 @@ module Luban
|
|
80
86
|
|
81
87
|
def load_libraries
|
82
88
|
applications.each do |app|
|
83
|
-
require "#{
|
89
|
+
require "#{apps_path}/#{app}/lib/application"
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
@@ -90,6 +96,7 @@ module Luban
|
|
90
96
|
|
91
97
|
def setup_cli
|
92
98
|
setup_applications
|
99
|
+
setup_init_application
|
93
100
|
super
|
94
101
|
end
|
95
102
|
|
@@ -100,9 +107,23 @@ module Luban
|
|
100
107
|
def setup_applications
|
101
108
|
@apps = {}
|
102
109
|
applications.map(&:to_sym).each do |app|
|
103
|
-
|
110
|
+
if application_initialized?(app)
|
111
|
+
@apps[app] = command(app, base: application_base_class(app))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def setup_init_application
|
117
|
+
command :init do
|
118
|
+
desc 'Initialize a Luban deployment application'
|
119
|
+
argument :application, 'Application name', required: true
|
120
|
+
action! :init_application
|
104
121
|
end
|
105
122
|
end
|
123
|
+
|
124
|
+
def application_initialized?(app)
|
125
|
+
File.file?("#{apps_path}/#{app}/config/deploy/#{stage}.rb")
|
126
|
+
end
|
106
127
|
end
|
107
128
|
end
|
108
129
|
end
|
@@ -24,11 +24,36 @@ module Luban
|
|
24
24
|
end
|
25
25
|
service_action :update_profile, dispatch_to: :configurator, locally: true
|
26
26
|
|
27
|
+
def has_templates?
|
28
|
+
respond_to?(:default_templates_path, true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def init_service(args:, opts:)
|
32
|
+
return unless has_templates?
|
33
|
+
require 'fileutils'
|
34
|
+
puts " Initializing #{name} profile"
|
35
|
+
templates_path = config_finder[:application].profile_templates_path.join(name.to_s)
|
36
|
+
profile_path = config_finder[:application].stage_profile_path.join(name.to_s)
|
37
|
+
[templates_path, profile_path].each { |p| FileUtils.mkdir(p) unless p.directory? }
|
38
|
+
init_templates.each do |src_path|
|
39
|
+
next unless src_path.file?
|
40
|
+
dst_path = (src_path.extname == '.erb' ? templates_path : profile_path).
|
41
|
+
join(src_path.basename)
|
42
|
+
print " - #{dst_path.basename}"
|
43
|
+
if dst_path.file?
|
44
|
+
puts " [skipped]"
|
45
|
+
else
|
46
|
+
FileUtils.cp(src_path, dst_path)
|
47
|
+
puts " [created]"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
27
52
|
protected
|
28
53
|
|
29
54
|
def on_configure
|
30
55
|
super
|
31
|
-
include_default_templates_path if
|
56
|
+
include_default_templates_path if has_templates?
|
32
57
|
end
|
33
58
|
|
34
59
|
def include_default_templates_path
|
@@ -43,6 +68,10 @@ module Luban
|
|
43
68
|
super
|
44
69
|
linked_dirs.push('log', 'pids')
|
45
70
|
end
|
71
|
+
|
72
|
+
def init_templates
|
73
|
+
default_templates_path.children
|
74
|
+
end
|
46
75
|
end
|
47
76
|
end
|
48
77
|
end
|
@@ -107,9 +107,9 @@ module Luban
|
|
107
107
|
def base_path; base_path ||= target.apps_path.join(target.application); end
|
108
108
|
|
109
109
|
def has_profile?
|
110
|
-
stage_profile_templates_path.
|
111
|
-
stage_profile_path.
|
112
|
-
profile_templates_path.
|
110
|
+
!Dir["#{stage_profile_templates_path}/**/*"].empty? or
|
111
|
+
!Dir["#{stage_profile_path}/**/*"].empty? or
|
112
|
+
!Dir["#{profile_templates_path}/**/*"].empty?
|
113
113
|
end
|
114
114
|
|
115
115
|
def find_template_file(file_name)
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Luban
|
4
|
+
module Deployment
|
5
|
+
module Helpers
|
6
|
+
module Generator
|
7
|
+
using Luban::CLI::CoreRefinements
|
8
|
+
|
9
|
+
module Base
|
10
|
+
protected
|
11
|
+
|
12
|
+
def skeletons_path
|
13
|
+
@skeletons_path ||=
|
14
|
+
Pathname.new(__FILE__).dirname.join('..').join('templates').realpath
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_dir(src_path, dst_path, stages: [], depth: 1)
|
18
|
+
indent = ' ' * depth
|
19
|
+
print indent + "- #{dst_path.basename}"
|
20
|
+
mkdir(dst_path)
|
21
|
+
src_files = []
|
22
|
+
src_path.each_child do |p|
|
23
|
+
if p.directory?
|
24
|
+
if placeholder?(p.basename)
|
25
|
+
stages.each do |s|
|
26
|
+
copy_dir(p, dst_path.join(staged_basename(s, p.basename)), depth: depth + 1)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
copy_dir(p, dst_path.join(p.basename), stages: stages, depth: depth + 1)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
src_files << p
|
33
|
+
end
|
34
|
+
end
|
35
|
+
src_files.each do |f|
|
36
|
+
basename = f.basename
|
37
|
+
action = :copy_file
|
38
|
+
if basename.extname == '.erb'
|
39
|
+
basename = basename.sub_ext('')
|
40
|
+
action = :render_file
|
41
|
+
end
|
42
|
+
if placeholder?(basename)
|
43
|
+
stages.each do |stage|
|
44
|
+
n = staged_basename(stage, basename)
|
45
|
+
print indent + " - #{n}"
|
46
|
+
send(action, f, dst_path.join(n), context: binding)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
print indent + " - #{basename}"
|
50
|
+
send(action, f, dst_path.join(basename))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def mkdir(path)
|
56
|
+
if path.directory?
|
57
|
+
puts " [skipped]"
|
58
|
+
else
|
59
|
+
FileUtils.mkdir(path)
|
60
|
+
puts " [created]"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def copy_file(src_path, dst_path)
|
65
|
+
if dst_path.file?
|
66
|
+
puts " [skipped]"
|
67
|
+
else
|
68
|
+
FileUtils.cp(src_path, dst_path)
|
69
|
+
puts " [created]"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_file(template_path, output_path, context: binding)
|
74
|
+
if output_path.file?
|
75
|
+
puts " [skipped]"
|
76
|
+
else
|
77
|
+
require 'erb'
|
78
|
+
File.open(output_path, 'w') do |f|
|
79
|
+
f.write ERB.new(File.read(template_path), nil, '<>').result(context)
|
80
|
+
end
|
81
|
+
puts " [created]"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def placeholder?(basename)
|
86
|
+
basename.to_s =~ /^__stage/
|
87
|
+
end
|
88
|
+
|
89
|
+
def staged_basename(stage, basename)
|
90
|
+
basename.to_s.sub!(/^__stage/, stage)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module Project
|
95
|
+
include Base
|
96
|
+
|
97
|
+
def project_skeleton_path
|
98
|
+
@project_skeleton_path ||= skeletons_path.join('project')
|
99
|
+
end
|
100
|
+
|
101
|
+
def project_target_path
|
102
|
+
@project_target_path ||= (work_dir or Pathname.pwd.join(project))
|
103
|
+
end
|
104
|
+
|
105
|
+
def create_project_skeleton
|
106
|
+
puts "Creating skeleton for project #{project.camelcase}"
|
107
|
+
copy_dir(project_skeleton_path, project_target_path, stages: stages)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module Application
|
112
|
+
include Base
|
113
|
+
|
114
|
+
def application_skeleton_path
|
115
|
+
@application_skeleton_path ||= skeletons_path.join('application')
|
116
|
+
end
|
117
|
+
|
118
|
+
def application_target_path
|
119
|
+
@application_target_path ||= apps_path.join(application)
|
120
|
+
end
|
121
|
+
|
122
|
+
def application_name
|
123
|
+
"#{project}:#{application}".camelcase
|
124
|
+
end
|
125
|
+
|
126
|
+
def create_application_skeleton
|
127
|
+
puts "Creating skeleton for #{stage} application #{application_name}"
|
128
|
+
copy_dir(application_skeleton_path, application_target_path, stages: [stage])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -20,6 +20,12 @@ module Luban
|
|
20
20
|
@config_file ||= work_dir.join(lubanfile)
|
21
21
|
end
|
22
22
|
|
23
|
+
def init_project(args:, opts:)
|
24
|
+
set_default :project, args[:project]
|
25
|
+
singleton_class.send(:include, Luban::Deployment::Helpers::Generator::Project)
|
26
|
+
create_project_skeleton
|
27
|
+
end
|
28
|
+
|
23
29
|
protected
|
24
30
|
|
25
31
|
def on_configure
|
@@ -31,12 +37,14 @@ module Luban
|
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
|
-
def
|
40
|
+
def set_default_common_parameters
|
35
41
|
%i(luban_roles luban_root_path stages).each { |p| set_default p, rc[p.to_s] }
|
42
|
+
set_default :user, (rc['user'] || ENV['USER'])
|
43
|
+
end
|
36
44
|
|
45
|
+
def set_default_project_parameters
|
37
46
|
set_default :applications, find_applications
|
38
47
|
set_default :project, File.basename(work_dir)
|
39
|
-
set_default :user, (rc['user'] || ENV['USER'])
|
40
48
|
end
|
41
49
|
|
42
50
|
def find_applications
|
@@ -73,11 +81,13 @@ module Luban
|
|
73
81
|
|
74
82
|
def setup_cli_with_projects
|
75
83
|
load_configuration_file(config_file)
|
76
|
-
|
84
|
+
set_default_common_parameters
|
85
|
+
set_default_project_parameters
|
77
86
|
load_libraries
|
78
87
|
|
79
88
|
version Luban::Deployment::VERSION
|
80
89
|
desc "Manage the deployment of project #{project.camelcase}"
|
90
|
+
setup_init_project(false)
|
81
91
|
setup_projects
|
82
92
|
end
|
83
93
|
|
@@ -96,10 +106,19 @@ module Luban
|
|
96
106
|
end
|
97
107
|
|
98
108
|
def setup_cli_without_projects
|
109
|
+
set_default_common_parameters
|
110
|
+
|
99
111
|
version Luban::Deployment::VERSION
|
100
112
|
desc "Framework to manage project deployment"
|
101
|
-
|
102
|
-
|
113
|
+
|
114
|
+
setup_init_project
|
115
|
+
end
|
116
|
+
|
117
|
+
def setup_init_project(new_project = true)
|
118
|
+
command :init do
|
119
|
+
desc 'Initialize a Luban deployment project'
|
120
|
+
argument :project, 'Project name', required: true if new_project
|
121
|
+
action! :init_project
|
103
122
|
end
|
104
123
|
end
|
105
124
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Deployment configuration for application <%= application_name %>
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) <%= Time.now.year %> <%= user.capitalize %>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
stages %w(<%= stages.join(' ') %>)
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Deployment configuration for <%= stage %> project <%= project.camelcase %>
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rubyist Lei
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: luban-cli
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/luban/deployment/error.rb
|
135
135
|
- lib/luban/deployment/helpers.rb
|
136
136
|
- lib/luban/deployment/helpers/configuration.rb
|
137
|
+
- lib/luban/deployment/helpers/generator.rb
|
137
138
|
- lib/luban/deployment/helpers/utils.rb
|
138
139
|
- lib/luban/deployment/packages/bundler.rb
|
139
140
|
- lib/luban/deployment/packages/git.rb
|
@@ -143,8 +144,25 @@ files:
|
|
143
144
|
- lib/luban/deployment/packages/yaml.rb
|
144
145
|
- lib/luban/deployment/parameters.rb
|
145
146
|
- lib/luban/deployment/runner.rb
|
147
|
+
- lib/luban/deployment/templates/application/config/deploy.rb.erb
|
148
|
+
- lib/luban/deployment/templates/application/config/deploy/__stage.rb.erb
|
149
|
+
- lib/luban/deployment/templates/application/config/deploy/__stage/packages/.gitkeep
|
150
|
+
- lib/luban/deployment/templates/application/config/deploy/__stage/profile/.gitkeep
|
151
|
+
- lib/luban/deployment/templates/application/config/deploy/__stage/templates/.gitkeep
|
152
|
+
- lib/luban/deployment/templates/application/config/templates/profile/.gitkeep
|
153
|
+
- lib/luban/deployment/templates/application/lib/application.rb.erb
|
146
154
|
- lib/luban/deployment/templates/envrc.erb
|
147
155
|
- lib/luban/deployment/templates/header.erb
|
156
|
+
- lib/luban/deployment/templates/project/CHANGELOG.md.erb
|
157
|
+
- lib/luban/deployment/templates/project/Gemfile
|
158
|
+
- lib/luban/deployment/templates/project/LICENSE.txt.erb
|
159
|
+
- lib/luban/deployment/templates/project/Lubanfile.rb.erb
|
160
|
+
- lib/luban/deployment/templates/project/README.md.erb
|
161
|
+
- lib/luban/deployment/templates/project/apps/.gitkeep
|
162
|
+
- lib/luban/deployment/templates/project/config/deploy.rb.erb
|
163
|
+
- lib/luban/deployment/templates/project/config/deploy/__stage.rb.erb
|
164
|
+
- lib/luban/deployment/templates/project/config/templates/.gitkeep
|
165
|
+
- lib/luban/deployment/templates/project/lib/project.rb.erb
|
148
166
|
- lib/luban/deployment/templates/unset_envrc.erb
|
149
167
|
- lib/luban/deployment/version.rb
|
150
168
|
- lib/luban/deployment/worker.rb
|