Img source: redmine.org

Redmine is a flexible project management web application that is open source, written in Ruby on Rails. If you need to start using it for your own projects, then chances are you need to deploy it to a server. In this article, you can see how to deploy the current latest stable version of Redmine to Heroku, as it sometimes can be a bit problematic.

We first need to clone the latest stable version:
<span style="font-weight: 400;">git clone https://github.com/redmine/redmine.git -b 3.4-stable</span>

You can find the latest version by looking at the branches at Github.

Then we have to change the directory to the one in which redmine is currently located at:

<span style="font-weight: 400;">cd redmine </span>

Then we need to delete certain lines from .gitignore:

<span style="font-weight: 400;">Gemfile.lock</span>
<span style="font-weight: 400;">Gemfile.local</span>
<span style="font-weight: 400;">public/plugin_assets </span>
<span style="font-weight: 400;">config/initializers/session_store.rb </span>
<span style="font-weight: 400;">config/initializers/secret_token.rb </span>
<span style="font-weight: 400;">config/configuration.yml </span>
<span style="font-weight: 400;">config/email.yml</span>

Then we need to remove the following block from Gemfile:

<span style="font-weight: 400;">database_file = File.join(File.dirname(__FILE__), "config/database.yml")</span>
<span style="font-weight: 400;"> if File.exist?(database_file)</span>
<span style="font-weight: 400;">   database_config = YAML::load(ERB.new(IO.read(database_file)).result)</span>
<span style="font-weight: 400;">   adapters = database_config.values.map {|c| c['adapter']}.compact.uniq</span>
<span style="font-weight: 400;">   if adapters.any?</span>
<span style="font-weight: 400;">     adapters.each do |adapter|</span>
<span style="font-weight: 400;">       case adapter</span>
<span style="font-weight: 400;">       when 'mysql2'</span>
<span style="font-weight: 400;">         gem "mysql2", "~> 0.4.6", :platforms => [:mri, :mingw, :x64_mingw]</span>
<span style="font-weight: 400;">       when /postgresql/</span>
<span style="font-weight: 400;">         gem "pg", "~> 0.18.1", :platforms => [:mri, :mingw, :x64_mingw]</span>
<span style="font-weight: 400;">       when /sqlite3/</span>
<span style="font-weight: 400;">         gem "sqlite3", (RUBY_VERSION < "2.0" && RUBY_PLATFORM =~ /mingw/ ? "1.3.12" : "~>1.3.12"),</span>
<span style="font-weight: 400;">                        :platforms => [:mri, :mingw, :x64_mingw]</span>
<span style="font-weight: 400;">       when /sqlserver/</span>
<span style="font-weight: 400;">         gem "tiny_tds", (RUBY_VERSION >= "2.0" ? "~> 1.0.5" : "~> 0.7.0"), :platforms => [:mri, :mingw, :x64_mingw]</span>
<span style="font-weight: 400;">         gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw, :x64_mingw]</span>
<span style="font-weight: 400;">       else</span>
<span style="font-weight: 400;">         warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")</span>
<span style="font-weight: 400;">       end</span>
<span style="font-weight: 400;">     end</span>
<span style="font-weight: 400;">   else</span>
<span style="font-weight: 400;">    warn("No adapter found in config/database.yml, please configure it first")</span>
<span style="font-weight: 400;">   end</span>
<span style="font-weight: 400;"> else</span>
<span style="font-weight: 400;">  warn("Please configure your config/database.yml first")</span>
<span style="font-weight: 400;"> end</span>

We then need to add the block displayed down below:

<span style="font-weight: 400;">group :development, :test do</span>
<span style="font-weight: 400;">  gem 'sqlite3'</span>
<span style="font-weight: 400;">end</span>

<span style="font-weight: 400;">group :production do</span>
<span style="font-weight: 400;">  gem 'pg'</span>
<span style="font-weight: 400;">  gem 'rails_12factor'</span>
<span style="font-weight: 400;">  gem 'thin' # change this if you want to use other rack web server</span>
<span style="font-weight: 400;">end</span>

Then we need to install these gem files without production:

<span style="font-weight: 400;">bundle install --without production test</span><span style="font-weight: 400;">
</span>

Our application needs a secret token, which we can generate using the following command:

<span style="font-weight: 400;">rake generate_secret_token</span>

We need to create a heroku app:

<span style="font-weight: 400;">heroku create APP_NAME</span>

Then we need to avoid aborting when doing the deployment to Heroku, by commenting or removing the following line at config/environment.rb:

<span style="font-weight: 400;">exit 1</span><span style="font-weight: 400;">
</span>

We then need to add this line config/application.rb:

<span style="font-weight: 400;">config.assets.initialize_on_precompile = false</span>

We also need to add a database to this application:

<span style="font-weight: 400;">heroku addons:create heroku-postgresql</span><span style="font-weight: 400;">
</span>

Now we can commit and push our changes:

 


<span style="font-weight: 400;">git add -A</span>
<span style="font-weight: 400;">git commit -m “Prepare Redmine for Heroku deployment”</span>
<span style="font-weight: 400;">git push heroku 3.4-stable:master </span>

 

Notice that the version 3.4 may change at the time when you read this article, so it is probably better for you to get the latest version at GitHub and deploy it.

 

We also need to run the following rake tasks:


<span style="font-weight: 400;">heroku run rake db:migrate</span>
<span style="font-weight: 400;">heroku run rake redmine:load_default_data</span>

If we want to login into application, we can use a user that is created in the beginning:
Login: admin
Password: admin

If we want to reset the database, we can use the following:
heroku pg:reset DB_NAME

That’s all we need to do. We can now open the application deployed to Heroku:

<span style="font-weight: 400;">heroku open </span>