`
clark1231
  • 浏览: 247525 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Deploy Rails App With Mina

阅读更多

原文请见我另外一个博客:http://caok1231.com/blog/2013/03/20/deploy-rails-app-with-mina/

 

capistrano是使用的最多的部署工具,最近社区中不少人开始推荐mina,试着用了下部署的速度的确快了很多。虽然mina最近两个月都没有更新,不过仍然希望这个项目能得到很好的发展。

 

下面简单总结下使用mina简单部署rails应用的过程。

 

1.安装mina

Gemfile中

group :development do

  gem 'mina', :git => 'git://github.com/nadarei/mina.git'

end

使用mina 0.2.1的时候可能会出现Mina hangs after entering SSH password, 而0.2.0的版本没有这个问题,但为了使用最新的版本可以直接从原项目中取(这样的话在执行mina命令时要加上bundle exec).

 

2.初始化mina

bundle

bundle exec mina init

它将创建部署文件config/deploy.rb

 

3.创建你的服务器

$ ssh username@your.server.com

 

# Once in your server, create the deploy folder:

~@your.server.com$ mkdir /var/www/foobar.com

~@your.server.com$ chown -R username /var/www/foobar.com

这样可以避免部署时出现的sudo的错误

 

4.配置mina

config/deploy.rb

require 'mina/bundler'

require 'mina/rails'

require 'mina/git'

require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)

# require 'mina/rvm'    # for rvm support. (http://rvm.io)

 

set :domain, 'foobar.com'                 # 设置你的ip地址或域名

set :deploy_to, '/var/www/foobar.com'     # 设置部署的路径

set :repository, 'git://...'              # git地址

#set :repository, File.expand_path('../../.git/', __FILE__)  #直接取本地的git项目

set :branch, 'master'                     # 确定代码分支

 

# 设置需要共享的文件

set :shared_paths, ['config/database.yml', 'log', 'tmp']

 

# 可选设置

set :user, 'foobar'    # SSH 用户名.

# set :port, '30000'   # SSH 端口,默认22.

 

# 设置对于大多数的命令(mina deploy或mina rake)都需要预先加载的环境

task :environment do

  # 如果使用的是rbenv,这么设置,但需确保.rbenv-version(rbenv local 1.9.3-p374)已经存在于你的项目中

  invoke :'rbenv:load'

 

  # 如果使用rvm,可以这样加载一个RVM version@gemset

  # invoke :'rvm:use[ruby-1.9.3-p374@default]'

end

 

# mina setup 时会执行的操作

task :setup => :environment do

  queue! %[mkdir -p "#{deploy_to}/shared/log"]              # 创建日志目录

  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]      # 设置日志目录权限

 

  queue! %[mkdir -p "#{deploy_to}/shared/config"]           # 创建配置目录

  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]   # 设置配置目录权限

 

  # 生成服务器的database.yml

  queue! %[cd #{deploy_to}/shared && git archive --remote=#{repository} #{branch} config | tar -x config/database.yml]

end

 

# 进行mina deploy会进行的操作

desc "Deploys the current version to the server."

task :deploy => :environment do

  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'

 

    to :launch do

      queue 'touch tmp/restart.txt'

    end

  end

end

 

5.服务器目录初始化

bundle exec mina setup

也可以这样操作,使提示更加详细些

bundle exec mina setup --verbose

6.进行项目部署

bundle exec mina deploy

查看其他命令

mina tasks

 

原文请见我另外一个博客:http://caok1231.com/blog/2013/03/20/deploy-rails-app-with-mina/

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics