mina 部署配置

require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv'  # for rbenv support. (https://rbenv.org)
# require 'mina/rvm'    # for rvm support. (https://rvm.io)

# Basic settings:
#   domain       - The hostname to SSH to.
#   deploy_to    - Path to deploy into.
#   repository   - Git repo to clone from. (needed by mina/git)
#   branch       - Branch name to deploy. (needed by mina/git)

set :application_name, 'yourapp'
set :domain, 'hostname'
set :deploy_to, 'deploy_path'
set :repository, 'git@...'
set :branch, 'master'

# Optional settings:
  # set :user, 'Username'          # Username in the server to SSH to.
  # set :forward_agent, true     # SSH forward_agent.
  # set :port, '30000'           # SSH port number.

# shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step.

# set :shared_dirs, fetch(:shared_dirs, []).push('somedir')

# 要保证项目文件夹里有config文件夹,否则不能建立ln目标文件
# set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')

# This task is the environment that is loaded for all remote run commands, such as
# `mina deploy` or `mina rake`.
task :environment do
  # If you're using rbenv, use this to load the rbenv environment.
  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
  # invoke :'rbenv:load'

  # For those using RVM, use this to load an RVM version@gemset.
  # invoke :'rvm:use', 'ruby-2.2.4@default'
end

# Put any custom commands you need to run at setup
# All paths in `shared_dirs` and `shared_paths` will be created on their own.
task :setup do
  # command %{rbenv install 2.3.0}
end

desc "Deploys the current version to the server."
task :deploy do
  # uncomment this line to make sure you pushed your local branch to the remote origin
  # invoke :'git:ensure_pushed'

  # 自定义本地要执行的任务 :local/:remote
  run(:local) do
    invoke :'hexo:generate'
    invoke :'hexo:deploy'
  end

  # 加入本地ssh-key到ssh-add代理,以便远程主机有权限拉取代码
  run(:local) do
    command %{ ssh-add ~/.ssh/id_rsa}
  end


  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.

    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    # invoke :'bundle:install'
    # invoke :'rails:db_migrate'
    # invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      in_path(fetch(:current_path)) do
        # command %{mkdir -p tmp/}
        # command %{touch tmp/restart.txt}
        # 这里必须有可以执行的代码,否则运行时出错,没有代码要执行可以注释掉整个代码块
      end
    end
  end

  # you can use `run :local` to run tasks on local machine before of after the deploy scripts
  # run(:local) { touch 'hello.txt'}
end

# custom task
namespace :hexo do
  desc "genarte hexo posts"
  task :generate do
    def hexo_generate
      puts "Geginning generate posts"
      command %{ hexo g }
    end
    hexo_generate
  end

  desc "deploy hexo posts"
  task :deploy do
    def hexo_deploy
      puts "Deploying posts to git"
      command %{ hexo d }
    end
    hexo_deploy
  end

end
# For help in making your deploy script, see the Mina documentation:
#
#  - https://github.com/mina-deploy/mina/tree/master/docs