dply 0.0.2 → 0.0.5
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/.gitignore +1 -1
- data/bin/drake +15 -3
- data/docs/README +38 -0
- data/docs/dply.rb +23 -0
- data/docs/stages.rb +8 -0
- data/lib/dply/cli/deploy.rb +5 -4
- data/lib/dply/cli/reload.rb +58 -0
- data/lib/dply/config.rb +18 -6
- data/lib/dply/config_downloader.rb +35 -0
- data/lib/dply/deploy.rb +3 -7
- data/lib/dply/dplyr.rb +18 -3
- data/lib/dply/git.rb +6 -0
- data/lib/dply/linker.rb +15 -31
- data/lib/dply/reload.rb +29 -0
- data/lib/dply/remote_task.rb +5 -4
- data/lib/dply/shell.rb +18 -3
- data/lib/dply/stages_config.rb +13 -4
- data/lib/dply/strategy/default.rb +7 -0
- data/lib/dply/strategy/git.rb +24 -4
- data/lib/dply/tasks.rb +22 -4
- data/lib/dply/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6a7c74b1b9d89269d2b64c1a023c52a01d6f69a
|
|
4
|
+
data.tar.gz: a4cd0427ab1c9609a03e628e880d9877fd80bc9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bfd678b1482e99e440dfa89edbcde8d533b3f3883f190e05a63f29d5e61f5be3f571f495924b59856e9d4c6c52a670f22c48a3ef5a78d648911960e620f73f5a
|
|
7
|
+
data.tar.gz: dcfdee4e48b8b322b0dec930765a1f4be090cec5ef7b8e1714ac8de995a6203db1ed8c91fe25db68d3aec8bd7e43ac5b2df3aabb9e2aa4bf4399efbfae47ed16
|
data/.gitignore
CHANGED
data/bin/drake
CHANGED
|
@@ -8,10 +8,13 @@ require 'optparse'
|
|
|
8
8
|
require 'dply/error'
|
|
9
9
|
require 'dply/version'
|
|
10
10
|
require 'dply/logger'
|
|
11
|
+
require 'dply/config'
|
|
11
12
|
require 'pathname'
|
|
12
13
|
|
|
13
14
|
logger = ::Dply::Logger.logger
|
|
14
|
-
options = {
|
|
15
|
+
options = {
|
|
16
|
+
read_config: true
|
|
17
|
+
}
|
|
15
18
|
|
|
16
19
|
opts_parser = OptionParser.new do |opts|
|
|
17
20
|
|
|
@@ -29,7 +32,11 @@ opts_parser = OptionParser.new do |opts|
|
|
|
29
32
|
path = Pathname.new(d)
|
|
30
33
|
raise ::Dply::Error, "deploy_dir path must be absolute" if path.relative?
|
|
31
34
|
options[:deploy_dir] = path
|
|
32
|
-
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
opts.on("--no-config", "Do not read config file") do
|
|
38
|
+
options[:read_config] = false
|
|
39
|
+
end
|
|
33
40
|
|
|
34
41
|
opts.on("-v", "--version", "Show version") do |v|
|
|
35
42
|
puts ::Dply::VERSION
|
|
@@ -57,12 +64,17 @@ begin
|
|
|
57
64
|
opts_parser.order!(ARGV)
|
|
58
65
|
deploy_dir = options[:deploy_dir] || Dir.pwd
|
|
59
66
|
Dir.chdir deploy_dir
|
|
67
|
+
config = Dply::Config.new(deploy_dir, read_config: options[:read_config]).to_struct
|
|
60
68
|
|
|
61
69
|
command = (ARGV.shift || "").to_sym
|
|
62
70
|
case command
|
|
63
71
|
when :deploy
|
|
64
72
|
require 'dply/cli/deploy'
|
|
65
|
-
cli = Dply::Cli::Deploy.new(deploy_dir, ARGV)
|
|
73
|
+
cli = Dply::Cli::Deploy.new(deploy_dir, config, ARGV)
|
|
74
|
+
cli.run
|
|
75
|
+
when :reload
|
|
76
|
+
require 'dply/cli/reload'
|
|
77
|
+
cli = Dply::Cli::Reload.new(deploy_dir, config, ARGV)
|
|
66
78
|
cli.run
|
|
67
79
|
when :''
|
|
68
80
|
puts opts_parser
|
data/docs/README
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
directory structure when app is deployed using dplyr:
|
|
2
|
+
|
|
3
|
+
/srv/app_user/app/
|
|
4
|
+
├── config
|
|
5
|
+
│ └── database.yml
|
|
6
|
+
├── current -> repo
|
|
7
|
+
├── dply.rb
|
|
8
|
+
├── shared
|
|
9
|
+
│ ├── log
|
|
10
|
+
│ ├── public
|
|
11
|
+
│ │ └── assets
|
|
12
|
+
│ └── tmp
|
|
13
|
+
│ ├── pids
|
|
14
|
+
│ └── sockets
|
|
15
|
+
├── repo
|
|
16
|
+
│ ├── app
|
|
17
|
+
│ ├── config
|
|
18
|
+
│ │ └── database.yml -> ../../config/database.yml
|
|
19
|
+
│ ├── config.ru
|
|
20
|
+
│ ├── db
|
|
21
|
+
| ├── dply
|
|
22
|
+
│ ├── Gemfile
|
|
23
|
+
│ ├── Gemfile.lock
|
|
24
|
+
│ ├── lib
|
|
25
|
+
│ ├── log -> ../shared/log
|
|
26
|
+
│ ├── public
|
|
27
|
+
│ │ ├── assets -> ../../shared/public/assets
|
|
28
|
+
│ ├── Rakefile
|
|
29
|
+
│ ├── README.md
|
|
30
|
+
│ ├── README.rdoc
|
|
31
|
+
│ ├── tmp -> ../shared/tmp
|
|
32
|
+
├── shared
|
|
33
|
+
│ ├── log
|
|
34
|
+
│ ├── public
|
|
35
|
+
│ │ └── assets
|
|
36
|
+
│ └── tmp
|
|
37
|
+
│ ├── pids
|
|
38
|
+
│ └── sockets
|
data/docs/dply.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
repo "git@github.com:user/repo.git"
|
|
2
|
+
strategy :git
|
|
3
|
+
target :production
|
|
4
|
+
#create directories in shared/ dir
|
|
5
|
+
shared_dirs [
|
|
6
|
+
"public/assets"
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
# target(relative to repo root) => source(relative to shared/ dir)
|
|
10
|
+
dir_map ({
|
|
11
|
+
"log" => "log",
|
|
12
|
+
"tmp" => "tmp",
|
|
13
|
+
"public/assets" => "public/assets"
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
# target(relative to repo root) => source(relative to config/ dir)
|
|
17
|
+
config_map ({
|
|
18
|
+
"config/database.yml" => "database.yml",
|
|
19
|
+
"config/some_config" => "some_config"
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
config_download_url "http://127.0.0.1/prefix"
|
|
23
|
+
config_skip_download ["some_config"]
|
data/docs/stages.rb
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
stage :production do
|
|
2
|
+
user "dev"
|
|
3
|
+
ask :user # exported to env as DPLY_USER
|
|
4
|
+
deploy_dir "/home/dev/project"
|
|
5
|
+
parallel_runs 1
|
|
6
|
+
host "10.1.1.1", deploy_dir: "/home/dev/project1", id: "project1", user: "dev1"
|
|
7
|
+
host "10.1.1.2", deploy_dir: "/home/dev/project2", id: "project2"
|
|
8
|
+
end
|
data/lib/dply/cli/deploy.rb
CHANGED
|
@@ -8,10 +8,11 @@ module Dply
|
|
|
8
8
|
|
|
9
9
|
include Logger
|
|
10
10
|
|
|
11
|
-
attr_reader :deploy_dir, :argv
|
|
11
|
+
attr_reader :deploy_dir, :argv, :config
|
|
12
12
|
|
|
13
|
-
def initialize(deploy_dir, argv)
|
|
13
|
+
def initialize(deploy_dir, config, argv)
|
|
14
14
|
@deploy_dir = deploy_dir
|
|
15
|
+
@config = config
|
|
15
16
|
@argv = argv
|
|
16
17
|
end
|
|
17
18
|
|
|
@@ -19,13 +20,13 @@ module Dply
|
|
|
19
20
|
lock.acquire
|
|
20
21
|
opts.parse!(argv)
|
|
21
22
|
target = argv.shift
|
|
22
|
-
|
|
23
|
+
config.target = target if target
|
|
23
24
|
deploy.options = options
|
|
24
25
|
deploy.run
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def deploy
|
|
28
|
-
@deploy ||= ::Dply::Deploy.new(deploy_dir)
|
|
29
|
+
@deploy ||= ::Dply::Deploy.new(deploy_dir, config)
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def lock
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'dply/reload'
|
|
2
|
+
require 'dply/logger'
|
|
3
|
+
require 'dply/lock'
|
|
4
|
+
|
|
5
|
+
module Dply
|
|
6
|
+
module Cli
|
|
7
|
+
class Reload
|
|
8
|
+
|
|
9
|
+
include Logger
|
|
10
|
+
|
|
11
|
+
attr_reader :deploy_dir, :argv, :config
|
|
12
|
+
|
|
13
|
+
def initialize(deploy_dir, config, argv)
|
|
14
|
+
@deploy_dir = deploy_dir
|
|
15
|
+
@argv = argv
|
|
16
|
+
@config = config
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
lock.acquire
|
|
21
|
+
opts.parse!(argv)
|
|
22
|
+
target = argv.shift
|
|
23
|
+
config.target = target if target
|
|
24
|
+
reload.options = options
|
|
25
|
+
reload.run
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reload
|
|
29
|
+
@reload ||= ::Dply::Reload.new(deploy_dir, config)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def lock
|
|
33
|
+
@lock ||= ::Dply::Lock.new(deploy_dir)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def opts
|
|
37
|
+
OptionParser.new do |opts|
|
|
38
|
+
|
|
39
|
+
opts.banner = "Usage: dply reload [options] [target]"
|
|
40
|
+
|
|
41
|
+
opts.on("--skip-bundler", "Skip bundle install") do |e|
|
|
42
|
+
options[:skip_bundler] = true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
opts.on("-h", "--help", "Help") do
|
|
46
|
+
puts opts
|
|
47
|
+
exit
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def options
|
|
53
|
+
@options ||= {}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/dply/config.rb
CHANGED
|
@@ -5,11 +5,11 @@ module Dply
|
|
|
5
5
|
class Config
|
|
6
6
|
|
|
7
7
|
include Helper
|
|
8
|
-
attr_reader :deploy_dir, :
|
|
8
|
+
attr_reader :deploy_dir, :read_config
|
|
9
9
|
|
|
10
|
-
def initialize(deploy_dir,
|
|
10
|
+
def initialize(deploy_dir, read_config: true)
|
|
11
11
|
@deploy_dir = deploy_dir
|
|
12
|
-
@
|
|
12
|
+
@read_config = read_config
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def config
|
|
@@ -24,9 +24,11 @@ module Dply
|
|
|
24
24
|
link_config: false,
|
|
25
25
|
config_map: nil,
|
|
26
26
|
dir_map: nil,
|
|
27
|
-
shared_dirs: []
|
|
27
|
+
shared_dirs: [],
|
|
28
|
+
config_skip_download: [],
|
|
29
|
+
config_download_url: nil
|
|
28
30
|
}
|
|
29
|
-
read_from_file
|
|
31
|
+
read_from_file if read_config
|
|
30
32
|
return @config
|
|
31
33
|
end
|
|
32
34
|
|
|
@@ -55,6 +57,16 @@ module Dply
|
|
|
55
57
|
set :config_map, map
|
|
56
58
|
end
|
|
57
59
|
|
|
60
|
+
def config_skip_download(list)
|
|
61
|
+
set :config_skip_download, list
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def config_download_url(url)
|
|
65
|
+
set :config_download_url, url
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
58
70
|
def dir_map(map)
|
|
59
71
|
set :dir_map, map
|
|
60
72
|
end
|
|
@@ -90,7 +102,7 @@ module Dply
|
|
|
90
102
|
|
|
91
103
|
def read_from_file
|
|
92
104
|
if not File.readable? config_file
|
|
93
|
-
raise error "dply.rb not found in #{deploy_dir}"
|
|
105
|
+
raise error "dply.rb not found in #{deploy_dir}"
|
|
94
106
|
return
|
|
95
107
|
end
|
|
96
108
|
instance_eval(File.read(config_file))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'dply/helper'
|
|
2
|
+
module Dply
|
|
3
|
+
class ConfigDownloader
|
|
4
|
+
|
|
5
|
+
include Helper
|
|
6
|
+
attr_accessor :base_url, :config_files, :config_skip_download
|
|
7
|
+
|
|
8
|
+
def initialize(config_files , base_url, secret: nil, config_skip_download: [])
|
|
9
|
+
@config_files = config_files
|
|
10
|
+
@base_url = base_url
|
|
11
|
+
@secret = secret
|
|
12
|
+
@config_skip_download = config_skip_download
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def download_all
|
|
16
|
+
config_files.each do |f|
|
|
17
|
+
if config_skip_download.include? f
|
|
18
|
+
logger.debug "skipping to download file #{f}"
|
|
19
|
+
next
|
|
20
|
+
end
|
|
21
|
+
download f
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def download(file)
|
|
26
|
+
url = "#{base_url}/#{file}"
|
|
27
|
+
logger.bullet "downloading #{file}"
|
|
28
|
+
http_status = `curl -w "%{http_code}" -f -s -o 'config/#{file}' '#{url}' `
|
|
29
|
+
if http_status != "200"
|
|
30
|
+
raise error "failed to download #{file}, http status #{http_status}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/dply/deploy.rb
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
require 'dply/setup'
|
|
2
1
|
require 'dply/strategy'
|
|
3
2
|
require 'dply/config'
|
|
4
3
|
|
|
5
4
|
module Dply
|
|
6
5
|
class Deploy
|
|
7
6
|
|
|
8
|
-
attr_reader :deploy_dir
|
|
7
|
+
attr_reader :deploy_dir, :config
|
|
9
8
|
attr_writer :options
|
|
10
9
|
|
|
11
|
-
def initialize(deploy_dir)
|
|
10
|
+
def initialize(deploy_dir, config)
|
|
12
11
|
@deploy_dir = deploy_dir
|
|
12
|
+
@config = config
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def run
|
|
16
16
|
strategy.deploy
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def config
|
|
20
|
-
@config ||= Config.new(deploy_dir).to_struct
|
|
21
|
-
end
|
|
22
|
-
|
|
23
19
|
def strategy
|
|
24
20
|
@strategy ||= Strategy.load(config, options)
|
|
25
21
|
end
|
data/lib/dply/dplyr.rb
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
require 'dply/stages_config'
|
|
2
2
|
require 'dply/remote_task'
|
|
3
|
+
require 'dply/logger'
|
|
4
|
+
|
|
3
5
|
module Dply
|
|
4
6
|
class Dplyr
|
|
5
7
|
|
|
8
|
+
include Logger
|
|
9
|
+
|
|
6
10
|
attr_reader :stage, :argv
|
|
7
11
|
def initialize(stage, argv)
|
|
8
12
|
@stage = stage
|
|
@@ -10,11 +14,14 @@ module Dply
|
|
|
10
14
|
end
|
|
11
15
|
|
|
12
16
|
def run
|
|
17
|
+
global_switches = []
|
|
18
|
+
global_switches << "--debug" if logger.debug?
|
|
13
19
|
case stage
|
|
14
20
|
when 'dev'
|
|
15
|
-
|
|
21
|
+
global_switches << "--no-config"
|
|
22
|
+
system "drake #{global_switches.join(" ")} #{argv_str}"
|
|
16
23
|
when 'local'
|
|
17
|
-
system "drake #{argv_str}"
|
|
24
|
+
system "drake #{global_switches.join(" ")} #{argv_str}"
|
|
18
25
|
else
|
|
19
26
|
run_remote_task
|
|
20
27
|
end
|
|
@@ -32,12 +39,20 @@ module Dply
|
|
|
32
39
|
stage_data[:parallel_runs]
|
|
33
40
|
end
|
|
34
41
|
|
|
42
|
+
def env_str
|
|
43
|
+
str = ""
|
|
44
|
+
stage_data[:env].each do |k,v|
|
|
45
|
+
str << %(DPLY_#{k.upcase}="#{v}" )
|
|
46
|
+
end
|
|
47
|
+
str
|
|
48
|
+
end
|
|
49
|
+
|
|
35
50
|
def argv_str
|
|
36
51
|
@argv_str ||= argv.join(' ')
|
|
37
52
|
end
|
|
38
53
|
|
|
39
54
|
def run_remote_task
|
|
40
|
-
remote_task = ::Dply::RemoteTask.new(hosts, argv_str, parallel_jobs: parallel_jobs)
|
|
55
|
+
remote_task = ::Dply::RemoteTask.new(hosts, argv_str, parallel_jobs: parallel_jobs, env: env_str)
|
|
41
56
|
remote_task.run
|
|
42
57
|
end
|
|
43
58
|
|
data/lib/dply/git.rb
CHANGED
data/lib/dply/linker.rb
CHANGED
|
@@ -4,52 +4,36 @@ module Dply
|
|
|
4
4
|
|
|
5
5
|
include Helper
|
|
6
6
|
|
|
7
|
-
attr_reader :src_dir, :dest_dir, :map
|
|
7
|
+
attr_reader :src_dir, :dest_dir, :map
|
|
8
8
|
|
|
9
|
-
def initialize(src_dir, dest_dir, map:
|
|
9
|
+
def initialize(src_dir, dest_dir, map: {})
|
|
10
10
|
verify_absolute src_dir, dest_dir
|
|
11
11
|
@src_dir = src_dir
|
|
12
12
|
@dest_dir = dest_dir
|
|
13
13
|
@map = map
|
|
14
|
-
@dir_prefix = dir_prefix
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def create_symlinks
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
logger.debug "linking #{
|
|
23
|
-
symlink(
|
|
17
|
+
mapped_files.each do |f|
|
|
18
|
+
target = link_target(f)
|
|
19
|
+
source = link_source(f)
|
|
20
|
+
relative_source = link_relative_source(source, target)
|
|
21
|
+
logger.debug "linking #{target} -> #{source}"
|
|
22
|
+
symlink(relative_source, target)
|
|
24
23
|
end
|
|
25
24
|
end
|
|
26
25
|
|
|
27
|
-
def
|
|
28
|
-
|
|
26
|
+
def link_target(relative_target)
|
|
27
|
+
Pathname.new "#{dest_dir}/#{relative_target}"
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
def
|
|
32
|
-
|
|
30
|
+
def link_source(relative_target)
|
|
31
|
+
relative_source = map[relative_target]
|
|
32
|
+
Pathname.new "#{src_dir}/#{relative_source}"
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def
|
|
36
|
-
target
|
|
37
|
-
Pathname.new "#{dest_dir}/#{target}"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def absolute_source_path(src)
|
|
41
|
-
Pathname.new "#{src_dir}/#{src}"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def default_map
|
|
46
|
-
@h ||= Hash.new do |hash, key|
|
|
47
|
-
dir_prefix ? "#{dir_prefix}/#{key}" : "#{key}"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def all_files
|
|
52
|
-
Dir.chdir(src_dir) { Dir.glob("*") }
|
|
35
|
+
def link_relative_source(source, target)
|
|
36
|
+
source.relative_path_from target.parent
|
|
53
37
|
end
|
|
54
38
|
|
|
55
39
|
def mapped_files
|
data/lib/dply/reload.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
data/lib/dply/remote_task.rb
CHANGED
|
@@ -7,12 +7,13 @@ module Dply
|
|
|
7
7
|
|
|
8
8
|
include Logger
|
|
9
9
|
|
|
10
|
-
attr_reader :hosts, :parallel_jobs, :task
|
|
10
|
+
attr_reader :hosts, :parallel_jobs, :task, :env
|
|
11
11
|
|
|
12
|
-
def initialize(hosts, task, parallel_jobs: 1)
|
|
12
|
+
def initialize(hosts, task, parallel_jobs: 1, env: "")
|
|
13
13
|
@hosts = hosts
|
|
14
14
|
@parallel_jobs = parallel_jobs
|
|
15
15
|
@task = task
|
|
16
|
+
@env = env
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def run
|
|
@@ -78,9 +79,9 @@ module Dply
|
|
|
78
79
|
host = host_info[:host]
|
|
79
80
|
deploy_dir = host_info[:deploy_dir]
|
|
80
81
|
if logger.debug?
|
|
81
|
-
%(ssh -tt -oBatchMode=yes -l #{user} #{host} "drake --debug -d #{deploy_dir} #{task} 2>&1")
|
|
82
|
+
%(ssh -tt -oBatchMode=yes -l #{user} #{host} "#{env} drake --debug -d #{deploy_dir} #{task} 2>&1")
|
|
82
83
|
else
|
|
83
|
-
%(ssh -tt -oBatchMode=yes -l #{user} #{host} "drake -d #{deploy_dir} #{task} 2>&1" 2>/dev/null)
|
|
84
|
+
%(ssh -tt -oBatchMode=yes -l #{user} #{host} "#{env} drake -d #{deploy_dir} #{task} 2>&1" 2>/dev/null)
|
|
84
85
|
end
|
|
85
86
|
end
|
|
86
87
|
|
data/lib/dply/shell.rb
CHANGED
|
@@ -5,17 +5,18 @@ module Dply
|
|
|
5
5
|
|
|
6
6
|
include Logger
|
|
7
7
|
|
|
8
|
-
def cmd(command, display: true, error_msg: nil, return_output: false)
|
|
8
|
+
def cmd(command, display: true, error_msg: nil, return_output: false, env:{})
|
|
9
|
+
stringify_values(env)
|
|
9
10
|
if display
|
|
10
11
|
puts "#{"\u2219".bold.blue} #{command}"
|
|
11
12
|
else
|
|
12
13
|
logger.debug command
|
|
13
14
|
end
|
|
14
15
|
if return_output
|
|
15
|
-
output = `#{command}`
|
|
16
|
+
output = `#{env_str(env)} #{command}`
|
|
16
17
|
else
|
|
17
18
|
output = ""
|
|
18
|
-
system "#{command} 2>&1"
|
|
19
|
+
system env, "#{command} 2>&1"
|
|
19
20
|
end
|
|
20
21
|
return_value = $?.exitstatus
|
|
21
22
|
error_msg ||= "non zero exit for \"#{command}\""
|
|
@@ -43,5 +44,19 @@ module Dply
|
|
|
43
44
|
symlink src, dst
|
|
44
45
|
end
|
|
45
46
|
|
|
47
|
+
def env_str(env)
|
|
48
|
+
str = ""
|
|
49
|
+
env.each do |k,v|
|
|
50
|
+
str << %(#{k}="#{v.to_s}")
|
|
51
|
+
end
|
|
52
|
+
str
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def stringify_values(hash)
|
|
56
|
+
hash.each do |k,v|
|
|
57
|
+
hash[k] = v.to_s
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
46
61
|
end
|
|
47
62
|
end
|
data/lib/dply/stages_config.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Dply
|
|
|
35
35
|
host: host,
|
|
36
36
|
user: user || get_from_current_stage(:user),
|
|
37
37
|
deploy_dir: deploy_dir || get_from_current_stage(:deploy_dir),
|
|
38
|
-
id: id ||
|
|
38
|
+
id: id || host
|
|
39
39
|
}
|
|
40
40
|
hosts << host_info
|
|
41
41
|
end
|
|
@@ -72,10 +72,19 @@ module Dply
|
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def ask(key)
|
|
76
|
+
print "Enter #{key}: "
|
|
77
|
+
value = STDIN.gets.chomp
|
|
78
|
+
env = get_from_current_stage(:env)
|
|
79
|
+
env[key] = value
|
|
80
|
+
end
|
|
81
|
+
|
|
75
82
|
def init_stage(name)
|
|
76
|
-
stages[name] = {
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
stages[name] = {
|
|
84
|
+
hosts: [],
|
|
85
|
+
parallel_runs: 1,
|
|
86
|
+
env: {}
|
|
87
|
+
}
|
|
79
88
|
end
|
|
80
89
|
|
|
81
90
|
|
data/lib/dply/strategy/git.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'dply/helper'
|
|
2
2
|
require 'dply/setup'
|
|
3
3
|
require 'dply/linker'
|
|
4
|
+
require 'dply/config_downloader'
|
|
4
5
|
require 'forwardable'
|
|
5
6
|
|
|
6
7
|
|
|
@@ -12,7 +13,9 @@ module Dply
|
|
|
12
13
|
include Helper
|
|
13
14
|
|
|
14
15
|
def_delegators :config, :target, :branch, :link_config,
|
|
15
|
-
|
|
16
|
+
:config_dir, :config_map, :dir_map, :config_skip_download,
|
|
17
|
+
:config_download_url
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
attr_reader :config, :options
|
|
18
21
|
|
|
@@ -23,17 +26,31 @@ module Dply
|
|
|
23
26
|
|
|
24
27
|
def deploy
|
|
25
28
|
setup.run
|
|
29
|
+
config_downloader.download_all if config_download_url
|
|
26
30
|
Dir.chdir current_dir do
|
|
31
|
+
previous_version = git.commit_id
|
|
27
32
|
git_step
|
|
33
|
+
current_version = git.commit_id
|
|
28
34
|
link_dirs
|
|
29
35
|
link_config_files
|
|
30
|
-
|
|
36
|
+
env = {
|
|
37
|
+
"DPLY_PREVIOUS_VERSION" => previous_version,
|
|
38
|
+
"DPLY_CURRENT_VERSION" => current_version
|
|
39
|
+
}
|
|
40
|
+
tasks.deploy target, env: env
|
|
31
41
|
end
|
|
32
42
|
end
|
|
33
43
|
|
|
34
44
|
def switch
|
|
35
45
|
end
|
|
36
46
|
|
|
47
|
+
def reload
|
|
48
|
+
config_downloader.download_all if config_download_url
|
|
49
|
+
Dir.chdir current_dir do
|
|
50
|
+
tasks.reload target
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
37
54
|
private
|
|
38
55
|
|
|
39
56
|
def current_dir
|
|
@@ -63,10 +80,13 @@ module Dply
|
|
|
63
80
|
|
|
64
81
|
def config_linker
|
|
65
82
|
return @config_linker if @config_linker
|
|
66
|
-
dir_prefix = config_dir || "config"
|
|
67
83
|
source = "#{config.deploy_dir}/config"
|
|
68
84
|
dest = current_dir
|
|
69
|
-
@config_linker ||= ::Dply::Linker.new(source, dest, map: config_map
|
|
85
|
+
@config_linker ||= ::Dply::Linker.new(source, dest, map: config_map)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def config_downloader
|
|
89
|
+
@config_downloader = ::Dply::ConfigDownloader.new(config_map.values.uniq, config_download_url, config_skip_download: config_skip_download)
|
|
70
90
|
end
|
|
71
91
|
|
|
72
92
|
def dir_linker
|
data/lib/dply/tasks.rb
CHANGED
|
@@ -4,14 +4,21 @@ module Dply
|
|
|
4
4
|
|
|
5
5
|
include Shell
|
|
6
6
|
|
|
7
|
-
def deploy(target)
|
|
7
|
+
def deploy(target, env:{})
|
|
8
|
+
env.merge!(env_from_yml)
|
|
8
9
|
bundle_install
|
|
9
|
-
cmd "#{rake_command} #{target}:deploy"
|
|
10
|
+
cmd "#{rake_command} #{target}:deploy", env: env
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def switch(target)
|
|
13
|
+
def switch(target, env:{})
|
|
14
|
+
env.merge!(env_from_yml)
|
|
13
15
|
bundle_install
|
|
14
|
-
cmd "#{rake_command} #{target}:switch"
|
|
16
|
+
cmd "#{rake_command} #{target}:switch", env: env
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def reload(target)
|
|
20
|
+
bundle_install
|
|
21
|
+
cmd "#{rake_command} #{target}:reload", env: env_from_yml
|
|
15
22
|
end
|
|
16
23
|
|
|
17
24
|
def gemfile_exists?
|
|
@@ -33,5 +40,16 @@ module Dply
|
|
|
33
40
|
cmd "bundle install"
|
|
34
41
|
end
|
|
35
42
|
|
|
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)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
36
54
|
end
|
|
37
55
|
end
|
data/lib/dply/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.5
|
|
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
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -55,10 +55,15 @@ files:
|
|
|
55
55
|
- bin/drake
|
|
56
56
|
- code_dump/alt_remote_task.rb
|
|
57
57
|
- code_dump/old_remote_task.rb
|
|
58
|
+
- docs/README
|
|
59
|
+
- docs/dply.rb
|
|
60
|
+
- docs/stages.rb
|
|
58
61
|
- dply.gemspec
|
|
59
62
|
- lib/dply.rb
|
|
60
63
|
- lib/dply/cli/deploy.rb
|
|
64
|
+
- lib/dply/cli/reload.rb
|
|
61
65
|
- lib/dply/config.rb
|
|
66
|
+
- lib/dply/config_downloader.rb
|
|
62
67
|
- lib/dply/custom_logger.rb
|
|
63
68
|
- lib/dply/deploy.rb
|
|
64
69
|
- lib/dply/dplyr.rb
|
|
@@ -70,6 +75,7 @@ files:
|
|
|
70
75
|
- lib/dply/lock.rb
|
|
71
76
|
- lib/dply/logger.rb
|
|
72
77
|
- lib/dply/release.rb
|
|
78
|
+
- lib/dply/reload.rb
|
|
73
79
|
- lib/dply/remote_task.rb
|
|
74
80
|
- lib/dply/repo.rb
|
|
75
81
|
- lib/dply/report.rb
|