pushdeploy 0.0.1 → 0.0.2
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/bin/pushdeploy_create_config +24 -30
- data/bin/pushdeploy_install_hook +70 -104
- data/lib/pushdeploy/version.rb +1 -1
- metadata +1 -1
@@ -1,40 +1,34 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#
|
4
4
|
# This script creates a file 'after_deploy.rb' in your config directory.
|
5
5
|
# You should run it inside of your project directory.
|
6
6
|
#
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
# This script is launched by post-receive hook when push is completed.
|
15
|
-
# The general purpose of this script is to run bundler, migration and
|
16
|
-
# other commands that you want to launch after deployment.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'pushdeploy'
|
20
|
-
|
21
|
-
PushDeploy.new(ARGV) do
|
22
|
-
bundle
|
23
|
-
migrate
|
24
|
-
run "touch #{@deploy_to}/tmp/restart.txt"
|
25
|
-
end
|
26
|
-
EOF
|
8
|
+
Dir.mkdir "./config" if !File.directory? './config'
|
9
|
+
|
10
|
+
config_file = File.open "./config/after_deploy.rb", "w"
|
11
|
+
raise "A error has been occured while trying to write to $(pwd)/config/after_deploy.rb. Not enough permission?" if config_file.nil?
|
27
12
|
|
28
|
-
|
13
|
+
config_file.write %{#!/usr/bin/env ruby
|
14
|
+
|
15
|
+
#
|
16
|
+
# This script is launched by post-receive hook when push is completed.
|
17
|
+
# The general purpose of this script is to run bundler, migration and
|
18
|
+
# other commands that you want to launch after deployment.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'pushdeploy'
|
29
22
|
|
30
|
-
|
23
|
+
PushDeploy.new(ARGV) do
|
24
|
+
bundle
|
25
|
+
migrate
|
26
|
+
run "touch #{@deploy_to}/tmp/restart.txt"
|
27
|
+
end
|
28
|
+
}
|
31
29
|
|
32
|
-
|
30
|
+
puts "\n*************************************"
|
31
|
+
puts "\e[00;32mConfig has been successfully created!\e[00m"
|
32
|
+
puts "*************************************\n"
|
33
33
|
|
34
|
-
|
35
|
-
echo -e "\n**********************************"
|
36
|
-
echo -e "\n\x1B[00;32mConfig has been successfully created!\x1B[00m\n"
|
37
|
-
echo -e "You can edit $(pwd)/config/after_deploy.rb to add commands that you want to run after deployment.\n"
|
38
|
-
else
|
39
|
-
echo -e "\n\x1B[00;31mAn error has been occured while trying to write to $(pwd)/config/after_deploy.rb. Not enough permission?\e[00m"
|
40
|
-
fi
|
34
|
+
puts "You can edit " + `pwd`.chop + "/config/after_deploy.rb to add commands that you want to run after deployment.\n\n"
|
data/bin/pushdeploy_install_hook
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#
|
4
4
|
# Overrides post-receive hook in your git repository.
|
@@ -18,121 +18,87 @@
|
|
18
18
|
# which lauches bundler, migrate and other commands that you specified.
|
19
19
|
#
|
20
20
|
|
21
|
-
repository
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
echo -e "\nMay be you run installer from a wrong directory?"
|
37
|
-
echo -e "\nYou should run it from the root folder of your project. Something like /var/www/html/myapp/"
|
38
|
-
echo "Current dir is: $(pwd)"
|
39
|
-
echo -e "\n\x1B[00;32mAnyway, no worries, we can try to set everything up manually. Just answer some questions about your environment.\x1B[00m "
|
40
|
-
fi
|
21
|
+
repository=`git config --get remote.origin.url`
|
22
|
+
|
23
|
+
rvm_path = ENV['rvm_path']
|
24
|
+
rvm_string = rvm_path.nil? ? nil : `rvm current`
|
25
|
+
current_path = `pwd`.chop
|
26
|
+
|
27
|
+
if ! File.directory?(repository) || ARGV[0] == '-m'
|
28
|
+
|
29
|
+
if ! File.directory?(repository)
|
30
|
+
puts "\n\e[00;31m*** Can't locate your git repository. ***\e[00m"
|
31
|
+
puts "\nMay be you run installer from a wrong directory?"
|
32
|
+
puts "\nYou should run it from the root folder of your project. Something like /var/www/html/myapp/"
|
33
|
+
puts "Current dir is: #{current_path}"
|
34
|
+
puts "\n\e[00;32mAnyway, no worries, we can try to set everything up manually. Just answer some questions about your environment.\e[00m "
|
35
|
+
end
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
get_rvm_string
|
37
|
+
print "\nWhere is the git repository for this project located?: "
|
38
|
+
repository = gets.chomp
|
46
39
|
|
47
|
-
if
|
48
|
-
|
49
|
-
|
40
|
+
if !rvm_path.nil?
|
41
|
+
puts "\n\e[00;32mRVM path found:\e[00m \e[00;34m#{rvm_path}\e[00m.\n"
|
42
|
+
puts "* hit Enter if this is a correct path."
|
50
43
|
else
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
fi
|
44
|
+
puts "\nRVM path not found.\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
puts "* type \e[00;32mn\e[00m if you don't even use RVM."
|
48
|
+
puts "* or just enter your own path."
|
49
|
+
print "\nYour answer: "
|
50
|
+
new_rvm_path = gets.chomp
|
51
|
+
|
52
|
+
if new_rvm_path == 'n'
|
53
|
+
rvm_path = nil
|
54
|
+
elsif !new_rvm_path.empty?
|
55
|
+
rvm_path = new_rvm_path
|
56
|
+
end
|
57
|
+
|
66
58
|
|
67
|
-
if
|
68
|
-
|
59
|
+
if new_rvm_path != "n" && !rvm_path.nil?
|
60
|
+
puts "\n***************************************************************************\n"
|
69
61
|
|
70
|
-
if
|
71
|
-
|
72
|
-
|
62
|
+
if !rvm_string.nil?
|
63
|
+
puts "This is your active gemset and version of Ruby: \e[00;34m#{rvm_string}\e[00m."
|
64
|
+
puts "\n* Just hit Enter if this is correct for your project."
|
73
65
|
else
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
66
|
+
puts "Your rvm ruby string is not detected for some reason."
|
67
|
+
end
|
68
|
+
print "\nEnter a rvm ruby string (usually something like 1.9.2@rails3): "
|
69
|
+
|
70
|
+
new_rvm_string = gets.chomp
|
71
|
+
rvm_string = new_rvm_string.empty? ? rvm_string : new_rvm_string
|
72
|
+
|
73
|
+
end
|
79
74
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
75
|
+
end
|
76
|
+
|
77
|
+
# create 'hooks' folder if it doesn't exist
|
78
|
+
Dir.mkdir "#{repository}/hooks" if !File.directory? "#{repository}/hooks"
|
79
|
+
|
80
|
+
hook_file = File.open "#{repository}/hooks/post-receive", "w"
|
81
|
+
puts "\e[00;31mA error has been occured while trying to write to #{repository}/hooks/post-receive. Not enough permission?\e[00m\n\n Try using: sudo\n" && exit if hook_file.nil?
|
82
|
+
|
83
|
+
# writing a bash script to a hook
|
84
|
+
hook_file.write %{#!/bin/sh
|
85
|
+
deploy_dir=#{current_path}
|
86
|
+
read oldrev newrev refname
|
87
|
+
|
88
|
+
unset GIT_DIR && cd \$deploy_dir && git --work-tree=\$deploy_dir pull #{repository} -f
|
84
89
|
}
|
85
90
|
|
86
|
-
|
87
|
-
{
|
88
|
-
cat <<-EOF
|
89
|
-
#!/bin/sh
|
90
|
-
deploy_dir=$(pwd)
|
91
|
-
read oldrev newrev refname
|
92
|
-
|
93
|
-
unset GIT_DIR && cd \$deploy_dir && git --work-tree=\$deploy_dir pull $repository -f
|
94
|
-
EOF
|
95
|
-
|
96
|
-
if [ -n "$rvm_path" -a -n "$rvm_string" ]; then
|
97
|
-
cat <<-EOF
|
98
|
-
source "$rvm_path/scripts/rvm"
|
99
|
-
rvm $rvm_string
|
100
|
-
EOF
|
101
|
-
fi
|
102
|
-
|
103
|
-
cat <<-EOF
|
104
|
-
\$deploy_dir/config/auto_deploy.rb \$oldrev \$newrev \$refname \$deploy_dir
|
105
|
-
EOF
|
106
|
-
|
107
|
-
}
|
108
|
-
|
109
|
-
if [ -z "$repository" -o "$1" == "-m" ]; then
|
110
|
-
manual_setup
|
111
|
-
else
|
112
|
-
get_rvm_string
|
113
|
-
fi
|
114
|
-
|
115
|
-
# create 'hooks' folder if it doesn't exist
|
116
|
-
|
117
|
-
if [ -z "$repository/hooks" ]; then
|
118
|
-
echo "Creating a hook folder (didn't exist).."
|
119
|
-
mkdir -p "$repository/hooks"
|
120
|
-
fi
|
91
|
+
hook_file.write %{source "#{rvm_path}/scripts/rvm"\nrvm #{rvm_string}} if rvm_path && rvm_string
|
121
92
|
|
122
|
-
|
93
|
+
hook_file.write "\$deploy_dir/config/auto_deploy.rb \$oldrev \$newrev \$refname \$deploy_dir"
|
123
94
|
|
124
|
-
|
125
|
-
echo -e "\x1B[00;31mYou don't have permission to modify $repository/hooks/\x1B[00m"
|
126
|
-
echo "Try using: sudo $0"
|
127
|
-
exit 1
|
128
|
-
fi
|
95
|
+
`chmod 770 #{repository}/hooks/post-receive`
|
129
96
|
|
130
|
-
|
131
|
-
if [ "$?" -ne 0 ]; then echo "A error occured while trying to write a hook."; exit 1; fi
|
97
|
+
puts "A error occured while trying to set permission of the hook. Try sudo?" && exit if !$?.success?
|
132
98
|
|
133
|
-
|
134
|
-
|
99
|
+
puts "\n*****************************************************************"
|
100
|
+
puts "\e[00;32mpost-receive hook has been successfully installed to #{repository}/hooks/post-receive\e[00m"
|
101
|
+
puts "*******************************************************************\n"
|
135
102
|
|
136
|
-
|
137
|
-
echo "Don't forget to run 'pushdeploy_create_config' inside of your project directory"
|
103
|
+
puts "Don't forget to run 'pushdeploy_create_config' inside of your project directory on a development machine.\n\n"
|
138
104
|
|
data/lib/pushdeploy/version.rb
CHANGED