capistrano-node-deploy 1.0.9 → 1.1.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.
- data/VERSION +1 -1
- data/capistrano-node-deploy.gemspec +2 -2
- data/lib/capistrano/node-deploy.rb +30 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "capistrano-node-deploy"
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Smith"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-30"
|
13
13
|
s.description = "Capistrano recipes for deploying node apps"
|
14
14
|
s.email = "james@loopj.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "digest/md5"
|
1
2
|
require "railsless-deploy"
|
2
3
|
require "multi_json"
|
3
4
|
|
@@ -13,7 +14,7 @@ respawn
|
|
13
14
|
respawn limit 99 5
|
14
15
|
|
15
16
|
script
|
16
|
-
exec
|
17
|
+
exec sudo -u {{node_user}} NODE_ENV={{node_env}} {{node_binary}} {{current_path}}/{{app_command}} 2>> {{shared_path}}/{{node_env}}.err.log 1>> {{shared_path}}/{{node_env}}.out.log
|
17
18
|
end script
|
18
19
|
EOD
|
19
20
|
|
@@ -21,18 +22,37 @@ def remote_file_exists?(full_path)
|
|
21
22
|
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
22
23
|
end
|
23
24
|
|
25
|
+
def remote_file_content_same_as?(full_path, content)
|
26
|
+
Digest::MD5.hexdigest(content) == capture("md5sum #{full_path} | awk '{ print $1 }'").strip
|
27
|
+
end
|
28
|
+
|
29
|
+
def remote_file_differs?(full_path, content)
|
30
|
+
exists = remote_file_exists?(full_path)
|
31
|
+
!exists || exists && !remote_file_content_same_as?(full_path, content)
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_upstart_config
|
35
|
+
UPSTART_TEMPLATE.gsub(/\{\{(.*?)\}\}/) { eval($1) }
|
36
|
+
end
|
37
|
+
|
24
38
|
Capistrano::Configuration.instance(:must_exist).load do |configuration|
|
25
39
|
before "deploy", "deploy:create_release_dir"
|
26
40
|
before "deploy", "node:check_upstart_config"
|
27
|
-
after "deploy:
|
28
|
-
after "deploy:
|
41
|
+
after "deploy:finalize_update", "node:install_packages"
|
42
|
+
after "deploy:finalize_update", "node:restart"
|
29
43
|
after "deploy:rollback", "node:restart"
|
30
44
|
|
31
45
|
package_json = MultiJson.load(File.open("package.json").read) rescue {}
|
32
46
|
|
33
47
|
set :application, package_json["name"] unless defined? application
|
34
48
|
set :app_command, package_json["main"] || "index.js" unless defined? app_command
|
49
|
+
|
35
50
|
set :node_binary, "/usr/bin/node" unless defined? node_binary
|
51
|
+
set :node_env, "production" unless defined? node_env
|
52
|
+
set :node_user, "deploy" unless defined? node_user
|
53
|
+
|
54
|
+
set :upstart_job_name, "#{application}-#{node_env}" unless defined? upstart_job_name
|
55
|
+
set :upstart_file_path, "/etc/init/#{upstart_job_name}.conf" unless defined? upstart_file_path
|
36
56
|
|
37
57
|
namespace :node do
|
38
58
|
desc "Check required packages and install if packages are not installed"
|
@@ -44,7 +64,7 @@ Capistrano::Configuration.instance(:must_exist).load do |configuration|
|
|
44
64
|
end
|
45
65
|
|
46
66
|
task :check_upstart_config do
|
47
|
-
create_upstart_config
|
67
|
+
create_upstart_config if remote_file_differs?(upstart_file_path, generate_upstart_config)
|
48
68
|
end
|
49
69
|
|
50
70
|
desc "Create upstart script for this node app"
|
@@ -53,26 +73,26 @@ Capistrano::Configuration.instance(:must_exist).load do |configuration|
|
|
53
73
|
temp_config_file_path = "#{shared_path}/#{application}.conf"
|
54
74
|
|
55
75
|
# Generate and upload the upstart script
|
56
|
-
put
|
76
|
+
put generate_upstart_config, temp_config_file_path
|
57
77
|
|
58
78
|
# Copy the script into place and make executable
|
59
|
-
sudo "cp #{temp_config_file_path} #{
|
60
|
-
sudo "chmod +x #{config_file_path}"
|
79
|
+
sudo "cp #{temp_config_file_path} #{upstart_file_path}"
|
61
80
|
end
|
62
81
|
|
63
82
|
desc "Start the node application"
|
64
83
|
task :start do
|
65
|
-
sudo "start #{
|
84
|
+
sudo "start #{upstart_job_name}"
|
66
85
|
end
|
67
86
|
|
68
87
|
desc "Stop the node application"
|
69
88
|
task :stop do
|
70
|
-
sudo "stop #{
|
89
|
+
sudo "stop #{upstart_job_name}"
|
71
90
|
end
|
72
91
|
|
73
92
|
desc "Restart the node application"
|
74
93
|
task :restart do
|
75
|
-
sudo "
|
94
|
+
sudo "stop #{upstart_job_name}"
|
95
|
+
sudo "start #{upstart_job_name}"
|
76
96
|
end
|
77
97
|
end
|
78
98
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-node-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.9
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-10-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|