miniploy 0.0.1
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/LICENSE +23 -0
- data/README.md +70 -0
- data/bin/miniploy +6 -0
- data/lib/miniploy/cli.rb +11 -0
- data/lib/miniploy/deploy.rb +48 -0
- data/lib/miniploy/dsl.rb +47 -0
- data/lib/miniploy.rb +7 -0
- data/miniploy.gemspec +19 -0
- metadata +88 -0
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright 2011 Thibault Jouan. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
5
|
+
* Redistributions of source code must retain the above copyright notice, this
|
6
|
+
list of conditions and the following disclaimer.
|
7
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer in the documentation
|
9
|
+
and/or other materials provided with the distribution.
|
10
|
+
* Neither the name of the software nor the names of its contributors may be
|
11
|
+
used to endorse or promote products derived from this software without
|
12
|
+
specific prior written permission.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND ANY
|
15
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
|
18
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
21
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# miniploy
|
2
|
+
|
3
|
+
A minimal deployment tool using ruby, ssh and git.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Create a `config/miniploy.rb` file in your app:
|
9
|
+
|
10
|
+
app = 'myapp'
|
11
|
+
repository = 'repository-host.example:myapp'
|
12
|
+
target = 'user@deploy-host.example'
|
13
|
+
|
14
|
+
|
15
|
+
Initial deployment:
|
16
|
+
|
17
|
+
miniploy setup
|
18
|
+
|
19
|
+
|
20
|
+
Deploying updates from repository:
|
21
|
+
|
22
|
+
miniploy update
|
23
|
+
|
24
|
+
|
25
|
+
## Complete config sample
|
26
|
+
|
27
|
+
app = 'myapp'
|
28
|
+
repository = 'repository-host.example:myapp'
|
29
|
+
target = 'user@deploy-host.example'
|
30
|
+
bundle_add = %w[unicorn]
|
31
|
+
ssh_args = '-A'
|
32
|
+
|
33
|
+
after_setup do
|
34
|
+
append "#{app_path}/config/unicorn.rb", <<-eoh.gsub(/^ +/, '')
|
35
|
+
pid '$HOME/#{pid_path}'
|
36
|
+
listen '$HOME/#{run_path}/unicorn.sock'
|
37
|
+
eoh
|
38
|
+
end
|
39
|
+
|
40
|
+
start do
|
41
|
+
bundle_run 'unicorn -c config/unicorn.rb -D'
|
42
|
+
end
|
43
|
+
|
44
|
+
stop do
|
45
|
+
run "kill -QUIT `cat #{pid_path}`"
|
46
|
+
end
|
47
|
+
|
48
|
+
after_update do
|
49
|
+
run "kill -HUP `cat #{pid_path}`"
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def pid_path
|
54
|
+
"#{run_path}/unicorn.pid"
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
## Requirements
|
59
|
+
|
60
|
+
- ruby
|
61
|
+
- git
|
62
|
+
- ssh client
|
63
|
+
- rake (development)
|
64
|
+
|
65
|
+
|
66
|
+
## Installation
|
67
|
+
|
68
|
+
You need ruby and rubygems, then install the miniploy gem:
|
69
|
+
|
70
|
+
gem install miniploy
|
data/bin/miniploy
ADDED
data/lib/miniploy/cli.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Miniploy
|
2
|
+
class Deploy
|
3
|
+
include Miniploy::DSL
|
4
|
+
|
5
|
+
def initialize(filepath = 'config/miniploy.rb')
|
6
|
+
instance_eval File.read(filepath) + <<-eoh
|
7
|
+
local_variables.each do |v|
|
8
|
+
self.send "\#{v}=", eval(v.to_s) rescue nil
|
9
|
+
end
|
10
|
+
eoh
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
run "git clone --depth 1 #{repository} #{app_path}"
|
15
|
+
run "mkdir -p #{app_path}/tmp/run"
|
16
|
+
setup_bundler
|
17
|
+
rake 'db:create'
|
18
|
+
rake 'db:migrate'
|
19
|
+
after_setup
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup_bundler
|
23
|
+
return unless use_bundler?
|
24
|
+
bundle_add.each do |gem|
|
25
|
+
append "#{app_path}/Gemfile", "gem 'unicorn'"
|
26
|
+
end
|
27
|
+
run <<-eoh.gsub(/\A +/, '').chomp
|
28
|
+
bundle install --without development test \\
|
29
|
+
--gemfile #{app_path}/Gemfile --path $HOME/.bundle
|
30
|
+
eoh
|
31
|
+
end
|
32
|
+
|
33
|
+
def ssh(cmd)
|
34
|
+
system('ssh', ssh_args, target, cmd)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update
|
38
|
+
run "cd #{app_path} && git fetch origin && git reset --hard origin"
|
39
|
+
setup_bundler
|
40
|
+
rake 'db:migrate'
|
41
|
+
after_update
|
42
|
+
end
|
43
|
+
|
44
|
+
def use_bundler?
|
45
|
+
ssh "test -f #{app_path}/Gemfile"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/miniploy/dsl.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Miniploy
|
2
|
+
module DSL
|
3
|
+
attr_accessor :app, :repository, :target, :ssh_args, :bundle_add
|
4
|
+
|
5
|
+
def app_path
|
6
|
+
"apps/#{app}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def append(filepath, content)
|
10
|
+
run "echo \"#{content}\" >> #{filepath}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def bundle_run(cmd)
|
14
|
+
run "cd #{app_path} && RACK_ENV=production bundle exec #{cmd}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def rake(task)
|
18
|
+
bundle_run "rake #{task}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(cmd)
|
22
|
+
puts ">> `#{cmd}`"
|
23
|
+
raise RuntimeError unless ssh(cmd)
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_path
|
27
|
+
"#{app_path}/tmp/run"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.hook(*methods)
|
31
|
+
methods.each do |method|
|
32
|
+
eval <<-eoh
|
33
|
+
def #{method}(&block)
|
34
|
+
@hooks ||= {}
|
35
|
+
if block_given?
|
36
|
+
@hooks[:#{method}] = block
|
37
|
+
else
|
38
|
+
@hooks[:#{method}].call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
eoh
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
hook :after_setup, :start, :stop, :after_update
|
46
|
+
end
|
47
|
+
end
|
data/lib/miniploy.rb
ADDED
data/miniploy.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
|
2
|
+
require 'miniploy'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'miniploy'
|
6
|
+
s.version = Miniploy::VERSION
|
7
|
+
s.summary = 'Minimalistic deployment tool'
|
8
|
+
s.description = <<-eoh.gsub(/^ +/, '')
|
9
|
+
A minimal deployment tool using ssh and git.
|
10
|
+
eoh
|
11
|
+
|
12
|
+
s.author = 'Thibault Jouan'
|
13
|
+
s.email = 'tj@a13.fr'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split "\n"
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
|
+
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: miniploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thibault Jouan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-02 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: |
|
35
|
+
A minimal deployment tool using ssh and git.
|
36
|
+
|
37
|
+
email: tj@a13.fr
|
38
|
+
executables:
|
39
|
+
- miniploy
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- bin/miniploy
|
48
|
+
- lib/miniploy.rb
|
49
|
+
- lib/miniploy/cli.rb
|
50
|
+
- lib/miniploy/deploy.rb
|
51
|
+
- lib/miniploy/dsl.rb
|
52
|
+
- miniploy.gemspec
|
53
|
+
homepage:
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.7.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Minimalistic deployment tool
|
86
|
+
test_files: []
|
87
|
+
|
88
|
+
has_rdoc:
|