octopress-deploy 1.0.0.alpha.3 → 1.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -48
- data/lib/octopress-deploy.rb +45 -82
- data/lib/octopress-deploy/commands.rb +38 -11
- data/lib/octopress-deploy/git.rb +11 -5
- data/lib/octopress-deploy/rsync.rb +15 -6
- data/lib/octopress-deploy/s3.rb +53 -44
- data/lib/octopress-deploy/version.rb +1 -1
- data/octopress-deploy.gemspec +1 -1
- data/test/Gemfile +0 -1
- data/test/test.rb +8 -8
- metadata +8 -9
- data/History.markdown +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3335ecc6a5982dd61e353698ee6ed3521a65b62f
|
4
|
+
data.tar.gz: 6b5fc858d82ed0290ea6553f2950f9741718a883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b4efe0fd05a85e1a68b75a04e1b3397654b6d0ab0f245d4a69fe77355d81a75ad6936496babc3764e9cf703396a61839de8056f7030a1dc43abdd11740f997
|
7
|
+
data.tar.gz: 5ba60aa87c352378fe530213d068e54e6e0b23db48f994cfc644cf4c258e65da58a857967d68d2d64e8a7d785e58dbd0ebf8805b7564193a2758d532f867f37c
|
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
Deployment tools for Octopress and Jekyll blogs (or really any static site).
|
4
4
|
|
5
|
-
Currently this supports deploying through S3, Git and Rsync.
|
6
|
-
deployment methods are welcome.
|
5
|
+
Currently this supports deploying through S3, Git and Rsync. Pull request to support other deployment methods are welcome.
|
7
6
|
|
8
7
|
## Installation
|
9
8
|
|
@@ -21,94 +20,129 @@ Or install it yourself as:
|
|
21
20
|
|
22
21
|
## Set up
|
23
22
|
|
24
|
-
|
23
|
+
First set up a configuration file for your deployment method.
|
25
24
|
|
26
|
-
```
|
27
|
-
$ octopress deploy
|
25
|
+
```sh
|
26
|
+
$ octopress deploy init git # or rsync, s3
|
28
27
|
```
|
29
28
|
|
30
|
-
This will
|
29
|
+
This will generate a `_deploy.yml` file in your current
|
30
|
+
directory which you can edit to add any necessary configuration.
|
31
|
+
**Remember to add your configuration to `.gitignore` to be sure
|
32
|
+
you never commit sensitive information to your repository.**
|
33
|
+
|
34
|
+
## Deploying
|
31
35
|
|
32
|
-
|
36
|
+
Deployment is tailored to work with Jekyll, but it will work for
|
37
|
+
any static site. Simply make sure your configuration points to
|
38
|
+
the root directory of your static site (For Jekyll, that's
|
39
|
+
probably `_site`) then tell Octopress to deploy it.
|
33
40
|
|
34
|
-
```
|
35
|
-
$ octopress deploy
|
41
|
+
```sh
|
42
|
+
$ octopress deploy
|
36
43
|
```
|
37
44
|
|
38
|
-
|
45
|
+
This will read your `_deploy.yml` configuration and deploy your
|
46
|
+
site. If you like, you can specify a configuration file.
|
39
47
|
|
40
|
-
```
|
41
|
-
|
48
|
+
```sh
|
49
|
+
$ octopress deploy --config _staging.yml
|
42
50
|
```
|
43
51
|
|
44
|
-
|
52
|
+
## Pull down your site
|
45
53
|
|
46
|
-
|
54
|
+
With the `pull` command, you can pull your site down into a local directory.
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
```sh
|
57
|
+
octopress deploy pull <DIRECTORY>
|
58
|
+
```
|
59
|
+
|
60
|
+
Mainly you'd do this if you're troubleshooting deployment and you want to see if it's working how you expected.
|
52
61
|
|
62
|
+
## Amazon S3 Deployment Configuration
|
53
63
|
|
54
|
-
|
64
|
+
To deploy with Amazon S3 you will need to install the [aws-sdk gem](https://rubygems.org/gems/aws-sdk).
|
55
65
|
|
56
|
-
Important: when using S3, you must add your _deploy.yml to your .gitignore to prevent accidentally sharing
|
57
|
-
account access information.
|
66
|
+
Important: when using S3, you must add your `_deploy.yml` to your .gitignore to prevent accidentally sharing
|
67
|
+
account access information.
|
58
68
|
|
59
|
-
| Config | Description
|
60
|
-
|
61
|
-
| `
|
62
|
-
| `
|
63
|
-
| `
|
64
|
-
| `
|
65
|
-
| `
|
66
|
-
| `
|
67
|
-
| `
|
69
|
+
| Config | Description | Default
|
70
|
+
|:--------------------|:------------------------------------------------------|:-------------|
|
71
|
+
| `method` | Deployment method, in this case use 's3' | |
|
72
|
+
| `site_dir` | Path to static site files | _site |
|
73
|
+
| `bucket_name` | S3 bucket name | |
|
74
|
+
| `access_key_id` | AWS access key | |
|
75
|
+
| `secret_access_key` | AWS secret key | |
|
76
|
+
| `remote_path` | Directory files should be synced to. | / |
|
77
|
+
| `verbose` | [optional] Display all file actions during deploy. | true |
|
78
|
+
| `region` | [optional] Region for your AWS bucket | us-east-1 |
|
79
|
+
| `delete` | Delete files in `remote_path` not found in `site_dir` | false |
|
68
80
|
|
69
81
|
If you choose a bucket which doesn't yet exist, Octopress Deploy will offer to create it for you, and offer to configure it as a static website.
|
70
82
|
|
71
|
-
|
83
|
+
If you configure Octopress to delete files, all files found in the `remote_path` on S3 bucket will be removed unless they match local site files.
|
84
|
+
If `remote_path` is a subdirectory, only files in that subdirectory will be evaluated for deletion.
|
85
|
+
|
86
|
+
### AWS config via ENV
|
72
87
|
|
73
|
-
|
88
|
+
If you prefer, you can store AWS access credentials in environment variables instead of a conifiguration file.
|
74
89
|
|
75
90
|
| Config | ENV var |
|
76
91
|
|:--------------------|:-------------------------------|
|
77
92
|
| `access_key_id` | AWS_ACCESS_KEY_ID |
|
78
93
|
| `secret_access_key` | AWS_SECRET_ACCESS_KEY |
|
79
|
-
| `region` | AWS_DEFAULT_REGIONS |
|
80
94
|
|
95
|
+
Note: configurations in `_deploy.yml` will override environment variables so be sure to remove those if you decide to use environment variables.
|
81
96
|
|
82
|
-
|
97
|
+
### Add a new bucket
|
83
98
|
|
84
|
-
If
|
85
|
-
|
99
|
+
If your AWS credentials are properly configured, you can add a new bucket with this command.
|
100
|
+
|
101
|
+
```sh
|
102
|
+
octopress deploy add_bucket
|
103
|
+
```
|
86
104
|
|
87
|
-
|
105
|
+
This will connect to AWS, create a new S3 bucket, and configure it for static website hosting. This command can use the settings in your deployment configuration or you can pass options to override those settings.
|
106
|
+
|
107
|
+
| Option | Description | Default
|
108
|
+
|:--------------|:-------------------------------------------------|:---------------|
|
109
|
+
| `--name` | Override the `bucket_name` configuration | |
|
110
|
+
| `--region` | Override the `region` configuration | |
|
111
|
+
| `--index` | Specify an index page for your site | index.html |
|
112
|
+
| `--error` | Specify an error page for your site | error.html |
|
113
|
+
| `--config` | Use a custom configuration file | _deploy.yml |
|
114
|
+
|
115
|
+
You'll only need to pass options if you want to override settings in your deploy config file.
|
116
|
+
|
117
|
+
## Git Deployment Configuration
|
88
118
|
|
89
119
|
Only `git_url` is required. Other options will default as shown below.
|
90
120
|
|
91
121
|
| Config | Description | Default
|
92
122
|
|:--------------|:-------------------------------------------------|:---------------|
|
93
|
-
| `
|
94
|
-
| `
|
95
|
-
| `
|
96
|
-
| `
|
123
|
+
| `method` | Deployment method, in this case use 'git' | |
|
124
|
+
| `site_dir` | Path to static site files | _site |
|
125
|
+
| `git_url` | Url for remote git repository | |
|
126
|
+
| `git_branch` | Deployment branch for git repository | master |
|
127
|
+
| `deploy_dir` | Directory where deployment files are staged | .deploy |
|
128
|
+
| `remote` | Name of git remote | deploy |
|
97
129
|
|
98
|
-
|
99
|
-
|
100
|
-
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.
|
130
|
+
## Rsync Deployment Configuration
|
101
131
|
|
102
132
|
| Config | Description | Default
|
103
133
|
|:---------------|:--------------------------------------------------|:---------------|
|
134
|
+
| `method` | Deployment method, in this case use 'rsync' | |
|
135
|
+
| `site_dir` | Path to static site files | _site |
|
104
136
|
| `user` | ssh user, e.g user@host.com | |
|
105
137
|
| `port` | ssh port | 22 |
|
106
|
-
| `remote_path` | Remote destination's document root
|
107
|
-
| `exclude_file` | Path to a file containing rsync exclusions
|
108
|
-
| `exclude` | Inline list of rsync exclusions
|
109
|
-
| `include` | Inline list of inclusions to override exclusions
|
138
|
+
| `remote_path` | Remote destination's document root | |
|
139
|
+
| `exclude_file` | Path to a file containing rsync exclusions | |
|
140
|
+
| `exclude` | Inline list of rsync exclusions | |
|
141
|
+
| `include` | Inline list of inclusions to override exclusions | |
|
110
142
|
| `delete` | Delete files in destination not found in source | false |
|
111
143
|
|
144
|
+
You can rsync to a local directory by configuring `remote_path` and leaving off `user` and `port`.
|
145
|
+
|
112
146
|
## Contributing
|
113
147
|
|
114
148
|
1. Fork it
|
data/lib/octopress-deploy.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path("../", __FILE__)
|
2
|
-
|
3
|
-
require 'octopress-deploy/version'
|
4
|
-
require 'octopress-deploy/core_ext'
|
2
|
+
#
|
5
3
|
require 'colorator'
|
6
4
|
require 'yaml'
|
7
|
-
require '
|
5
|
+
require 'octopress'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
require 'octopress-deploy/version'
|
8
|
+
require 'octopress-deploy/core_ext'
|
9
|
+
require 'octopress-deploy/commands'
|
12
10
|
|
13
11
|
|
14
12
|
module Octopress
|
@@ -18,34 +16,44 @@ module Octopress
|
|
18
16
|
autoload :S3, 'octopress-deploy/s3'
|
19
17
|
|
20
18
|
METHODS = {
|
21
|
-
'git'=> Git,
|
22
|
-
'rsync'=> Rsync,
|
23
|
-
's3'=> S3
|
19
|
+
'git' => Git,
|
20
|
+
'rsync' => Rsync,
|
21
|
+
's3' => S3
|
24
22
|
}
|
25
23
|
|
26
24
|
def self.push(options={})
|
27
25
|
init_options(options)
|
28
26
|
if !File.exists? @options[:config_file]
|
29
|
-
|
27
|
+
abort "File not found: #{@options[:config_file]}. Create a deployment config file with `octopress deploy init <METHOD>`."
|
30
28
|
else
|
31
29
|
parse_options
|
32
30
|
deploy_method.new(@options).push()
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
|
-
def self.pull(
|
34
|
+
def self.pull(options={})
|
37
35
|
init_options(options)
|
38
36
|
if !File.exists? @options[:config_file]
|
39
|
-
|
37
|
+
abort "No deployment config found. Create one with: octopress deploy init #{@options[:config_file]}"
|
40
38
|
else
|
41
39
|
parse_options
|
42
|
-
if !File.exists? @options[:
|
43
|
-
FileUtils.mkdir_p @options[:
|
40
|
+
if !File.exists? @options[:dir]
|
41
|
+
FileUtils.mkdir_p @options[:dir]
|
44
42
|
end
|
45
43
|
deploy_method.new(@options).pull()
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
47
|
+
def self.add_bucket(options={})
|
48
|
+
init_options(options)
|
49
|
+
if !File.exists? @options[:config_file]
|
50
|
+
abort "File not found: #{@options[:config_file]}. Create a deployment config file with `octopress deploy init <METHOD>`."
|
51
|
+
else
|
52
|
+
parse_options
|
53
|
+
deploy_method.new(@options).add_bucket()
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
49
57
|
def self.parse_options
|
50
58
|
config = YAML.load(File.open(@options[:config_file])).to_symbol_keys
|
51
59
|
@options = @options.to_symbol_keys
|
@@ -53,9 +61,9 @@ module Octopress
|
|
53
61
|
end
|
54
62
|
|
55
63
|
def self.init_options(options={})
|
56
|
-
@options
|
64
|
+
@options = options.to_symbol_keys
|
57
65
|
@options[:config_file] ||= '_deploy.yml'
|
58
|
-
@options[:site_dir]
|
66
|
+
@options[:site_dir] ||= site_dir
|
59
67
|
end
|
60
68
|
|
61
69
|
def self.deploy_method
|
@@ -72,26 +80,21 @@ module Octopress
|
|
72
80
|
|
73
81
|
# Create a config file
|
74
82
|
#
|
75
|
-
def self.init_config(
|
76
|
-
|
77
|
-
options[:method] = method
|
78
|
-
init_options(options)
|
79
|
-
end
|
83
|
+
def self.init_config(options={})
|
84
|
+
options = options.to_symbol_keys
|
80
85
|
|
81
|
-
|
82
|
-
|
86
|
+
if !options[:method]
|
87
|
+
abort "Please provide a deployment method. e.g. #{METHODS.keys}"
|
83
88
|
end
|
84
89
|
|
90
|
+
init_options(options)
|
85
91
|
write_config
|
86
92
|
check_gitignore
|
87
93
|
end
|
88
94
|
|
89
95
|
def self.write_config
|
90
|
-
if !@options[:
|
91
|
-
|
92
|
-
!ask_bool("A config file already exists at #{@options[:config_file]}. Overwrite?")
|
93
|
-
return puts "No config file written."
|
94
|
-
end
|
96
|
+
if File.exist?(@options[:config_file]) && !@options[:force]
|
97
|
+
abort "A config file already exists at #{@options[:config_file]}. Use --force to overwrite."
|
95
98
|
end
|
96
99
|
|
97
100
|
config = get_config.strip
|
@@ -100,71 +103,31 @@ module Octopress
|
|
100
103
|
puts "------------------"
|
101
104
|
puts "#{config.yellow}"
|
102
105
|
puts "------------------"
|
103
|
-
puts "
|
106
|
+
puts "Modify these configurations as necessary."
|
104
107
|
end
|
105
108
|
|
106
109
|
def self.get_config
|
107
110
|
<<-FILE
|
108
|
-
method: #{@options[:method]}
|
109
|
-
site_dir: #{@options[:site_dir]}
|
111
|
+
#{"method: #{@options[:method]}".ljust(40)} # How do you want to deploy? git, rsync or s3.
|
112
|
+
#{"site_dir: #{@options[:site_dir]}".ljust(40)} # Location of your your static site files.
|
113
|
+
|
110
114
|
#{deploy_method.default_config(@options)}
|
111
115
|
FILE
|
112
116
|
end
|
113
117
|
|
118
|
+
# Checks the repository's .gitignore for the config file
|
119
|
+
#
|
120
|
+
# returns: Boolean - whether it is present or not.
|
121
|
+
#
|
114
122
|
def self.check_gitignore
|
115
123
|
gitignore = File.join(`git rev-parse --show-toplevel`.strip, ".gitignore")
|
116
|
-
if !File.exist?(gitignore) ||
|
117
|
-
Pathname.new(gitignore).read.match(/^#{@options[:config_file]}/i).nil?
|
118
|
-
if ask_bool("Do you want to add #{@options[:config_file]} to your .gitignore?")
|
119
|
-
git_ignore_config_file gitignore
|
120
|
-
return true
|
121
|
-
end
|
122
|
-
else
|
123
|
-
return true
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def self.git_ignore_config_file(gitignore)
|
128
|
-
File.open(gitignore, 'a') { |f| f.write(@options[:config_file]) }
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.ask_bool(message)
|
132
|
-
ask_or_default(true, message) do
|
133
|
-
ask(message, ['y','n']) == 'y'
|
134
|
-
end
|
135
|
-
end
|
136
124
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
answer = get_stdin("#{message} [#{options}]: ").downcase.strip
|
142
|
-
if valid_options.map{|o| o.downcase}.include?(answer)
|
143
|
-
return answer
|
144
|
-
else
|
145
|
-
return false
|
146
|
-
end
|
147
|
-
else
|
148
|
-
answer = get_stdin("#{message}: ")
|
149
|
-
end
|
150
|
-
answer
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def self.get_stdin(message)
|
155
|
-
print message
|
156
|
-
STDIN.gets.chomp
|
157
|
-
end
|
158
|
-
|
159
|
-
def self.should_ask?
|
160
|
-
!ENV['NO_ASK']
|
161
|
-
end
|
162
|
-
|
163
|
-
def self.ask_or_default(default, message)
|
164
|
-
if should_ask?
|
165
|
-
yield
|
125
|
+
if !File.exist?(gitignore) ||
|
126
|
+
File.open(gitignore).read.match(/^#{@options[:config_file]}/i).nil?
|
127
|
+
puts "Remember to add #{@options[:config_file]} to your .gitignore."
|
128
|
+
false
|
166
129
|
else
|
167
|
-
|
130
|
+
true
|
168
131
|
end
|
169
132
|
end
|
170
133
|
end
|
@@ -3,20 +3,47 @@ module Octopress
|
|
3
3
|
class Commands < Octopress::Command
|
4
4
|
def self.init_with_program(p)
|
5
5
|
p.command(:deploy) do |c|
|
6
|
-
c.syntax "
|
6
|
+
c.syntax "deploy [options]"
|
7
7
|
c.description "Deploy your Octopress site."
|
8
|
-
c.option "using", "--using METHOD", "Define the push method to use, overriding your configuration file's setting"
|
9
8
|
c.option "config_file", "--config FILE", "The path to your config file (default: _deploy.yml)"
|
10
|
-
c.option "init", "--init METHOD", "Initialize a config file with the options for the given method."
|
11
|
-
c.option "pull", "--pull DIRECTORY", "Pull down the published copy of your site into a directory (default: ./site-pull)"
|
12
9
|
|
13
|
-
c.action do |
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
c.action do |args, options|
|
11
|
+
Octopress::Deploy.push(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
c.command(:pull) do |c|
|
15
|
+
c.syntax "pull <DIRECTORY>"
|
16
|
+
c.description "Pull down the published copy of your site into a directory (default: ./site-pull)"
|
17
|
+
c.option "config_file", "--config FILE", "The path to your config file (default: _deploy.yml)"
|
18
|
+
|
19
|
+
c.action do |args, options|
|
20
|
+
options['dir'] = args.first
|
21
|
+
Octopress::Deploy.pull(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
c.command(:init) do |c|
|
26
|
+
c.syntax 'init <METHOD> [options]'
|
27
|
+
c.description "Create a configuration file for a deployment method (#{Deploy::METHODS.keys.join(', ')})."
|
28
|
+
c.option 'force', '--force', 'Initialize a config file even if it already exists.'
|
29
|
+
|
30
|
+
c.action do |args, options|
|
31
|
+
options['method'] = args.first
|
32
|
+
Octopress::Deploy.init_config(options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
c.command(:add_bucket) do |c|
|
37
|
+
c.syntax 'add_bucket [options]'
|
38
|
+
c.description "Add a new S3 bucket and configure it for static websites."
|
39
|
+
c.option 'bucket_name','--name NAME','Choose a bucket name. (Defaults: to bucket_name in config file)'
|
40
|
+
c.option 'region','--region REGION','Choose a region. (Defaults: to region in config file)'
|
41
|
+
c.option 'index_page','--index PAGE','Specify an index page. (Default: index.html)'
|
42
|
+
c.option 'error_page','--error PAGE','Specify an error page. (Default: 404.html)'
|
43
|
+
c.option "config_file", "--config FILE", "The path to your config file (default: _deploy.yml)"
|
44
|
+
|
45
|
+
c.action do |args, options|
|
46
|
+
Octopress::Deploy.add_bucket(options)
|
20
47
|
end
|
21
48
|
end
|
22
49
|
end
|
data/lib/octopress-deploy/git.rb
CHANGED
@@ -5,13 +5,13 @@ module Octopress
|
|
5
5
|
def initialize(options={})
|
6
6
|
@options = options
|
7
7
|
@repo = @options[:git_url]
|
8
|
-
@branch = @options[:git_branch]
|
8
|
+
@branch = @options[:git_branch] || 'master'
|
9
9
|
@remote = @options[:remote] || 'deploy'
|
10
10
|
@remote_path = @options[:remote_path] || ''
|
11
11
|
@remote_path = @remote_path.sub(/^\//,'') #remove leading slash
|
12
|
-
@site_dir = File.expand_path(@options[:site_dir])
|
12
|
+
@site_dir = File.expand_path(@options[:site_dir]) || '_site'
|
13
13
|
@deploy_dir = File.expand_path(@options[:deploy_dir] || '.deploy')
|
14
|
-
@pull_dir = @options[:
|
14
|
+
@pull_dir = @options[:dir]
|
15
15
|
abort "Deploy Failed: Configure a git_url in #{@options[:config_file]} before deploying.".red if @repo.nil?
|
16
16
|
end
|
17
17
|
|
@@ -44,8 +44,14 @@ module Octopress
|
|
44
44
|
|
45
45
|
def self.default_config(options={})
|
46
46
|
<<-CONFIG
|
47
|
-
git_url: #{options[:git_url]}
|
48
|
-
git_branch: #{options[:git_branch] || 'master'}
|
47
|
+
#{"git_url: #{options[:git_url]}".ljust(40)} # remote repository url, e.g. git@github.com:username/repo_name
|
48
|
+
#{"git_branch: #{options[:git_branch] || 'master'}".ljust(40)} # Git branch where static site files are commited
|
49
|
+
|
50
|
+
# Note on git_branch:
|
51
|
+
# If using GitHub project pages, set the branch to 'gh-pages'.
|
52
|
+
# For GitHub user/organization pages or Heroku, set the branch to 'master'.
|
53
|
+
|
54
|
+
#{"# remote_path: #{options[:remote_path]}".ljust(40)} # Destination directory
|
49
55
|
CONFIG
|
50
56
|
end
|
51
57
|
|
@@ -12,9 +12,11 @@ module Octopress
|
|
12
12
|
@exclude_file = @options[:exclude_file]
|
13
13
|
@exclude_file = File.expand_path(@exclude_file) if @exclude_file
|
14
14
|
@include = @options[:include]
|
15
|
-
@
|
15
|
+
@exclude_file = @options[:include_file]
|
16
|
+
@exclude_file = File.expand_path(@include_file) if @include_file
|
17
|
+
@delete = @options[:delete] || false
|
16
18
|
@remote_path = @remote_path.sub(/^\//,'') #remove leading slash
|
17
|
-
@pull_dir = @options[:
|
19
|
+
@pull_dir = @options[:dir]
|
18
20
|
end
|
19
21
|
|
20
22
|
def push
|
@@ -35,6 +37,7 @@ module Octopress
|
|
35
37
|
cmd << " -e " if @exclude_file || @exclude
|
36
38
|
cmd << " --exclude-from #{@exclude_file} " if @exclude_file
|
37
39
|
cmd << " --exclude #{@exclude} " if @exclude
|
40
|
+
cmd << " --include-from #{@include_file} " if @include_file
|
38
41
|
cmd << " --include #{@include} " if @include
|
39
42
|
cmd << " --rsh='ssh -p#{@port}' " if @user && @port
|
40
43
|
cmd << " --delete " if @delete
|
@@ -52,10 +55,16 @@ module Octopress
|
|
52
55
|
|
53
56
|
def self.default_config(options={})
|
54
57
|
<<-CONFIG
|
55
|
-
user: #{options[:user]}
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
#{"user: #{options[:user]}".ljust(40)} # The user for your host, e.g. user@host.com
|
59
|
+
#{"remote_path: #{options[:remote_path]}".ljust(40)} # Destination directory
|
60
|
+
#{"delete: #{options[:delete]}".ljust(40)} # Remove files from destination which don't match files in source
|
61
|
+
|
62
|
+
#{"# port: #{options[:port]}".ljust(40)} # If your host requires a non standard port
|
63
|
+
#{"# exclude: ".ljust(40)} # Path to file containing list of files to exclude
|
64
|
+
#{"# exclude-file: ".ljust(40)} # Path to file containing list of files to exclude
|
65
|
+
#{"# include: ".ljust(40)} # Path to file containing list of files to include
|
66
|
+
#{"# include-file: ".ljust(40)} # Path to file containing list of files to include
|
67
|
+
|
59
68
|
CONFIG
|
60
69
|
end
|
61
70
|
|
data/lib/octopress-deploy/s3.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'find'
|
2
2
|
require 'fileutils'
|
3
|
-
require 'aws-sdk'
|
4
3
|
|
5
4
|
module Octopress
|
6
5
|
module Deploy
|
7
6
|
class S3
|
8
7
|
|
9
8
|
def initialize(options)
|
9
|
+
begin
|
10
|
+
require 'aws-sdk'
|
11
|
+
rescue LoadError
|
12
|
+
abort "Please install the aws-sdk gem first."
|
13
|
+
end
|
14
|
+
@options = options
|
10
15
|
@local = options[:site_dir]
|
11
16
|
@bucket_name = options[:bucket_name]
|
12
17
|
@access_key = options[:access_key_id] || ENV['AWS_ACCESS_KEY_ID']
|
@@ -16,40 +21,48 @@ module Octopress
|
|
16
21
|
@verbose = options[:verbose] || true
|
17
22
|
@delete = options[:delete]
|
18
23
|
@remote_path = @remote_path.sub(/^\//,'') # remove leading slash
|
19
|
-
@pull_dir = options[:
|
24
|
+
@pull_dir = options[:dir]
|
20
25
|
connect
|
21
26
|
end
|
22
27
|
|
23
28
|
def push
|
24
|
-
abort "Seriously, you should. Quitting..." unless Deploy.check_gitignore
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
#abort "Seriously, you should. Quitting..." unless Deploy.check_gitignore
|
30
|
+
@bucket = @s3.buckets[@bucket_name]
|
31
|
+
if !@bucket.exists?
|
32
|
+
abort "Bucket not found: '#{@bucket_name}'. Check your configuration or create a bucket using: `octopress deploy add_bucket`"
|
33
|
+
else
|
34
|
+
puts "Syncing #{@local} files to #{@bucket_name} on S3."
|
35
|
+
write_files
|
36
|
+
delete_files if delete_files?
|
37
|
+
status_message
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
def pull
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
@bucket = @s3.buckets[@bucket_name]
|
43
|
+
if !@bucket.exists?
|
44
|
+
abort "Bucket not found: '#{@bucket_name}'. Check your configuration or create a bucket using: `octopress deploy add_bucket`"
|
45
|
+
else
|
46
|
+
puts "Syncing #{@bucket_name} files to #{@pull_dir} on S3."
|
47
|
+
@bucket.objects.each do |object|
|
48
|
+
path = File.join(@pull_dir, object.key)
|
49
|
+
dir = File.dirname(path)
|
50
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
51
|
+
File.open(path, 'w') { |f| f.write(object.read) }
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
40
55
|
|
41
56
|
# Connect to S3 using the AWS SDK
|
42
57
|
# Retuns an aws bucket
|
58
|
+
#
|
43
59
|
def connect
|
44
60
|
AWS.config(access_key_id: @access_key, secret_access_key: @secret_key, region: @region)
|
45
|
-
s3 = AWS.s3
|
46
|
-
@bucket = s3.buckets[@bucket_name]
|
47
|
-
unless @bucket.exists? || create_bucket(s3.buckets)
|
48
|
-
abort "No bucket created. Change your config to point to an existing bucket."
|
49
|
-
end
|
61
|
+
@s3 = AWS.s3
|
50
62
|
end
|
51
63
|
|
52
64
|
# Write site files to the selected bucket
|
65
|
+
#
|
53
66
|
def write_files
|
54
67
|
puts "Writing #{pluralize('file', site_files.size)}:" if @verbose
|
55
68
|
site_files.each do |file|
|
@@ -64,6 +77,7 @@ module Octopress
|
|
64
77
|
end
|
65
78
|
|
66
79
|
# Delete files from the bucket, to ensure a 1:1 match with site files
|
80
|
+
#
|
67
81
|
def delete_files
|
68
82
|
if deletable_files.size > 0
|
69
83
|
puts "Deleting #{pluralize('file', deletable_files.size)}:" if @verbose
|
@@ -78,30 +92,24 @@ module Octopress
|
|
78
92
|
end
|
79
93
|
end
|
80
94
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
true
|
89
|
-
end
|
95
|
+
# Create a new S3 bucket
|
96
|
+
#
|
97
|
+
def add_bucket
|
98
|
+
puts @bucket_name
|
99
|
+
@bucket = @s3.buckets.create(@bucket_name)
|
100
|
+
puts "Created new bucket '#{@bucket_name}' in region '#{@region}'."
|
101
|
+
configure_bucket
|
90
102
|
end
|
91
103
|
|
92
104
|
def configure_bucket
|
93
|
-
error_page = remote_path('404.html')
|
94
|
-
index_page = remote_path('index.html')
|
105
|
+
error_page = @options['error_page'] || remote_path('404.html')
|
106
|
+
index_page = @options['index_page'] || remote_path('index.html')
|
95
107
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
cfg.error_document_key = error_page
|
100
|
-
end
|
101
|
-
puts "Bucket configured with index_document: #{index_page} and error_document: #{error_page}."
|
102
|
-
else
|
103
|
-
puts "You'll want to configure your new bucket using the AWS management console."
|
108
|
+
config = @bucket.configure_website do |cfg|
|
109
|
+
cfg.index_document_suffix = index_page
|
110
|
+
cfg.error_document_key = error_page
|
104
111
|
end
|
112
|
+
puts "Bucket configured with index_document: #{index_page} and error_document: #{error_page}."
|
105
113
|
end
|
106
114
|
|
107
115
|
def delete_files?
|
@@ -161,13 +169,14 @@ module Octopress
|
|
161
169
|
# Return default configuration options for this deployment type
|
162
170
|
def self.default_config(options={})
|
163
171
|
<<-CONFIG
|
164
|
-
bucket_name: #{options[:bucket_name]}
|
165
|
-
access_key_id: #{options[:access_key_id]}
|
166
|
-
secret_access_key: #{options[:secret_access_key]}
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
172
|
+
#{"bucket_name: #{options[:bucket_name]}".ljust(40)} # Name of the S3 bucket where these files will be stored.
|
173
|
+
#{"access_key_id: #{options[:access_key_id]}".ljust(40)} # Get this from your AWS console at aws.amazon.com.
|
174
|
+
#{"secret_access_key: #{options[:secret_access_key]}".ljust(40)} # Keep it safe; keep it secret. Keep this file in your .gitignore.
|
175
|
+
#{"remote_path: #{options[:remote_path] || '/'}".ljust(40)} # relative path on bucket where files should be copied.
|
176
|
+
|
177
|
+
#{"# region: #{options[:region] || 'us-east-1'}".ljust(40)} # Region where your bucket is located.
|
178
|
+
#{"# delete: #{options[:delete] || 'true'}".ljust(40)} # Remove files from destination which do not match source files.
|
179
|
+
#{"# verbose: #{options[:verbose] || 'true'}".ljust(40)} # Print out all file operations.
|
171
180
|
CONFIG
|
172
181
|
end
|
173
182
|
|
data/octopress-deploy.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_runtime_dependency "octopress", "~> 3.0.0.rc.1"
|
20
21
|
spec.add_runtime_dependency "colorator"
|
21
|
-
spec.add_runtime_dependency "aws-sdk"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
data/test/Gemfile
CHANGED
data/test/test.rb
CHANGED
@@ -67,9 +67,9 @@ def test_remote_git
|
|
67
67
|
|
68
68
|
# Test remote git deployment
|
69
69
|
#
|
70
|
-
Octopress::Deploy.init_config('git', config_file: config,
|
70
|
+
Octopress::Deploy.init_config(method: 'git', config_file: config, force: true, git_branch: 'test_git_deploy', git_url: repo)
|
71
71
|
Octopress::Deploy.push(config_file: config)
|
72
|
-
Octopress::Deploy.pull('pull-git', config_file: config)
|
72
|
+
Octopress::Deploy.pull(dir: 'pull-git', config_file: config)
|
73
73
|
diff_dir('_site', 'pull-git')
|
74
74
|
end
|
75
75
|
|
@@ -86,7 +86,7 @@ def test_local_git
|
|
86
86
|
# Test local git deployment
|
87
87
|
#
|
88
88
|
Octopress::Deploy.push(config_file: config, git_url: File.expand_path(repo), remote_path: 'site')
|
89
|
-
Octopress::Deploy.pull('pull-git', config_file: config, git_url: File.expand_path(repo), remote_path: 'site')
|
89
|
+
Octopress::Deploy.pull(dir: 'pull-git', config_file: config, git_url: File.expand_path(repo), remote_path: 'site')
|
90
90
|
diff_dir('_site', 'pull-git/site')
|
91
91
|
end
|
92
92
|
|
@@ -99,9 +99,9 @@ def test_remote_rsync
|
|
99
99
|
|
100
100
|
# Test remote git deployment
|
101
101
|
#
|
102
|
-
Octopress::Deploy.init_config('rsync', config_file: config,
|
102
|
+
Octopress::Deploy.init_config(method: 'rsync', config_file: config, force: true, user: 'imathis@imathis.com', remote_path: '~/octopress-deploy/rsync/')
|
103
103
|
Octopress::Deploy.push(config_file: config)
|
104
|
-
Octopress::Deploy.pull('pull-rsync', config_file: config)
|
104
|
+
Octopress::Deploy.pull(dir: 'pull-rsync', config_file: config)
|
105
105
|
diff_dir('_site', 'pull-rsync')
|
106
106
|
|
107
107
|
end
|
@@ -115,9 +115,9 @@ def test_local_rsync
|
|
115
115
|
|
116
116
|
# Test local git deployment
|
117
117
|
#
|
118
|
-
Octopress::Deploy.init_config('rsync', config_file: config,
|
118
|
+
Octopress::Deploy.init_config(method: 'rsync', config_file: config, force: true, remote_path: 'local-rsync')
|
119
119
|
Octopress::Deploy.push(config_file: config)
|
120
|
-
Octopress::Deploy.pull('pull-rsync', config_file: config, user: false, remote_path: 'local-rsync')
|
120
|
+
Octopress::Deploy.pull(dir: 'pull-rsync', config_file: config, user: false, remote_path: 'local-rsync')
|
121
121
|
diff_dir('_site', 'pull-rsync')
|
122
122
|
end
|
123
123
|
|
@@ -126,7 +126,7 @@ def test_s3
|
|
126
126
|
config = "_s3_deploy.yml"
|
127
127
|
`rm -rf pull-s3`
|
128
128
|
Octopress::Deploy.push(config_file: config)
|
129
|
-
Octopress::Deploy.pull('pull-s3', config_file: config)
|
129
|
+
Octopress::Deploy.pull(dir: 'pull-s3', config_file: config)
|
130
130
|
diff_dir('_site', 'pull-s3')
|
131
131
|
end
|
132
132
|
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: octopress
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0.rc.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0.rc.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: colorator
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
@@ -75,7 +75,6 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- Gemfile
|
78
|
-
- History.markdown
|
79
78
|
- LICENSE.txt
|
80
79
|
- README.md
|
81
80
|
- Rakefile
|
data/History.markdown
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
## HEAD
|
2
|
-
|
3
|
-
### Major Enhancements
|
4
|
-
|
5
|
-
### Minor Enhancements
|
6
|
-
|
7
|
-
* Ask user if they would like to ignore the `_deploy.yml` file & automate (#7)
|
8
|
-
|
9
|
-
### Bug Fixes
|
10
|
-
|
11
|
-
* Symbolize all incoming keys to `Octopress::Deploy.init_config` (#4)
|
12
|
-
|
13
|
-
### Development Fixes
|