Skip to content

Instantly share code, notes, and snippets.

@ezekg
Forked from schikulski/Mina WordPress deploy
Last active August 29, 2015 14:08
Show Gist options
  • Save ezekg/8b8e3b8e76eebb9ce20c to your computer and use it in GitHub Desktop.
Save ezekg/8b8e3b8e76eebb9ce20c to your computer and use it in GitHub Desktop.
require 'mina/git' # Require mina/git
set :term_mode, nil # Bug in OS X that makes the password promp kinda fishy...
set :domain, 'example.com' # The web servers SSH domain
set :deploy_to, '/home/user/my-site' # Full path to where you want Mina to deploy
set :repository, 'https://USERNAME@bitbucket.org/USERNAME/REPOSITORY.git' # The git repository Mina shall use
set :branch, 'master' # What git branch Mina should get
set :user, 'username' # What username to connect with through SSH
set :current_path, 'www' # What file should be the current version. Probably 'www', 'public_html' or perhaps 'current'.
set :keep_releases, '5' # How many releases should Mina keep on the server
# Shared paths and files for all versions.
set :shared_paths, ['app/uploads', '.env', '.htaccess']
# The SETUP task - creating the necessary directories
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/shared/app/uploads"]
end
# The DEPLOY task, clone git repository and linking the shared paths
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
invoke :'git:clone' # cloning repository
invoke :'deploy:link_shared_paths' # linking shared paths
invoke :'deploy:cleanup' # cleaning all releases, keeping x releases
end
end
# The ROLLBACK task - thanks Vinh Quốc Nguyễn! - http://code.tutsplus.com/articles/an-introduction-to-deploying-wordpress-with-mina--wp-34776
desc "Rollback to previous verison."
task :rollback => :environment do
queue %[echo "----> Start to rollback"]
queue %[if [ $(ls #{deploy_to}/releases | wc -l) -gt 1 ]; then echo "---->Relink to previos release" && unlink #{deploy_to}/current && ln -s #{deploy_to}/releases/"$(ls #{deploy_to}/releases | tail -2 | head -1)" #{deploy_to}/current && echo "Remove old releases" && rm -rf #{deploy_to}/releases/"$(ls #{deploy_to}/releases | tail -1)" && echo "$(ls #{deploy_to}/releases | tail -1)" > #{deploy_to}/last_version && echo "Done. Rollback to v$(cat #{deploy_to}/last_version)" ; else echo "No more release to rollback" ; fi]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment