動作
如何在 Heroku 上安裝 Redmine (3.x.x)¶
參考以下文章:- https://stackoverflow.com/questions/39261996/heroku-and-rails-gem-load-error-with-postgres-however-it-is-specified-in-gemfi
- https://medium.com/mozaix-llc/how-to-deploy-redmine-to-heroku-41684d888b05
首先,將 Redmine 穩定版本原始碼使用 git clone 下載
git clone https://github.com/redmine/redmine.git -b 3.4-stable
並移動到 Redmine 專案目錄
cd redmine
編輯 .gitignore 檔案,並刪除以下幾行
Gemfile.lock Gemfile.local public/plugin_assets config/initializers/session_store.rb config/initializers/secret_token.rb config/configuration.yml config/email.yml
編輯 Gemfile,移除或註解掉以下區塊
database_file = File.join(File.dirname(__FILE__), "config/database.yml") if File.exist?(database_file) database_config = YAML::load(ERB.new(IO.read(database_file)).result) adapters = database_config.values.map {|c| c['adapter']}.compact.uniq if adapters.any? adapters.each do |adapter| case adapter when 'mysql2' gem "mysql2", "~> 0.4.6", :platforms => [:mri, :mingw, :x64_mingw] when /postgresql/ gem "pg", "~> 0.18.1", :platforms => [:mri, :mingw, :x64_mingw] when /sqlite3/ gem "sqlite3", (RUBY_VERSION < "2.0" && RUBY_PLATFORM =~ /mingw/ ? "1.3.12" : "~>1.3.12"), :platforms => [:mri, :mingw, :x64_mingw] when /sqlserver/ gem "tiny_tds", (RUBY_VERSION >= "2.0" ? "~> 1.0.5" : "~> 0.7.0"), :platforms => [:mri, :mingw, :x64_mingw] gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw, :x64_mingw] else warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems") end end else warn("No adapter found in config/database.yml, please configure it first") end else warn("Please configure your config/database.yml first") end
並新增以下區塊
group :production do
gem 'pg', '~> 0.20'
end
使用 bundle install 安裝 gem
bundle install
使用以下指令取得密鑰
rake generate_secret_token
在 config/environment.rb 中編輯為 "exit 1"(移除或註解掉)
exit 1
在 config/application.rb 中新增以下幾行
config.assets.initialize_on_precompile = false
建立 Heroku 應用程式
heroku apps:create -a APP_NAME
新增 PostgreSQL 附加元件
heroku addons:create heroku-postgresql
連結到遠端(Heroku)
heroku git:remote -a APP_NAME
使用以下指令部署到 Heroku
git add -A git commit -m “Redmine for Heroku deployment” git push heroku 3.4-stable:master
最後,進行遷移並載入預設資料
heroku run rake db:migrate heroku run rake redmine:load_default_data