dply 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ require 'dply/helper'
2
2
  require 'dply/setup'
3
3
  require 'dply/linker'
4
4
  require 'dply/config_downloader'
5
+ require 'dply/yum'
5
6
  require 'forwardable'
6
7
 
7
8
 
@@ -12,41 +13,36 @@ module Dply
12
13
  extend Forwardable
13
14
  include Helper
14
15
 
15
- def_delegators :config, :target, :branch, :link_config,
16
- :config_dir, :config_map, :dir_map, :config_skip_download,
16
+ attr_reader :config, :options
17
+ def_delegators :config, :target, :branch,
18
+ :config_map, :dir_map, :config_skip_download,
17
19
  :config_download_url
18
20
 
19
-
20
- attr_reader :config, :options
21
-
22
21
  def initialize(config, options)
23
22
  @config = config
24
- @options = options
23
+ @options = options || {}
25
24
  end
26
25
 
27
26
  def deploy
28
- setup.run
29
- config_downloader.download_all if config_download_url
27
+ setup.git
28
+ download_configs if config_download_url
30
29
  Dir.chdir current_dir do
31
30
  previous_version = git.commit_id
32
31
  git_step
33
32
  current_version = git.commit_id
34
33
  link_dirs
35
- link_config_files
36
- env = {
37
- "DPLY_PREVIOUS_VERSION" => previous_version,
38
- "DPLY_CURRENT_VERSION" => current_version
39
- }
40
- tasks.deploy target, env: env
34
+ link_config
35
+ yum_install
36
+ tasks.deploy target
37
+ # tasks.report_changes(previous_version, current_version)
41
38
  end
42
39
  end
43
40
 
44
- def switch
45
- end
46
-
47
41
  def reload
48
- config_downloader.download_all if config_download_url
42
+ download_configs if config_download_url
49
43
  Dir.chdir current_dir do
44
+ link_dirs
45
+ link_config_files
50
46
  tasks.reload target
51
47
  end
52
48
  end
@@ -54,7 +50,14 @@ module Dply
54
50
  private
55
51
 
56
52
  def current_dir
57
- @current_dir ||= "#{config.deploy_dir}/current"
53
+ @current_dir ||= "#{config.dir}/current"
54
+ end
55
+
56
+ def download_configs
57
+ files = config_map.values.uniq
58
+ downloader = ConfigDownloader.new(files, config_download_url)
59
+ downloader.skip_download = config_skip_download
60
+ downloader.download_all
58
61
  end
59
62
 
60
63
  def git_step
@@ -66,38 +69,32 @@ module Dply
66
69
  end
67
70
  end
68
71
 
69
- def link_config_files
70
- return if not link_config
71
- logger.bullet "symlinking config files"
72
- config_linker.create_symlinks
72
+ def link_dirs
73
+ link "#{config.dir}/shared", dir_map
73
74
  end
74
75
 
75
- def link_dirs
76
- return if not dir_map
77
- logger.bullet "symlinking shared dirs"
78
- dir_linker.create_symlinks
76
+ def link_config
77
+ link "#{config.dir}/config", config_map
79
78
  end
80
79
 
81
- def config_linker
82
- return @config_linker if @config_linker
83
- source = "#{config.deploy_dir}/config"
84
- dest = current_dir
85
- @config_linker ||= ::Dply::Linker.new(source, dest, map: config_map)
80
+ def yum_install
81
+ Yum.new("pkgs.yml").install
86
82
  end
87
83
 
88
- def config_downloader
89
- @config_downloader = ::Dply::ConfigDownloader.new(config_map.values.uniq, config_download_url, config_skip_download: config_skip_download)
84
+ def setup
85
+ @setup ||= Setup.new(@config)
90
86
  end
91
87
 
92
- def dir_linker
93
- return @dir_linker if @dir_linker
94
- source = "#{config.deploy_dir}/shared"
95
- dest = current_dir
96
- @dir_linker ||= ::Dply::Linker.new(source, dest, map: dir_map)
88
+ def tasks
89
+ @tasks ||= Tasks.new(deployment: true)
97
90
  end
98
91
 
99
- def setup
100
- @setup ||= Setup.load(:git, config)
92
+ def link(source, map)
93
+ return if not map
94
+ logger.bullet "symlinking #{source}"
95
+ dest = current_dir
96
+ linker = Linker.new(source, dest, map: map)
97
+ linker.create_symlinks
101
98
  end
102
99
 
103
100
  end
data/lib/dply/tasks.rb CHANGED
@@ -1,55 +1,52 @@
1
1
  require 'dply/shell'
