4fe4526807
Reason being, 'exec' will run the shell command and then exit the ruby process. While 'system will run the shell command and then continue execution. I feel this is a better example as the first thing I did was write a rake task that chains multiple tasks together and the way 'exec' was ending the process cost me a bit of time trouble shooting why. |
||
---|---|---|
features/support | ||
lib | ||
.gitignore | ||
COPYING | ||
Gemfile | ||
middleman-deploy.gemspec | ||
Rakefile | ||
README.md | ||
USAGE |
middleman-deploy
Deploys a middleman built site via rsync, ftp, sftp, or git (e.g. gh-pages on github).
Installation
Add this to the Gemfile of the repository of your middleman site:
gem "middleman-deploy"
and run bundle install
.
Usage
$ middleman build [--clean]
$ middleman deploy [--build-before]
To automatically run middleman build
during middleman deploy
, turn on the
build_before
option while activating the deploy extension:
activate :deploy do |deploy|
# ...
deploy.build_before = true # default: false
end
Possible Configurations
Middleman-deploy can deploy a site via rsync, ftp, sftp, or git.
Checkout the wiki for advanced set-up options.
rsync
Make sure that rsync
is installed, and activate the extension by adding the
following to config.rb
:
activate :deploy do |deploy|
deploy.method = :rsync
deploy.host = "www.example.com"
deploy.path = "/srv/www/site"
# Optional Settings
# deploy.user = "tvaughan" # no default
# deploy.port = 5309 # ssh port, default: 22
# deploy.clean = true # remove orphaned files on remote host, default: false
# deploy.flags = "-rltgoDvzO --no-p --del" # add custom flags, default: -avz
end
Git (e.g. GitHub Pages)
Make sure that git
is installed, and activate the extension by adding the
following to config.rb
:
activate :deploy do |deploy|
deploy.method = :git
# Optional Settings
# deploy.remote = "custom-remote" # remote name or git url, default: origin
# deploy.branch = "custom-branch" # default: gh-pages
# deploy.strategy = :submodule # commit strategy: can be :force_push or :submodule, default: :force_push
end
If you use a remote name, you must first add it using git remote add
. Run
git remote -v
to see a list of possible remote names. If you use a git url,
it must end with '.git'.
Afterwards, the build
directory will become a git repo.
If you use the force push strategy, this branch will be created on the remote if
it doesn't already exist.
But if you use the submodule strategy, you must first initialize build folder as
a submodule. See git submodule add
documentation.
FTP
Activate the extension by adding the following to config.rb
:
activate :deploy do |deploy|
deploy.method = :ftp
deploy.host = "ftp.example.com"
deploy.path = "/srv/www/site"
deploy.user = "tvaughan"
deploy.password = "secret"
end
SFTP
Activate the extension by adding the following to config.rb
:
activate :deploy do |deploy|
deploy.method = :sftp
deploy.host = "sftp.example.com"
deploy.port = 22
deploy.path = "/srv/www/site"
# Optional Settings
# deploy.user = "tvaughan" # no default
# deploy.password = "secret" # no default
end
Multiple Environments
Deploy your site to more than one configuration using environment variables.
# config.rb
case ENV['TARGET'].to_s.downcase
when 'production'
activate :deploy do |deploy|
deploy.method = :rsync
deploy.host = "www.example.com"
deploy.path = "/srv/www/production-site"
end
else
activate :deploy do |deploy|
deploy.method = :rsync
deploy.host = "staging.example.com"
deploy.path = "/srv/www/staging-site"
end
end
# Rakefile
namespace :deploy do
def deploy(env)
puts "Deploying to #{env}"
system "TARGET=#{env} bundle exec middleman deploy"
end
task :staging do
deploy :staging
end
task :production do
deploy :production
end
end
$ rake deploy:staging
$ rake deploy:production
Breaking Changes
v0.1.0
- Removed the
--clean
command-line option. This option only applied to the rsync deploy method. The idea going forward is that command-line options must apply to all deploy methods. Options that are specific to a deploy method will only be available inconfig.rb
. - Removed
deploy
from theafter_build
hook. This caused adeploy
to be run each timebuild
was called. This workflow never made sense.deploy
was added to theafter_build
hook simply because it was available.
- Removed the
Thanks!
A BIG thanks to everyone who has contributed! Almost all pull requests are accepted.
Other
Inspired by the rsync task in Octopress.