commit
f5dccd5c7d
5 changed files with 68 additions and 21 deletions
24
README.md
24
README.md
|
@ -6,7 +6,7 @@ Middleman Delpoy -- Deploy a [middleman](http://middlemanapp.com/) built site ov
|
|||
|
||||
## QUICK START
|
||||
|
||||
Be sure that `rsync` is installed.
|
||||
If deploying through `rsync`, be sure it is installed.
|
||||
|
||||
### Step 1
|
||||
|
||||
|
@ -27,22 +27,21 @@ Then run:
|
|||
|
||||
bundle install
|
||||
|
||||
### Step 4
|
||||
### Step 4a - Rsync setup
|
||||
|
||||
#### These settings are required.
|
||||
|
||||
Edit `config.rb`, and add:
|
||||
|
||||
activate :deploy do |deploy|
|
||||
deploy.user = "tvaughan"
|
||||
deploy.host = "www.example.com"
|
||||
deploy.path = "/srv/www/site"
|
||||
deploy.method = :rsync
|
||||
deploy.user = "tvaughan"
|
||||
deploy.host = "www.example.com"
|
||||
deploy.path = "/srv/www/site"
|
||||
end
|
||||
|
||||
Adjust these values accordingly.
|
||||
|
||||
### Step 4.1
|
||||
|
||||
#### These settings are optional.
|
||||
|
||||
To use a particular SSH port, add:
|
||||
|
@ -57,6 +56,17 @@ To remove orphaned files or directories on the remote host, add:
|
|||
|
||||
Default is `false`.
|
||||
|
||||
### Step 4b - Github Pages setup
|
||||
|
||||
Edit `config.rb`, and add:
|
||||
|
||||
activate :deploy do |deploy|
|
||||
deploy.method = :git
|
||||
end
|
||||
|
||||
The git deploy method assumes your project is in a repository with
|
||||
github set up as `origin` and a working `gh-pages` branch already in place.
|
||||
|
||||
### Step 5
|
||||
|
||||
middleman build
|
||||
|
|
|
@ -2,6 +2,8 @@ require "middleman-core/cli"
|
|||
|
||||
require "middleman-deploy/extension"
|
||||
|
||||
require 'git'
|
||||
|
||||
module Middleman
|
||||
module Cli
|
||||
|
||||
|
@ -18,18 +20,26 @@ module Middleman
|
|||
true
|
||||
end
|
||||
|
||||
desc "deploy", "Copy build directory to a remote host over rsync"
|
||||
desc "deploy", "Copy build directory to a remote host"
|
||||
method_option "clean",
|
||||
:type => :boolean,
|
||||
:aliases => "-c",
|
||||
:desc => "Remove orphaned files or directories on the remote host"
|
||||
def deploy
|
||||
shared_inst = ::Middleman::Application.server.inst
|
||||
send("deploy_#{self.middleman_options.method}")
|
||||
end
|
||||
|
||||
host = shared_inst.options.host
|
||||
port = shared_inst.options.port
|
||||
user = shared_inst.options.user
|
||||
path = shared_inst.options.path
|
||||
protected
|
||||
|
||||
def middleman_options
|
||||
::Middleman::Application.server.inst.options
|
||||
end
|
||||
|
||||
def deploy_rsync
|
||||
host = self.middleman_options.host
|
||||
port = self.middleman_options.port
|
||||
user = self.middleman_options.user
|
||||
path = self.middleman_options.path
|
||||
|
||||
# These only exists when the config.rb sets them!
|
||||
if (!host || !user || !path)
|
||||
|
@ -51,6 +61,30 @@ module Middleman
|
|||
run command
|
||||
end
|
||||
|
||||
def deploy_git
|
||||
puts "## Deploying to Github Pages"
|
||||
Dir.mktmpdir do |tmp|
|
||||
# clone ./ with branch gh-pages to tmp
|
||||
repo = Git.clone(ENV['MM_ROOT'], tmp)
|
||||
repo.checkout('origin/gh-pages', :new_branch => 'gh-pages')
|
||||
|
||||
# copy ./build/* to tmp
|
||||
FileUtils.cp_r(Dir.glob(File.join(ENV['MM_ROOT'], 'build', '*')), tmp)
|
||||
|
||||
# git add and commit in tmp
|
||||
repo.add
|
||||
repo.commit("Automated commit at #{Time.now.utc}")
|
||||
|
||||
# push from tmp to self
|
||||
repo.push('origin', 'gh-pages')
|
||||
|
||||
# push to github
|
||||
github_url = Git.open(ENV['MM_ROOT']).remote.url
|
||||
repo.add_remote('github', github_url)
|
||||
repo.push('github', 'gh-pages')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Alias "d" to "deploy"
|
||||
|
|
|
@ -5,7 +5,7 @@ require "middleman-core"
|
|||
module Middleman
|
||||
module Deploy
|
||||
|
||||
class Options < Struct.new(:host, :port, :user, :path, :clean); end
|
||||
class Options < Struct.new(:method, :host, :port, :user, :path, :clean); end
|
||||
|
||||
class << self
|
||||
|
||||
|
@ -17,6 +17,7 @@ module Middleman
|
|||
options = Options.new(options_hash)
|
||||
yield options if block_given?
|
||||
|
||||
options.method ||= :rsync
|
||||
options.port ||= 22
|
||||
options.clean ||= false
|
||||
|
||||
|
@ -25,8 +26,9 @@ module Middleman
|
|||
app.send :include, Helpers
|
||||
|
||||
app.after_configuration do
|
||||
if (!options.host || !options.user || !options.path)
|
||||
raise <<EOF
|
||||
if (options.method == :rsync)
|
||||
if (!options.host || !options.user || !options.path)
|
||||
raise <<EOF
|
||||
|
||||
|
||||
ERROR: middleman-deploy is not setup correctly. host, user, and path
|
||||
|
@ -39,6 +41,7 @@ activate :deploy do |deploy|
|
|||
end
|
||||
|
||||
EOF
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Middleman
|
||||
module Deploy
|
||||
PACKAGE = "middleman-deploy"
|
||||
VERSION = "0.0.3"
|
||||
VERSION = "0.0.4"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,11 @@ Gem::Specification.new do |s|
|
|||
s.name = Middleman::Deploy::PACKAGE
|
||||
s.version = Middleman::Deploy::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["Tom Vaughan"]
|
||||
s.authors = ["Tom Vaughan","Ben Cates"]
|
||||
s.email = ["thomas.david.vaughan@gmail.com"]
|
||||
s.homepage = "http://tvaughan.github.com/middleman-deploy/"
|
||||
s.summary = %q{Deploy a middleman built site over rsync.}
|
||||
s.description = %q{Deploy a middleman built site over rsync.}
|
||||
s.summary = %q{Deploy a middleman built site over rsync or to github pages.}
|
||||
s.description = %q{Deploy a middleman built site over rsync or to github pages.}
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
|
@ -21,5 +21,5 @@ Gem::Specification.new do |s|
|
|||
s.add_runtime_dependency("middleman-core", [">= 3.0.0"])
|
||||
|
||||
# Additional dependencies
|
||||
# s.add_runtime_dependency("gem-name", "gem-version")
|
||||
s.add_runtime_dependency("git", "~> 1.2.0")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue