Merge pull request #6 from benben/master

FTP deployment
master
Tom Vaughan 2012-11-08 08:18:36 -08:00
commit b71dc4d8df
4 changed files with 78 additions and 3 deletions

View File

@ -95,6 +95,22 @@ To use a particular branch, add:
Default is `gh-pages`. Run `git branch -a` to see a list of possible
branches.
### Step 4c - FTP setup
#### These settings are required.
Edit `config.rb`, and add:
activate :deploy do |deploy|
deploy.method = :ftp
deploy.host = "ftp.example.com"
deploy.user = "tvaughan"
deploy.password = "secret"
deploy.path = "/srv/www/site"
end
Adjust these values accordingly.
### Step 5
middleman build [--clean]

View File

@ -62,6 +62,16 @@ activate :deploy do |deploy|
# run `git branch -a` to see a list of possible branches
deploy.branch = "some-other-branch-name"
end
# To deploy the build directory to a remote host via ftp:
activate :deploy do |deploy|
deploy.method = :ftp
# host, user, passwword and path *must* be set
deploy.host = "ftp.example.com"
deploy.user = "tvaughan"
deploy.password = "secret"
deploy.path = "/srv/www/site"
end
EOF
end
@ -140,6 +150,54 @@ EOF
orig.remote(remote).fetch
end
def deploy_ftp
require 'net/ftp'
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 ftp to #{user}@#{host}:#{path}"
ftp = Net::FTP.new(host)
ftp.login(user, pass)
ftp.chdir(path)
ftp.passive = true
Dir.chdir('build/') do
Dir['**/*'].each do |f|
if File.directory?(f)
begin
ftp.mkdir(f)
rescue
puts "Folder '#{f}' exists. skipping..."
end
else
begin
if File.binary?(f)
ftp.putbinaryfile(f, f)
else
ftp.puttextfile(f, f)
end
rescue Exception => e
reply = e.message
err_code = reply[0,3].to_i
if err_code == 550
if File.binary?(f)
ftp.putbinaryfile(f, f)
else
ftp.puttextfile(f, f)
end
end
end
end
end
end
ftp.close
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, :path, :clean, :remote, :branch, :after_build); end
class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build); end
class << self

View File

@ -16,10 +16,11 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
# The version of middleman-core your extension depends on
s.add_runtime_dependency("middleman-core", [">= 3.0.0"])
# Additional dependencies
s.add_runtime_dependency("git", "~> 1.2.0")
s.add_runtime_dependency("ptools")
end