Merge branch 'master' of github.com:tvaughan/middleman-deploy

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
master
Tom Vaughan 2013-06-11 00:07:36 -04:00
commit ef47e6321a
4 changed files with 61 additions and 2 deletions

View File

@ -101,6 +101,22 @@ Edit `config.rb`, and add:
Adjust these values accordingly.
## Step 3d - SFTP setup
**These settings are required.**
Edit `config.rb`, and add:
activate :deploy do |deploy|
deploy.method = :sftp
deploy.host = "ftp.example.com"
deploy.user = "tvaughan"
deploy.password = "secret"
deploy.path = "/srv/www/site"
end
Adjust these values accordingly.
## Step 4
middleman build [--clean]

View File

@ -28,6 +28,7 @@ module Middleman
:aliases => "-c",
:desc => "Remove orphaned files or directories on the remote host"
def deploy
Middleman::Cli::Build.new.build if self.deploy_options.force_build
send("deploy_#{self.deploy_options.method}")
end
@ -158,7 +159,7 @@ EOF
end
#if there is a branch with that name, switch to it, otherwise create a new one and switch to it
if `git branch`.split("\n").delete_if{ |r| r =~ Regexp.new(branch,true) }.count == 0
if `git branch`.split("\n").any? { |b| b =~ /#{branch}/i }
`git checkout #{branch}`
else
`git checkout -b #{branch}`
@ -220,6 +221,45 @@ EOF
ftp.close
end
def deploy_sftp
require 'net/sftp'
require 'ptools'
host = self.deploy_options.host
user = self.deploy_options.user
pass = self.deploy_options.password
path = self.deploy_options.path
puts "## Deploying via sftp to #{user}@#{host}:#{path}"
Net::SFTP.start(host, user, :password => pass) do |sftp|
sftp.mkdir(path)
Dir.chdir(self.inst.build_dir) do
files = Dir.glob('**/*', File::FNM_DOTMATCH)
files.reject { |a| a =~ Regexp.new('\.$') }.each do |f|
if File.directory?(f)
begin
sftp.mkdir("#{path}/#{f}")
puts "Created directory #{f}"
rescue
end
else
begin
sftp.upload(f, "#{path}/#{f}")
rescue Exception => e
reply = e.message
err_code = reply[0,3].to_i
if err_code == 550
sftp.upload(f, "#{path}/#{f}")
end
end
puts "Copied #{f}"
end
end
end
end
end
end
# Alias "d" to "deploy"

View File

@ -5,7 +5,7 @@ require "middleman-core"
module Middleman
module Deploy
class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build); end
class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build, :force_build); end
class << self
@ -23,6 +23,7 @@ module Middleman
options.branch ||= "gh-pages"
options.after_build ||= false
options.force_build ||= false
app.after_build do |builder|
::Middleman::Cli::Deploy.new.deploy if options.after_build

View File

@ -11,6 +11,7 @@ Gem::Specification.new do |s|
s.homepage = "http://tvaughan.github.com/middleman-deploy/"
s.summary = %q{Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).}
s.description = %q{Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).}
s.license = "MIT"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@ -22,4 +23,5 @@ Gem::Specification.new do |s|
# Additional dependencies
s.add_runtime_dependency("ptools")
s.add_runtime_dependency("net-sftp")
end