2
+ require 'dply/bundle'
3
+ require 'json'
2
4
  module Dply
3
5
  class Tasks
4
6
 
5
7
  include Shell
6
8
 
7
- def deploy(target, env:{})
8
- env.merge!(env_from_yml)
9
- bundle_install
10
- cmd "#{rake_command} #{target}:deploy", env: env
9
+ def initialize(deployment: true)
10
+ @deployment = deployment
11
11
  end
12
12
 
13
- def switch(target, env:{})
14
- env.merge!(env_from_yml)
15
- bundle_install
16
- cmd "#{rake_command} #{target}:switch", env: env
13
+ def deploy(target)
14
+ bundle.install
15
+ rake "#{target}:deploy"
17
16
  end
18
17
 
19
18
  def reload(target)
20
- bundle_install
21
- cmd "#{rake_command} #{target}:reload", env: env_from_yml
19
+ bundle.install
20
+ rake "#{target}:reload"
22
21
  end
23
22
 
24
- def gemfile_exists?
25
- File.exists? "Gemfile"
23
+ def task(task)
24
+ bundle.install
25
+ rake task
26
26
  end
27
27
 
28
- def rake_command
29
- if gemfile_exists?
30
- "bundle exec rake -R dply"
31
- else
32
- "rake -R dply"
33
- end
28
+ def build(task)
29
+ bundle.install
30
+ bundle.clean
31
+ rake task
34
32
  end
35
33
 
36
- def bundle_install
37
- return if not gemfile_exists?
38
- exitstatus = system "bundle check > /dev/null"
39
- return if exitstatus
40
- cmd "bundle install"
34
+ def rake(task)
35
+ bundle.rake task
41
36
  end
42
37
 
43
- def env_from_yml
44
- path = "config/env.yml"
45
- if not File.readable? path
46
- logger.debug "skipped loading env from #{path}"
47
- return {}
48
- end
49
- require 'yaml'
50
- YAML.load_file(path)
38
+ def report_changes(previous_version, current_version)
39
+ info = {}
40
+ info[:current] = current_version
41
+ info[:previous] = previous_version
42
+ logger.remote "#{JSON.dump info}"
51
43
  end
52
44
 
45
+ private
46
+
47
+ def bundle
48
+ @bundle ||= Bundle.new(deployment: @deployment)
49
+ end
53
50
 
54
51
  end
55
52
  end
data/lib/dply/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dply
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/dply/yum.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'dply/helper'
2
+ require 'yaml'
3
+
4
+ module Dply
5
+ class Yum
6
+
7
+ include Helper
8
+
9
+ def initialize(pkgs_yml)
10
+ @pkgs_yml = pkgs_yml
11
+ end
12
+
13
+ def pkgs
14
+ @pkgs ||= load_pkgs
15
+ end
16
+
17
+ def install
18
+ return if installed?
19
+ cmd "sudo -n yum install -y #{not_installed_pkgs.join(' ')}"
20
+ end
21
+
22
+ private
23
+
24
+ def pkgs_str
25
+ pkgs.join " "
26
+ end
27
+
28
+ def not_installed_pkgs
29
+ @not_installed_pkgs ||= query_not_installed
30
+ end
31
+
32
+ def query_not_installed
33
+ return [] if pkgs_str.strip.empty?
34
+ command = "rpm -V --noscripts --nodeps --nofiles #{pkgs_str}"
35
+ matches = `#{command}`.scan(/^package (.*) is not installed$/)
36
+ end
37
+
38
+ def installed?
39
+ not_installed_pkgs.size == 0
40
+ end
41
+
42
+ def load_pkgs
43
+ if not File.readable? @pkgs_yml
44
+ logger.debug "skipping yum pkgs"
45
+ return []
46
+ end
47
+ YAML.load_file(@pkgs_yml)
48
+ rescue => e
49
+ error "error loading pkgs list"
50
+ end
51
+
52
+ end
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeraj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,37 +60,40 @@ files:
60
60
  - docs/stages.rb
61
61
  - dply.gemspec
62
62
  - lib/dply.rb
63
+ - lib/dply/archive.rb
64
+ - lib/dply/build.rb
65
+ - lib/dply/build_config.rb
66
+ - lib/dply/bundle.rb
67
+ - lib/dply/cli/build.rb
63
68
  - lib/dply/cli/deploy.rb
64
69
  - lib/dply/cli/reload.rb
65
70
  - lib/dply/config.rb
66
71
  - lib/dply/config_downloader.rb
72
+ - lib/dply/config_struct.rb
67
73
  - lib/dply/custom_logger.rb
68
- - lib/dply/deploy.rb
69
74
  - lib/dply/dplyr.rb
70
75
  - lib/dply/error.rb
71
76
  - lib/dply/ext/string.rb
72
77
  - lib/dply/git.rb
73
78
  - lib/dply/helper.rb
79
+ - lib/dply/jenkins.rb
74
80
  - lib/dply/linker.rb
75
81
  - lib/dply/lock.rb
76
82
  - lib/dply/logger.rb
77
83
  - lib/dply/release.rb
78
- - lib/dply/reload.rb
79
84
  - lib/dply/remote_task.rb
80
85
  - lib/dply/repo.rb
81
86
  - lib/dply/report.rb
82
87
  - lib/dply/setup.rb
83
- - lib/dply/setup/default.rb
84
- - lib/dply/setup/git.rb
85
- - lib/dply/setup/release.rb
86
88
  - lib/dply/shared_dirs.rb
87
89
  - lib/dply/shell.rb
88
90
  - lib/dply/stages_config.rb
89
91
  - lib/dply/strategy.rb
90
- - lib/dply/strategy/default.rb
92
+ - lib/dply/strategy/archive.rb
91
93
  - lib/dply/strategy/git.rb
92
94
  - lib/dply/tasks.rb
93
95
  - lib/dply/version.rb
96
+ - lib/dply/yum.rb
94
97
  homepage: ''
95
98
  licenses:
96
99
  - MIT
data/lib/dply/deploy.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'dply/strategy'
2
- require 'dply/config'
3
-
4
- module Dply
5
- class Deploy
6
-
7
- attr_reader :deploy_dir, :config
8
- attr_writer :options
9
-
10
- def initialize(deploy_dir, config)
11
- @deploy_dir = deploy_dir
12
- @config = config
13
- end
14
-
15
- def run
16
- strategy.deploy
17
- end
18
-
19
- def strategy
20
- @strategy ||= Strategy.load(config, options)
21
- end
22
-
23
- def options
24
- @options ||= {}
25
- end
26
-
27
-
28
- end
29
- end
data/lib/dply/reload.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'dply/strategy'
2
- require 'dply/config'
3
-
4
- module Dply
5
- class Reload
6
-
7
- attr_reader :deploy_dir, :config
8
- attr_writer :options
9
-
10
- def initialize(deploy_dir, config)
11
- @deploy_dir = deploy_dir
12
- @config = config
13
- end
14
-
15
- def run
16
- strategy.reload
17
- end
18
-
19
- def strategy
20
- @strategy ||= Strategy.load(config, options)
21
- end
22
-
23
- def options
24
- @options ||= {}
25
- end
26
-
27
-
28
- end
29
- end
@@ -1,31 +0,0 @@
1
- require 'fileutils'
2
- require 'dply/helper'
3
- require 'dply/shared_dirs'
4
-
5
- module Dply
6
- module Setup
7
- class Default
8
-
9
- include Helper
10
-
11
- attr_reader :config
12
-
13
- def initialize(config)
14
- @config = config
15
- end
16
-
17
- def run
18
- Dir.chdir config.deploy_dir do
19
- shared_dirs.create
20
- end
21
- end
22
-
23
- private
24
-
25
- def shared_dirs
26
- @shared_dirs ||= SharedDirs.new
27
- end
28
-
29
- end
30
- end
31
- end
@@ -1,52 +0,0 @@
1
- require 'fileutils'
2
- require 'dply/helper'
3
- require 'dply/repo'
4
- require 'dply/shared_dirs'
5
-
6
- module Dply
7
- module Setup
8
- class Git
9
-
10
- include Helper
11
-
12
- attr_reader :config
13
-
14
- def initialize(config)
15
- @config = config
16
- end
17
-
18
- def run
19
- Dir.chdir setup_dir do
20
- repo.create
21
- symlink "repo", "current"
22
- create_dirs
23
- shared_dirs.create_in "shared"
24
- end
25
- end
26
-
27
- private
28
-
29
- def repo
30
- @repo ||= ::Dply::Repo.new(repo_dir, config.repo)
31
- end
32
-
33
- def create_dirs
34
- dirs = ["config", "shared"]
35
- FileUtils.mkdir_p dirs
36
- end
37
-
38
- def shared_dirs
39
- @shared_dirs ||= SharedDirs.new(config.shared_dirs)
40
- end
41
-
42
- def setup_dir
43
- config.deploy_dir
44
- end
45
-
46
- def repo_dir
47
- "#{setup_dir}/repo"
48
- end
49
-
50
- end
51
- end
52
- end