pushdeploy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +14 -0
- data/Rakefile +2 -0
- data/bin/pushdeploy_create_config +40 -0
- data/bin/pushdeploy_install_hook +138 -0
- data/lib/pushdeploy/version.rb +3 -0
- data/lib/pushdeploy.rb +59 -0
- data/pushdeploy.gemspec +21 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) Artem Yankov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
#
|
4
|
+
# This script creates a file 'after_deploy.rb' in your config directory.
|
5
|
+
# You should run it inside of your project directory.
|
6
|
+
#
|
7
|
+
|
8
|
+
generate_config_body()
|
9
|
+
{
|
10
|
+
cat <<-EOF
|
11
|
+
#!/usr/bin/env ruby
|
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
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
if [ ! -d "./config" ]; then mkdir config; fi
|
31
|
+
|
32
|
+
generate_config_body > ./config/after_deploy.rb
|
33
|
+
|
34
|
+
if [ -f "./config/after_deploy.rb" ]; then
|
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
|
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
#
|
4
|
+
# Overrides post-receive hook in your git repository.
|
5
|
+
#
|
6
|
+
# First this script should determine the path to your remote origin git repository
|
7
|
+
# RVM path and rvm ruby string if you use it. If it can't determine
|
8
|
+
# path to the repository it will launch a manual mode where you'll have to
|
9
|
+
# enter these settings. You can also run 'pushdeploy_install_hook -m' to
|
10
|
+
# enter this mode.
|
11
|
+
#
|
12
|
+
# Then this script writes to /you_repository_path/hooks/post-recieve
|
13
|
+
# This hook is launched when you completed 'git push'.
|
14
|
+
#
|
15
|
+
# Hook should switch to the right RVM environment (if you use it)
|
16
|
+
# and run 'git pull' in your project directory. Then hook will run
|
17
|
+
# after_deploy.rb script in the config dir of project directory
|
18
|
+
# which lauches bundler, migrate and other commands that you specified.
|
19
|
+
#
|
20
|
+
|
21
|
+
repository=$(git config --get remote.origin.url)
|
22
|
+
|
23
|
+
get_rvm_string()
|
24
|
+
{
|
25
|
+
if [[ -n "$rvm_path" ]];
|
26
|
+
then
|
27
|
+
rvm_string=$(rvm current)
|
28
|
+
fi
|
29
|
+
}
|
30
|
+
|
31
|
+
manual_setup()
|
32
|
+
{
|
33
|
+
echo "Let's set up some variables"
|
34
|
+
if [ -z $repository ]; then
|
35
|
+
echo -e "\n\x1B[00;31m*** Can't locate your git repository. ***\x1B[00m"
|
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
|
41
|
+
|
42
|
+
echo -ne "Where is the git repository for this project located?: "
|
43
|
+
read repository
|
44
|
+
|
45
|
+
get_rvm_string
|
46
|
+
|
47
|
+
if [ -n $rvm_path ]; then
|
48
|
+
echo -e "\n\x1B[00;32mRVM path found:\x1B[00m \x1B[00;34m$rvm_path\x1B[00m.\n"
|
49
|
+
echo -e "* hit Enter if this is a correct path."
|
50
|
+
else
|
51
|
+
echo -e "\nRVM path not found.\n"
|
52
|
+
fi
|
53
|
+
|
54
|
+
echo -e "* type \x1B[00;32mn\x1B[00m if you don't even use RVM."
|
55
|
+
echo -e "* or just enter your own path."
|
56
|
+
echo -ne "\nYour answer: "
|
57
|
+
read new_rvm_path
|
58
|
+
|
59
|
+
if [ -n "$new_rvm_path" ]; then
|
60
|
+
if [ "$new_rvm_path" == "n" ]; then
|
61
|
+
rvm_path=""
|
62
|
+
else
|
63
|
+
rvm_path=$new_rvm_path
|
64
|
+
fi
|
65
|
+
fi
|
66
|
+
|
67
|
+
if [ "$new_rvm_path" != "n" -a -n "$rvm_path" ]; then
|
68
|
+
echo -e "\n***************************************************************************\n"
|
69
|
+
|
70
|
+
if [ -n $rvm_string ]; then
|
71
|
+
echo -e "This is your active gemset and version of Ruby: \x1B[00;34m$rvm_string\x1B[00m."
|
72
|
+
echo -e "\n* Just hit Enter if this is correct for your project."
|
73
|
+
else
|
74
|
+
echo "Your rvm ruby string is not detected for some reason."
|
75
|
+
fi
|
76
|
+
echo -ne "\nEnter a rvm ruby string (usually something like 1.9.2@rails3): "
|
77
|
+
read rvm_string
|
78
|
+
fi
|
79
|
+
|
80
|
+
echo $repository
|
81
|
+
echo $rvm_path
|
82
|
+
echo $rvm_string
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
generate_hook_body()
|
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
|
121
|
+
|
122
|
+
# check if we have permissions to write to the 'hooks' folder
|
123
|
+
|
124
|
+
if [ ! -w "$repository/hooks" ]; then
|
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
|
129
|
+
|
130
|
+
generate_hook_body > $repository/hooks/post-receive
|
131
|
+
if [ "$?" -ne 0 ]; then echo "A error occured while trying to write a hook."; exit 1; fi
|
132
|
+
|
133
|
+
chmod 770 $repository/hooks/post-receive
|
134
|
+
if [ "$?" -ne 0 ]; then echo "A error occured while trying to set permission of the hook. Try sudo?"; exit 1; fi
|
135
|
+
|
136
|
+
echo -e "\n\x1B[00;32mpost-receive hook has been successfully installed to $repository/hooks/post-receive\x1B[00m"
|
137
|
+
echo "Don't forget to run 'pushdeploy_create_config' inside of your project directory"
|
138
|
+
|
data/lib/pushdeploy.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
class PushDeploy
|
2
|
+
|
3
|
+
EMPTY_DIR = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
|
4
|
+
|
5
|
+
def initialize(args, &block)
|
6
|
+
|
7
|
+
puts 'Running auto_deploy...'
|
8
|
+
|
9
|
+
@deploy_to = args[3]
|
10
|
+
|
11
|
+
@oldrev, @newrev = args.shift, args.shift || 'HEAD'
|
12
|
+
if @oldrev == '0000000000000000000000000000000000000000'
|
13
|
+
@oldrev = EMPTY_DIR
|
14
|
+
elsif @oldrev.nil?
|
15
|
+
@oldrev = '@{-1}'
|
16
|
+
end
|
17
|
+
|
18
|
+
instance_exec(&block)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def bundle
|
23
|
+
return if @oldrev == '0'
|
24
|
+
|
25
|
+
return unless File.exist?('Gemfile')
|
26
|
+
if %x{git diff --name-only #{@oldrev} #{@newrev}} =~ /^Gemfile|\.gemspec$/
|
27
|
+
begin
|
28
|
+
# If Bundler in turn spawns Git, it can get confused by $GIT_DIR
|
29
|
+
git_dir = ENV.delete('GIT_DIR')
|
30
|
+
run "bundle check"
|
31
|
+
unless $?.success?
|
32
|
+
puts "Bundling..."
|
33
|
+
run "bundle | grep -v '^Using ' | grep -v ' is complete'"
|
34
|
+
end
|
35
|
+
ensure
|
36
|
+
ENV['GIT_DIR'] = git_dir
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def run(command)
|
42
|
+
Kernel.system "#{command} >&1"
|
43
|
+
end
|
44
|
+
|
45
|
+
def migrate
|
46
|
+
return if @oldrev == '0'
|
47
|
+
|
48
|
+
schema = %x{git diff --name-status #{@oldrev} #{@newrev} -- db/schema.rb}
|
49
|
+
if schema =~ /^A/
|
50
|
+
run "bundle exec rake db:create"
|
51
|
+
end
|
52
|
+
|
53
|
+
if `git diff HEAD^`.index("db/migrate")
|
54
|
+
puts "Migrating.."
|
55
|
+
run 'bundle exec rake db:migrate RAILS_ENV="production"'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/pushdeploy.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "pushdeploy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "pushdeploy"
|
7
|
+
s.version = Pushdeploy::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Artem Yankov"]
|
10
|
+
s.email = ["artem.yankov@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Easy deployment after 'git push' for Ruby applications}
|
13
|
+
s.description = %q{Automatically deploys application after 'git push' and run specified commands like 'bundle install' and 'rake db:migrate'}
|
14
|
+
|
15
|
+
s.rubyforge_project = "pushdeploy"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushdeploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Artem Yankov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-03 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Automatically deploys application after 'git push' and run specified commands like 'bundle install' and 'rake db:migrate'
|
17
|
+
email:
|
18
|
+
- artem.yankov@gmail.com
|
19
|
+
executables:
|
20
|
+
- pushdeploy_create_config
|
21
|
+
- pushdeploy_install_hook
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- MIT-LICENSE
|
30
|
+
- README.md
|
31
|
+
- Rakefile
|
32
|
+
- bin/pushdeploy_create_config
|
33
|
+
- bin/pushdeploy_install_hook
|
34
|
+
- lib/pushdeploy.rb
|
35
|
+
- lib/pushdeploy/version.rb
|
36
|
+
- pushdeploy.gemspec
|
37
|
+
homepage: ""
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: pushdeploy
|
60
|
+
rubygems_version: 1.7.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Easy deployment after 'git push' for Ruby applications
|
64
|
+
test_files: []
|
65
|
+
|