部署 你们用 mina 是如何部署多环境 / 多服务器的?

est · 2014年12月01日 · 最后由 hammer 回复于 2015年04月03日 · 4825 次阅读

难道只能用 $ mina deploy -f config/deploy_staging.rb 这种很 low 的形式吗?

难道只能写多份.rb 文件吗?

https://ruby-china.org/topics/23176 rails_env = environments.keys.include?(ENV['RAILS_ENV']) ? ENV['RAILS_ENV'] : 'develop'

#1 楼 @rubyu2 多谢。

看来您部署是通过 RACK_ENV=production mina deploy 这样的命令了?

https://github.com/endoze/mina-multistage

或者简单些

task :staging do
  set :domain, 'xxx.xxx.xxx.xxx'
  set :user, 'user'
  set :rails_env, 'staging'
  # ...
end

task :production do
  set :domain, 'xxx.xxx.xxx.xxx'
  set :user, 'user'
  set :rails_env, 'production'
  # ...
end

然后部署的时候

mina staging deploy

#3 楼 @greatghoul 这个姿势好。强力学习。

#2 楼 @est@greatghoul的方法类似。 mina deploy RAILS_ENV=production1 deploy 脚本里可以用 ENV['RAILS_ENV'] 来获取 RAILS_ENV 环境变量,可以根据不同 RAILS_ENV 环境变量,set 不同的值,甚至执行不同的 task 都是可以的。

ruby 可以使用 key-value 的方式设置环境变量。

➜  ~  RAILS_ENV='staging' ruby -e "puts ENV['RAILS_ENV']"
staging
➜  ~  ruby -e "puts ENV['PATH']"
/Users/u2/.rvm/gems/ruby-2.0.0-p481/bin:/Users/u2/.rvm/gems/ruby-2.0.0-p481@global/bin:/Users/u2/.rvm/rubies/ruby-2.0.0-p481/bin:/Users/u2/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

而且也可以传递参数

➜  ~  ruby -e "p ARGV" foo bar 
["foo", "bar"]
case ENV['on']
when 'production'
  puts "production"
  set :domain, 'production.com'
  set :branch, 'master'
when 'stg'
  puts "stg"
  set :domain, 'stg.com'
  set :branch, 'dev'
else
  puts "stg"
  set :domain, 'stg.com'
  set :branch, 'dev'
end

# mina  deploy  on=stg

需要 登录 后方可回复, 如果你还没有账号请 注册新账号