luban 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3bb8577686b082a631040457727ce47b0999543
4
- data.tar.gz: 657f3f393403953ea5606b288f997f212beb4ab3
3
+ metadata.gz: db4f45e199a07e299a540fde6da20ebc35ed9c55
4
+ data.tar.gz: a90ba102ab2eba5b2b11eadd4a4373f18eebdd8e
5
5
  SHA512:
6
- metadata.gz: 7344a5bdf345d666bed583166e90ed40b773fb2f7bdb224102b1d2eefc2de24a270d4b5ae23dbe1eb6fc4a36538ec100d335730134efe25c507474e39b659ff2
7
- data.tar.gz: 960aa2296bb31efdae8025a9180188867b94603871977ca307c3b6ac35540d5e99f993115c0e54b38a34849af9e68595d153e399ba25b81461efa3605db0fe8f
6
+ metadata.gz: beddaa95f8d175de1e33447f14b8eddb8ac7dc49744a39e17da918422364a14749585a1fa74959f46f53f237d25f27a34c7bece75be88f454e9101b2d36d809f
7
+ data.tar.gz: 3b337963512a401009e2500ba0f94e6277b2b3b4dac45e5201fa185cc2e46f2c7e2ad8ec208e4a4efca56d574753252bd7ea35400b6f7095fb6405b942be9cb2
data/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # Change log
2
+
3
+ ## Version 0.3.0 (Apr 12, 2016)
4
+
5
+ Minor enhancements:
6
+ * Changed to download third-party source packages locally to save internet access from app servers
7
+ * Refactored remote and local worker paths
8
+ * Moved build repositories to the last building step
9
+ * Fixed wrong clone path when fetching revision in Rsync strategy
10
+ * Upgrade OpenSSL to 1.0.2g for Git installer
11
+ * Code cleanup
12
+
13
+ ## Version 0.2.0 (Apr 01, 2016)
14
+
15
+ Bug fixes:
16
+ * Removed util method, #md5_for_dir, due to inconsistent hash
17
+ * Upgrade OpenSSL to 1.0.2g for Ruby installer
18
+ * Code cleanup
19
+
20
+ ## Version 0.1.0 (Mar 31, 2016)
21
+
22
+ New features:
23
+ * Configuration DSL to support environment setup
24
+ * Command-line interface to run Luban project
25
+ * Installer to install 3rd-party software packages
26
+ * OpenSSL installer
27
+ * YAML installer
28
+ * Git installer
29
+ * Ruby installer
30
+ * Rubygems installer
31
+ * Bundler installer
32
+ * Authenticator to setup passwordless SSH to application servers
33
+ * Builder to setup application environment
34
+ * Repository to manage application source and profile
35
+ * SCM strategy for Git
36
+ * SCM strategy for Rsync
37
+ * Publisher to deploy application release
@@ -64,9 +64,9 @@ module Luban
64
64
  def build(args:, opts:)
65
65
  show_app_environment
66
66
  promptless_authen(args: args, opts: opts)
67
- build_repositories(args: args, opts: opts)
68
67
  build!(args: args, opts: opts)
69
68
  install_all(args: args, opts: opts)
69
+ build_repositories(args: args, opts: opts)
70
70
  end
71
71
 
72
72
  def destroy(args:, opts:)
@@ -1,7 +1,9 @@
1
1
  module Luban
2
2
  module Deployment
3
3
  class Application
4
- class Builder < Luban::Deployment::Worker::Remote
4
+ class Builder < Luban::Deployment::Worker::Base
5
+ include Luban::Deployment::Worker::Paths::Remote
6
+
5
7
  def envrc_template_file
6
8
  @envrc_template_file ||= find_template_file("envrc.erb")
7
9
  end
@@ -39,8 +41,8 @@ module Luban
39
41
  protected
40
42
 
41
43
  def bootstrap
