octopress-deploy 1.0.0.alpha.1 → 1.0.0.alpha.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.
- checksums.yaml +4 -4
- data/README.md +38 -21
- data/lib/octopress-deploy/core_ext.rb +45 -0
- data/lib/octopress-deploy/git.rb +15 -54
- data/lib/octopress-deploy/rsync.rb +55 -0
- data/lib/octopress-deploy/version.rb +1 -1
- data/lib/octopress-deploy.rb +94 -1
- data/test/_deploy.yml +4 -4
- data/test/test.rb +18 -5
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 170e6e1991b426a98b1638fb45687b7016a9fc53
|
4
|
+
data.tar.gz: 9b9a154ac981bc45b2e01c7c46d171176f7f61de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a9439fa388b44668239362ad0ccb3fab3cfb878a17f355f90bed8c5c92258fabd25321f81dcd06dc47bf0f89daf484b8b133ed7ed4f6b4c784c46878574641
|
7
|
+
data.tar.gz: 17df7f348642dbb83c89b563390fa1b2e8cd8ab778e5d0a9e36682e9ba5669d6fa21e1281928971339268e7d527f1b8da5dfaa787d6dfc5511e7c5e9d0cff0d9
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Octopress Deploy
|
2
2
|
|
3
|
-
Deployment tools for Octopress and Jekyll blogs.
|
3
|
+
Deployment tools for Octopress and Jekyll blogs (or really any static site).
|
4
|
+
|
5
|
+
Currently this supports deploying through Git and Rsync. Requests for other
|
6
|
+
deployment methods are welcome.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -14,47 +17,61 @@ And then execute:
|
|
14
17
|
|
15
18
|
Or install it yourself as:
|
16
19
|
|
17
|
-
$ gem install octopress-deploy
|
18
|
-
|
19
|
-
## Deploying with Git
|
20
|
-
|
21
|
-
This is a generic git deployment system, it should work for GitHub, Heroku and other similar hosts.
|
22
|
-
|
23
|
-
#### 1. Add a configuration file
|
20
|
+
$ gem install octopress-deploy
|
24
21
|
|
25
|
-
|
22
|
+
## Set up
|
26
23
|
|
27
|
-
|
28
|
-
For project pages, the url should be the path to the project repo and the branch should be `gh-pages`.
|
24
|
+
To deploy your site run:
|
29
25
|
|
30
|
-
```
|
31
|
-
|
32
|
-
git:
|
33
|
-
url:
|
34
|
-
branch: master
|
26
|
+
```ruby
|
27
|
+
Octopress::Deploy.push()
|
35
28
|
```
|
36
29
|
|
37
|
-
|
30
|
+
This will read from your configuration file `_deploy.yml` and deploy your site. If your site has no configuration file, you will be asked if you want to generate one and what deployment method you want to use.
|
31
|
+
|
32
|
+
You can also generate a configuration by running:
|
38
33
|
|
39
34
|
```ruby
|
40
|
-
Octopress::Deploy
|
35
|
+
Octopress::Deploy.init_cofig('git') # or 'rsync'
|
41
36
|
```
|
42
37
|
|
43
|
-
|
38
|
+
This will generate a '_deploy.yml' file in your current directory.
|
44
39
|
|
45
|
-
###
|
40
|
+
### Configuration options
|
46
41
|
|
47
|
-
|
42
|
+
Configurations should be added to a `_deploy.yml` file in your project's root directory. You can pass options as a hash directy to the `push` method as well. Passed options will override options set in the config file.
|
48
43
|
|
49
44
|
| option | Description | Default
|
50
45
|
|:--------------|:-------------------------------------------------|:---------------|
|
51
46
|
| `config_file` | Path to the config file. | _config.yml |
|
52
47
|
| `site_dir` | Path to comipled site files. | _site |
|
48
|
+
|
49
|
+
|
50
|
+
### Git options
|
51
|
+
|
52
|
+
Only git_url is required. Other options will default as shown below.
|
53
|
+
|
54
|
+
| option | Description | Default
|
55
|
+
|:--------------|:-------------------------------------------------|:---------------|
|
53
56
|
| `git_url` | Url for remote git repository. | |
|
54
57
|
| `git_branch` | Deployment branch for git repository. | master |
|
55
58
|
| `deploy_dir` | Directory where deployment files are staged. | .deploy |
|
56
59
|
| `remote` | Name of git remote. | deploy |
|
57
60
|
|
61
|
+
### Rsync options
|
62
|
+
|
63
|
+
Only `remote_path` is required. If `user` is not present, Rsync will sync between two locally available directories. Do this if your site root is mounted locally.
|
64
|
+
|
65
|
+
| option | Description | Default
|
66
|
+
|:---------------|:--------------------------------------------------|:---------------|
|
67
|
+
| `user` | ssh user, e.g user@host.com | |
|
68
|
+
| `port` | ssh port | 22 |
|
69
|
+
| `remote_path` | Remote destination's document root. | |
|
70
|
+
| `exclude_file` | Path to a file containing rsync exclusions. | |
|
71
|
+
| `exclude` | Inline list of rsync exclusions. | |
|
72
|
+
| `include` | Inline list of inclusions to override exclusions. | |
|
73
|
+
| `delete` | Delete files in destination not found in source | false |
|
74
|
+
|
58
75
|
## Contributing
|
59
76
|
|
60
77
|
1. Fork it
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Hash
|
2
|
+
# Merges self with another hash, recursively.
|
3
|
+
#
|
4
|
+
# This code was lovingly stolen from some random gem:
|
5
|
+
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
6
|
+
#
|
7
|
+
# Thanks to whoever made it.
|
8
|
+
def deep_merge(hash)
|
9
|
+
target = dup
|
10
|
+
hash.keys.each do |key|
|
11
|
+
if hash[key].is_a? Hash and self[key].is_a? Hash
|
12
|
+
target[key] = target[key].deep_merge(hash[key])
|
13
|
+
next
|
14
|
+
end
|
15
|
+
target[key] = hash[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
target
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_symbol_keys
|
22
|
+
inject({}) do |memo, (k, v)|
|
23
|
+
if v.is_a? Hash
|
24
|
+
memo[k.to_sym] = v.to_symbol_keys
|
25
|
+
else
|
26
|
+
memo[k.to_sym] = v
|
27
|
+
end
|
28
|
+
|
29
|
+
memo
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_string_keys
|
34
|
+
inject({}) do |memo, (k, v)|
|
35
|
+
if v.is_a? Hash
|
36
|
+
memo[k.to_s] = v.to_string_keys
|
37
|
+
else
|
38
|
+
memo[k.to_s] = v
|
39
|
+
end
|
40
|
+
|
41
|
+
memo
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/lib/octopress-deploy/git.rb
CHANGED
@@ -1,37 +1,15 @@
|
|
1
1
|
module Octopress
|
2
2
|
module Deploy
|
3
3
|
class Git
|
4
|
-
def initialize(options={})
|
5
|
-
@config_file = options[:config_file] || '_deploy.yml'
|
6
|
-
if !File.exists? @config_file
|
7
|
-
init_config if ask_bool("Deployment config file not found. Create #{@config_file}?")
|
8
|
-
else
|
9
|
-
config = YAML.load(File.open(@config_file))
|
10
|
-
@site_dir = options[:site_dir] || config['site']
|
11
|
-
@repo = options[:git_url] || config['git']['url']
|
12
|
-
@branch = options[:git_branch] || config['git']['branch']
|
13
|
-
@deploy_dir = options[:deploy_dir] || config['git']['deploy_dir'] || '.deploy'
|
14
|
-
@remote = options[:remote] || config['git']['remote'] || 'deploy'
|
15
|
-
|
16
|
-
abort "Deploy Failed: You must provide a repository URL before deploying. Check your #{@config_file}.".red if @repo.nil?
|
17
|
-
end
|
18
|
-
end
|
19
4
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
FILE
|
29
|
-
File.open(@config_file, 'w') { |f| f.write(config) }
|
30
|
-
puts "File #{@config_file} created.".green
|
31
|
-
puts "------------------"
|
32
|
-
puts config
|
33
|
-
puts "------------------"
|
34
|
-
puts "Please update it with your settings."
|
5
|
+
def initialize(options={})
|
6
|
+
@options = options
|
7
|
+
@repo = @options[:git_url]
|
8
|
+
@branch = @options[:git_branch]
|
9
|
+
@site_dir = @options[:site_dir]
|
10
|
+
@remote = @options[:remote] || 'deploy'
|
11
|
+
@deploy_dir = @options[:deploy_dir] || '.deploy'
|
12
|
+
abort "Deploy Failed: You must provide a repository URL before deploying. Check your #{@options[:config_file]}.".red if @repo.nil?
|
35
13
|
end
|
36
14
|
|
37
15
|
# Initialize, pull, copy and deploy.
|
@@ -53,6 +31,12 @@ FILE
|
|
53
31
|
end
|
54
32
|
end
|
55
33
|
|
34
|
+
def self.default_config(options={})
|
35
|
+
config = <<-CONFIG
|
36
|
+
git_url: #{options[:git_url]}
|
37
|
+
git_branch: #{options[:git_branch] || 'master'}
|
38
|
+
CONFIG
|
39
|
+
end
|
56
40
|
|
57
41
|
# If necessary create deploy directory and initialize it with deployment remote
|
58
42
|
#
|
@@ -64,6 +48,7 @@ FILE
|
|
64
48
|
# Attempt to clone from the remote
|
65
49
|
#
|
66
50
|
cmd = "git clone #{@repo} --origin #{@remote} --branch #{@branch} ."
|
51
|
+
puts cmd
|
67
52
|
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
68
53
|
exit_status = wait_thr.value
|
69
54
|
|
@@ -102,30 +87,6 @@ FILE
|
|
102
87
|
`git add --all :/; git commit -m '#{message}'`
|
103
88
|
end
|
104
89
|
end
|
105
|
-
|
106
|
-
def ask_bool(message)
|
107
|
-
ask(message, ['y','n']) == 'y'
|
108
|
-
end
|
109
|
-
|
110
|
-
def ask(message, valid_options)
|
111
|
-
if valid_options
|
112
|
-
options = valid_options.join '/'
|
113
|
-
answer = get_stdin("#{message} [#{options}]: ").downcase.strip
|
114
|
-
if valid_options.map{|o| o.downcase}.include?(answer)
|
115
|
-
return answer
|
116
|
-
else
|
117
|
-
return false
|
118
|
-
end
|
119
|
-
else
|
120
|
-
answer = get_stdin("#{message}: ")
|
121
|
-
end
|
122
|
-
answer
|
123
|
-
end
|
124
|
-
|
125
|
-
def get_stdin(message)
|
126
|
-
print message
|
127
|
-
STDIN.gets.chomp
|
128
|
-
end
|
129
90
|
end
|
130
91
|
end
|
131
92
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Octopress
|
2
|
+
module Deploy
|
3
|
+
class Rsync
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@user = options[:user]
|
7
|
+
@port = options[:port] || "22"
|
8
|
+
@local = options[:site_dir]
|
9
|
+
@remote = options[:remote_path]
|
10
|
+
@exclude = options[:exclude]
|
11
|
+
@exclude_file = options[:exclude_file]
|
12
|
+
@include = options[:include]
|
13
|
+
@delete = options[:delete]
|
14
|
+
end
|
15
|
+
|
16
|
+
def push
|
17
|
+
cmd = "rsync -avz"
|
18
|
+
if @exclude || @exclude_file
|
19
|
+
cmd << "e"
|
20
|
+
if @exclude_file
|
21
|
+
cmd << " --exclude-from #{@exclude_file}"
|
22
|
+
else
|
23
|
+
cmd << " --exclude #{@exclude}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
if @include
|
27
|
+
cmd << " --include #{@include}"
|
28
|
+
end
|
29
|
+
if @user
|
30
|
+
cmd << " ssh -p #{@port}"
|
31
|
+
end
|
32
|
+
if @delete
|
33
|
+
cmd << " --delete"
|
34
|
+
end
|
35
|
+
cmd += " #{File.join(@local, '')} "
|
36
|
+
if @user
|
37
|
+
cmd << "#{@user}:"
|
38
|
+
end
|
39
|
+
cmd << "#{@remote}"
|
40
|
+
|
41
|
+
system cmd
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.default_config(options={})
|
45
|
+
config = <<-CONFIG
|
46
|
+
user: #{options[:user]}
|
47
|
+
port: #{options[:port] || '22'}
|
48
|
+
remote_path: #{options[:remote_path]}
|
49
|
+
delete: #{options[:delete]}
|
50
|
+
CONFIG
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/octopress-deploy.rb
CHANGED
@@ -1,10 +1,103 @@
|
|
1
1
|
require "octopress-deploy/version"
|
2
|
+
require "octopress-deploy/core_ext"
|
2
3
|
require "YAML"
|
3
4
|
require 'colorator'
|
4
5
|
require 'open3'
|
5
6
|
|
7
|
+
|
6
8
|
module Octopress
|
7
9
|
module Deploy
|
8
|
-
autoload :Git,
|
10
|
+
autoload :Git, 'octopress-deploy/git'
|
11
|
+
autoload :Rsync, 'octopress-deploy/rsync'
|
12
|
+
|
13
|
+
METHODS = {
|
14
|
+
'git'=> Git,
|
15
|
+
'rsync'=> Rsync
|
16
|
+
}
|
17
|
+
|
18
|
+
def self.push(options={})
|
19
|
+
init_options(options)
|
20
|
+
if !File.exists? @options[:config_file]
|
21
|
+
init_config if ask_bool("Deployment config file not found. Create #{@options[:config_file]}?")
|
22
|
+
else
|
23
|
+
parse_options
|
24
|
+
deploy_method.new(@options).push()
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.parse_options
|
29
|
+
config = YAML.load(File.open(@options[:config_file])).to_symbol_keys
|
30
|
+
@options = @options.to_symbol_keys
|
31
|
+
@options = config.deep_merge(@options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.init_options(options={})
|
35
|
+
@options ||= options
|
36
|
+
@options[:config_file] ||= '_deploy.yml'
|
37
|
+
@options[:site_dir] ||= site_dir
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.deploy_method
|
41
|
+
METHODS[@options[:method].downcase]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.site_dir
|
45
|
+
@options[:site_dir] || if File.exist? '_config.yml'
|
46
|
+
YAML.load(File.open('_config.yml'))['destination'] || '_site'
|
47
|
+
else
|
48
|
+
'_site'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Create a config file
|
53
|
+
#
|
54
|
+
def self.init_config(method=nil, options={})
|
55
|
+
init_options unless @options
|
56
|
+
@options ||= options
|
57
|
+
@options[:method] ||= method
|
58
|
+
unless @options[:method]
|
59
|
+
@options[:method] = ask("How would you like to deploy your site?", METHODS.keys)
|
60
|
+
end
|
61
|
+
config = <<-FILE
|
62
|
+
method: #{@options[:method]}
|
63
|
+
site_dir: #{@options[:site_dir]}
|
64
|
+
FILE
|
65
|
+
config += deploy_method.default_config(options)
|
66
|
+
|
67
|
+
if File.exist? @options[:config_file]
|
68
|
+
unless ask_bool("A config file already exists at #{@options[:config_file]}. Overwrite?")
|
69
|
+
abort "No config file written."
|
70
|
+
end
|
71
|
+
end
|
72
|
+
File.open(@options[:config_file], 'w') { |f| f.write(config) }
|
73
|
+
puts "File #{@options[:config_file]} created.".green
|
74
|
+
puts "------------------"
|
75
|
+
puts "#{config.yellow}------------------"
|
76
|
+
puts "Please add your configurations to this file."
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.ask_bool(message)
|
80
|
+
ask(message, ['y','n']) == 'y'
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.ask(message, valid_options)
|
84
|
+
if valid_options
|
85
|
+
options = valid_options.join '/'
|
86
|
+
answer = get_stdin("#{message} [#{options}]: ").downcase.strip
|
87
|
+
if valid_options.map{|o| o.downcase}.include?(answer)
|
88
|
+
return answer
|
89
|
+
else
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
else
|
93
|
+
answer = get_stdin("#{message}: ")
|
94
|
+
end
|
95
|
+
answer
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.get_stdin(message)
|
99
|
+
print message
|
100
|
+
STDIN.gets.chomp
|
101
|
+
end
|
9
102
|
end
|
10
103
|
end
|
data/test/_deploy.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
method: git
|
2
|
+
site_dir: _site
|
3
|
+
git_url: /Users/imathis/workspace/octodev/deploy/test/deploy_target
|
4
|
+
git_branch: master
|
data/test/test.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
require 'octopress-deploy'
|
2
2
|
|
3
|
-
|
4
|
-
FileUtils.
|
5
|
-
|
3
|
+
def test_git
|
4
|
+
FileUtils.mkdir 'deploy_target'
|
5
|
+
FileUtils.cd 'deploy_target' do
|
6
|
+
system 'git init --bare'
|
7
|
+
end
|
8
|
+
Octopress::Deploy.init_config('git', git_url: File.expand_path("deploy_target"))
|
9
|
+
Octopress::Deploy.push()
|
10
|
+
FileUtils.rm_r 'deploy_target'
|
6
11
|
end
|
7
12
|
|
8
|
-
|
9
|
-
FileUtils.
|
13
|
+
def test_rsync
|
14
|
+
FileUtils.mkdir_p "deploy-rsync"
|
15
|
+
Octopress::Deploy.init_config('rsync', remote_path: '.deploy')
|
16
|
+
Octopress::Deploy.push()
|
17
|
+
FileUtils.rm_r 'deploy-rsync'
|
18
|
+
end
|
19
|
+
|
20
|
+
test_git
|
21
|
+
test_rsync
|
22
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.alpha.
|
4
|
+
version: 1.0.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
@@ -65,7 +65,9 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/octopress-deploy.rb
|
68
|
+
- lib/octopress-deploy/core_ext.rb
|
68
69
|
- lib/octopress-deploy/git.rb
|
70
|
+
- lib/octopress-deploy/rsync.rb
|
69
71
|
- lib/octopress-deploy/version.rb
|
70
72
|
- octopress-deploy.gemspec
|
71
73
|
- test/Gemfile
|