42
- assure_dirs(etc_path, tmp_path,
43
- app_bin_path, app_tmp_path,
44
+ assure_dirs(etc_path, tmp_path, downloads_path,
45
+ app_bin_path, app_tmp_path,
44
46
  releases_path, shared_path)
45
47
  assure_linked_dirs
46
48
  end
@@ -1,7 +1,9 @@
1
1
  module Luban
2
2
  module Deployment
3
3
  class Application
4
- class Publisher < Luban::Deployment::Worker::Remote
4
+ class Publisher < Luban::Deployment::Worker::Base
5
+ include Luban::Deployment::Worker::Paths::Remote
6
+
5
7
  def release_name; task.opts.release[:name]; end
6
8
  def release_tag; task.opts.release[:tag]; end
7
9
  def release_package_path; task.opts.release[:path]; end
@@ -1,8 +1,9 @@
1
1
  module Luban
2
2
  module Deployment
3
3
  class Application
4
- class Repository < Luban::Deployment::Worker::Local
4
+ class Repository < Luban::Deployment::Worker::Base
5
5
  using Luban::CLI::CoreRefinements
6
+ include Luban::Deployment::Worker::Paths::Local
6
7
 
7
8
  DefaultRevisionSize = 12
8
9
 
@@ -20,7 +20,7 @@ module Luban
20
20
 
21
21
  def fetch_revision
22
22
  # Use MD5 as the revision
23
- capture(:tar, "-cf - #{dir} 2>/dev/null | openssl md5")[0, rev_size]
23
+ capture(:tar, "-cf - #{clone_path} 2>/dev/null | openssl md5")[0, rev_size]
24
24
  end
25
25
 
26
26
  def clone
@@ -64,7 +64,7 @@ module Luban
64
64
  end
65
65
 
66
66
  module Deploy
67
- %i(deploy rollback).each do |action|
67
+ %i(deploy).each do |action|
68
68
  define_method(action) do |args:, opts:|
69
69
  raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
70
70
  end
@@ -90,11 +90,19 @@ module Luban
90
90
 
91
91
  def versions; package_options.keys; end
92
92
 
93
- %i(install uninstall cleanup_all update_binstubs
93
+ define_task_method("download_package", task: :download, worker: :installer, locally: true)
94
+ define_task_method("install_package", task: :install, worker: :installer)
95
+
96
+ %i(uninstall cleanup_all update_binstubs
94
97
  get_summary which_current whence_origin).each do |m|
95
98
  define_task_method(m, worker: :installer)
96
99
  end
97
100
 
101
+ def install(args:, opts:)
102
+ md5 = download_package(args: args, opts: opts)[:md5]
103
+ install_package(args: args, opts: opts.merge(src_file_md5: md5))
104
+ end
105
+
98
106
  def install_all(args:, opts:)
99
107
  versions.each do |v|
100
108
  install(args: args, opts: opts.merge(version: v))
@@ -4,6 +4,8 @@ module Luban
4
4
  class Installer
5
5
  class InstallFailure < Luban::Deployment::Error; end
6
6
 
7
+ def src_file_md5; task.opts.src_file_md5; end
8
+
7
9
  def required_packages
8
10
  @required_packages ||=
9
11
  self.class.package_class(package_name).
@@ -18,20 +20,45 @@ module Luban
18
20
  raise NotImplementedError, "#{self.class.name}#installed? is an abstract method."
19
21
  end
20
22
 
23
+ def downloaded?
24
+ file?(src_file_path)
25
+ end
26
+
27
+ def cached?
28
+ file?(src_cache_path)
29
+ end
30
+
21
31
  def validate_download_url
22
32
  info "Validating download URL for #{package_full_name}"
23
33
  validate_download_url!
24
34
  end
25
35
 
36
+ def download
37
+ info "Downloading #{package_full_name}"
38
+ if downloaded?
39
+ update_result "Skipped! #{package_full_name} has been downloaded ALREADY.",
40
+ status: :skipped, md5: md5_for_file(src_file_path)
41
+ else
42
+ download_package!
43
+ if downloaded?
44
+ update_result "Successfully downloaded #{package_full_name}.",
45
+ md5: md5_for_file(src_file_path)
46
+ else
47
+ update_result "Failed to download #{package_full_name}. " +
48
+ "Please check install log for details: #{install_log_file_path}",
49
+ status: :failed, level: :error
50
+ end
51
+ end
52
+ end
53
+
26
54
  def install
27
55
  info "Installing #{package_full_name}"
28
56
  if installed?
29
57
  if force?
30
58
  install!
31
59
  else
32
- update_result "Skipped! #{package_full_name} has been installed ALREADY.",
33
- status: :skipped
34
- return
60
+ return update_result("Skipped! #{package_full_name} has been installed ALREADY.",
61
+ status: :skipped)
35
62
  end
36
63
  else
37
64
  install!
@@ -146,17 +173,21 @@ module Luban
146
173
 
147
174
  protected
148
175
 
149
- def before_install
150
- bootstrap
151
- unless installed? or file?(src_file_path)
176
+ def before_download
177
+ unless downloaded?
178
+ bootstrap_download
152
179
  validate_download_url
153
180
  end
181
+ end
182
+
183
+ def before_install
184
+ bootstrap_install unless installed?
154
185
  install_required_packages(:before_install)
155
186
  end
156
187
 
157
188
  def after_install
158
189
  install_required_packages(:after_install)
159
- update_binstubs!
190
+ update_binstubs
160
191
  end
161
192
 
162
193
  def install_required_packages(type)
@@ -177,7 +208,7 @@ module Luban
177
208
  end
178
209
 
179
210
  def install!
180
- download_package
211
+ upload_package
181
212
  uncompress_package
182
213
  assure_dirs(build_path)
183
214
  within build_path do
@@ -252,33 +283,45 @@ module Luban
252
283
  end
253
284
  end
254
285
 
255
- def bootstrap
256
- assure_dirs(etc_path, tmp_path, app_bin_path, install_path, install_log_path)
286
+ def bootstrap_download
287
+ assure_dirs(package_downloads_path)
257
288
  end
258
289
 
259
- def download_package
260
- info "Downloading #{package_full_name} source package"
261
- if file?(src_file_path)
262
- info "#{package_full_name} is downloaded ALREADY"
263
- else
264
- download_package!
265
- end
290
+ def bootstrap_install
291
+ assure_dirs(etc_path, tmp_path, app_bin_path, install_path, install_log_path)
266
292
  end
267
293
 
268
294
  def download_package!
269
- unless test("curl -L -o #{src_file_path} #{download_url} >> #{install_log_file_path} 2>&1")
295
+ unless test(:curl, "-L -o #{src_file_path} #{download_url}")
270
296
  rm(src_file_path)
271
297
  abort_action('download')
272
298
  end
273
299
  end
274
300
 
301
+ def upload_package
302
+ info "Uploading #{package_full_name} source package"
303
+ if file?(src_cache_path)
304
+ info "#{package_full_name} is uploaded ALREADY"
305
+ else
306
+ upload_package!
307
+ end
308
+ end
309
+
310
+ def upload_package!
311
+ upload!(src_file_path.to_s, src_cache_path.to_s)
312
+ unless md5_matched?(src_cache_path, src_file_md5)
313
+ rm(src_cache_path)
314
+ abort_action('upload')
315
+ end
316
+ end
317
+
275
318
  def uncompress_package
276
319
  info "Uncompressing #{package_full_name} source package"
277
320
  uncompress_package!
278
321
  end
279
322
 
280
323
  def uncompress_package!
281
- unless test("tar -xzf #{src_file_path} -C #{package_tmp_path} >> #{install_log_file_path} 2>&1")
324
+ unless test("tar -xzf #{src_cache_path} -C #{package_tmp_path} >> #{install_log_file_path} 2>&1")
282
325
  abort_action('uncompress')
283
326
  end
284
327
  end
@@ -12,40 +12,28 @@ module Luban
12
12
  @src_file_extname ||= DefaultSrcFileExtName
13
13
  end
14
14
 
15
- def src_file_path
16
- @src_file_path ||= tmp_path.join(src_file_name)
15
+ def src_cache_path
16
+ @src_cache_path ||= tmp_path.join(src_file_name)
17
17
  end
18
18
 
19
- def source_repo
20
- raise NotImplementedError, "#{self.class.name}#source_repo is an abstract method."
21
- end
22
-
23
- def download_from_source?
24
- lubhub_repo.nil?
25
- end
26
-
27
- def download_from_lubhub?
28
- !lubhub_repo.nil?
19
+ def src_file_path
20
+ @src_file_path ||= package_downloads_path.join(src_file_name)
29
21
  end
30
22
 
31
- def download_repo
32
- @download_repo ||= download_from_source? ? source_repo : lubhub_repo
23
+ def source_repo
24
+ raise NotImplementedError, "#{self.class.name}#source_repo is an abstract method."
33
25
  end
34
26
 
35
27
  def source_url_root
36
28
  raise NotImplementedError, "#{self.class.name}#source_url_root is an abstract method."
37
29
  end
38
30
 
39
- def download_url_root
40
- @download_url_root ||= download_from_source? ? source_url_root : package_name
41
- end
42
-
43
31
  def download_url
44
- @download_url ||= File.join(download_repo, download_url_root, src_file_name)
32
+ @download_url ||= File.join(source_repo, source_url_root, src_file_name)
45
33
  end
46
34
 
47
35
  def install_path
48
- @install_path ||= package_path.join('versions', package_version)
36
+ @install_path ||= package_versions_path.join(package_version)
49
37
  end
50
38
 
51
39
  def bin_path
@@ -1,7 +1,9 @@
1
1
  module Luban
2
2
  module Deployment
3
3
  module Package
4
- class Worker < Luban::Deployment::Worker::Remote
4
+ class Worker < Luban::Deployment::Worker::Base
5
+ include Luban::Deployment::Worker::Paths::Remote
6
+
5
7
  class << self
6
8
  def package_class(package)
7
9
  Luban::Deployment::Package::Base.package_class(package)
@@ -34,9 +36,17 @@ module Luban
34
36
  @package_path ||= luban_install_path.join('pkg', package_name)
35
37
  end
36
38
 
39
+ def package_versions_path
40
+ @package_versions_path ||= package_path.join('versions')
41
+ end
42
+
37
43
  def package_tmp_path
38
44
  @package_tmp_path ||= package_path.join('tmp')
39
45
  end
46
+
47
+ def package_downloads_path
48
+ @package_downloads_path ||= downloads_path.join(package_name)
49
+ end
40
50
  end
41
51
  end
42
52
  end
@@ -72,7 +72,7 @@ module Luban
72
72
  install_opts = ['--local']
73
73
  install_opts << "--no-document" unless install_doc?
74
74
  test("#{gem_executable} uninstall bundler -a -x -I >> #{install_log_file_path} 2>&1") and
75
- test("#{gem_executable} install #{install_opts.join(' ')} #{src_file_path} >> #{install_log_file_path} 2>&1")
75
+ test("#{gem_executable} install #{install_opts.join(' ')} #{src_cache_path} >> #{install_log_file_path} 2>&1")
76
76
  end
77
77
  end
78
78
  end
@@ -4,7 +4,7 @@ module Luban
4
4
  class Git < Luban::Deployment::Package::Binary
5
5
  apply_to :all do
6
6
  before_install do
7
- depend_on 'openssl', version: '1.0.2e'
7
+ depend_on 'openssl', version: '1.0.2g'
8
8
  end
9
9
  end
10
10
 
@@ -58,7 +58,7 @@ module Luban
58
58
  luban_root_path Pathname.new(luban_root_path)
59
59
  end
60
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')"
61
+ abort "Aborted! Luban root path should be a String or a Pathname: luban_root_path Pathname.new('#{DefaultLubanRootPath}')"
62
62
  end
63
63
  end
64
64
  end
@@ -70,9 +70,6 @@ module Luban
70
70
 
71
71
  parameter :process_monitor
72
72
  parameter :process_monitor_env
73
- parameter :lubhub_protocol
74
- parameter :lubhub_host
75
- parameter :lubhub_port
76
73
 
77
74
  parameter :sshkit_backend
78
75
  parameter :authen_key_type
@@ -82,26 +79,11 @@ module Luban
82
79
  parameter :pty
83
80
  parameter :connection_timeout
84
81
  parameter :ssh_options
85
- parameter :shell_setup
86
82
  parameter :use_sudo
87
83
 
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
84
  protected
101
85
 
102
86
  def set_default_project_parameters
103
- set_default :lubhub_protocol, 'http'
104
- set_default :lubhub_port, 8080
105
87
  set_default :sshkit_backend, SSHKit::Backend::Netssh
106
88
  set_default :authen_key_type, 'rsa'
107
89
  set_default :default_env, { path: '$PATH:/usr/local/bin' }
@@ -110,7 +92,6 @@ module Luban
110
92
  set_default :pty, false
111
93
  set_default :connection_timeout, 30 # second
112
94
  set_default :ssh_options, {}
113
- set_default :shell_setup, 'bash -l' # Use Bash interactive shell by default
114
95
  set_default :use_sudo, false # Turn off sudo by default
115
96
 
116
97
  setup_default_project_config_finder
@@ -1,5 +1,5 @@
1
1
  module Luban
2
2
  module Deployment
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,75 @@
1
+ module Luban
2
+ module Deployment
3
+ module Worker
4
+ module Paths
5
+ module Local
6
+ def project_path
7
+ @project_path ||= work_dir
8
+ end
9
+
10
+ def apps_path
11
+ @apps_path ||= project_path.join('apps')
12
+ end
13
+
14
+ def app_path
15
+ @app_path ||= apps_path.join(application)
16
+ end
17
+ end
18
+
19
+ module Remote
20
+ def env_path
21
+ @env_path ||= luban_root_path.join('env')
22
+ end
23
+
24
+ def etc_path
25
+ @etc_path ||= luban_root_path.join('etc')
26
+ end
27
+
28
+ def tmp_path
29
+ @tmp_path ||= luban_root_path.join('tmp')
30
+ end
31
+
32
+ def downloads_path
33
+ @downloads_path ||= luban_root_path.join('downloads')
34
+ end
35
+
36
+ def project_path
37
+ @project_path ||= env_path.join("#{stage}.#{project}")
38
+ end
39
+
40
+ def app_path
41
+ @app_path ||= project_path.join(application)
42
+ end
43
+
44
+ def app_bin_path
45
+ @app_bin_path ||= app_path.join('bin')
46
+ end
47
+
48
+ def app_tmp_path
49
+ @app_tmp_path ||= app_path.join('tmp')
50
+ end
51
+
52
+ def releases_path
53
+ @releases_path ||= app_path.join('releases')
54
+ end
55
+
56
+ def shared_path
57
+ @shared_path ||= app_path.join('shared')
58
+ end
59
+
60
+ def envrc_file
61
+ @envrc_file ||= app_path.join(".envrc")
62
+ end
63
+
64
+ def unset_envrc_file
65
+ @unset_envrc_file ||= app_path.join(".unset_envrc")
66
+ end
67
+
68
+ def luban_install_path
69
+ @luban_install_path ||= project_path.join('.luban')
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,4 +1,3 @@
1
1
  require_relative 'worker/task'
2
2
  require_relative 'worker/base'
3
- require_relative 'worker/local'
4
- require_relative 'worker/remote'
3
+ require_relative 'worker/paths'
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.2.0
4
+ version: 0.3.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-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: luban-cli
@@ -89,6 +89,7 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
@@ -142,9 +143,7 @@ files:
142
143
  - lib/luban/deployment/version.rb
143
144
  - lib/luban/deployment/worker.rb
144
145
  - lib/luban/deployment/worker/base.rb
145
- - lib/luban/deployment/worker/controller.rb
146
- - lib/luban/deployment/worker/local.rb
147
- - lib/luban/deployment/worker/remote.rb
146
+ - lib/luban/deployment/worker/paths.rb
148
147
  - lib/luban/deployment/worker/task.rb
149
148
  - luban.gemspec
150
149
  homepage: https://github.com/lubanrb/luban
@@ -1,11 +0,0 @@
1
- module Luban
2
- module Deployment
3
- module Worker
4
- class Controller < Base
5
- def bin_path
6
- @bin_path ||= install_path.join('bin')
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- module Luban
2
- module Deployment
3
- module Worker
4
- class Local < Base
5
- def project_path
6
- @project_path ||= work_dir
7
- end
8
-
9
- def apps_path
10
- @apps_path ||= project_path.join('apps')
11
- end
12
-
13
- def app_path
14
- @app_path ||= apps_path.join(application)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,55 +0,0 @@
1
- module Luban
2
- module Deployment
3
- module Worker
4
- class Remote < Base
5
- def env_path
6
- @env_path ||= luban_root_path.join('env')
7
- end
8
-
9
- def etc_path
10
- @etc_path ||= luban_root_path.join('etc')
11
- end
12
-
13
- def tmp_path
14
- @tmp_path ||= luban_root_path.join('tmp')
15
- end
16
-
17
- def project_path
18
- @project_path ||= env_path.join("#{stage}.#{project}")
19
- end
20
-
21
- def app_path
22
- @app_path ||= project_path.join(application)
23
- end
24
-
25
- def app_bin_path
26
- @app_bin_path ||= app_path.join('bin')
27
- end
28
-
29
- def app_tmp_path
30
- @app_tmp_path ||= app_path.join('tmp')
31
- end
32
-
33
- def releases_path
34
- @releases_path ||= app_path.join('releases')
35
- end
36
-
37
- def shared_path
38
- @shared_path ||= app_path.join('shared')
39
- end
40
-
41
- def luban_install_path
42
- @luban_install_path ||= project_path.join('.luban')
43
- end
44
-
45
- def envrc_file
46
- @envrc_file ||= app_path.join(".envrc")
47
- end
48
-
49
- def unset_envrc_file
50
- @unset_envrc_file ||= app_path.join(".unset_envrc")
51
- end
52
- end
53
- end
54
- end
55
- end