📜 ⬆️ ⬇️

We transfer Redmine from VPS to Heroku or how to get a free project-management tool

This article provides step-by-step instructions on how to publish a Redmine application on Heroku web hosting.



First, let's decide why and why we / you need it. Who still does not know what Redmine is, this is a web application for project management and error tracking (bug tracker). This is a fairly popular open source application with many plugins.
')
Heroku is a web application hosting platform. The distinctive features of which are ease of use, minimal configuration and the ability to quickly change the required server resources (for example, if habraeffect is expected, you can quickly increase the required power). What we are interested in for this article is the opportunity to host the application for free.

Why do you need this article? Although the Heroku platform provides several advantages over VPS hosting, it also has limitations. This article reveals the complexity of the installation and is designed for the average experienced user.


We will install the current trunk version of Redmine. It requires rails 2.3.14 and one of the versions of ruby ​​1.8.7, 1.9.2, 1.9.3.

At the moment we have.


In the example we will use the 1.9.2-p180 version of ruby. First create a new gemset.
rvm use ruby-1.9.2-p180
rvm gemset create 'redmineheroku'
rvm use ruby-1.9.2-p180@redmineheroku


Now we need to get the latest version of Redmine, we will take it from the git repository.
mkdir redmine_heroku
cd redmine_heroku
git init
git remote add redmine git://github.com/edavis10/redmine.git
git fetch redmine
git merge redmine/master


Now we need to change the settings for connecting to the database. Although we will not run the application locally, we will need to download information from the existing Redmine, which is already using MySql, so we will use it. Example "/config/database.yml":
 production: adapter: mysql database: redmineheroku host: localhost username: db_user password: db_password encoding: utf8 development: adapter: mysql database: redmineheroku host: localhost username: db_user password: db_password encoding: utf8 


At the moment, the trunk version of Redmine uses rails gem version 2.3.14, so install it. Just install the gem to connect to the data base and create an empty database.
gem install rails --version 2.3.14
gem install mysql
rake db:create RAILS_ENV=production


Because we already have an existing database, we need to import it. To do this, install the mysql client and import the database dump, which is taken from the last backup.
sudo apt-get install mysql-client-core-5.1
mysql -udb_user -pdb_password -h127.0.0.1 redmineheroku < ~/mysqldump-file-path.sql

I want to draw your attention to the fact that if the short flag (-u, -p and -h) is used for mysql, then the next parameter should be written without a space.

Next, create a session_key with a command that will create a new file "/config/initializers/session_store.rb"
rake generate_session_store

Because we already have session_key from the previous installation, replace the newly created key in the file "/config/initializers/session_store.rb". If this is a new installation, do not touch anything.

If you used Redmine plugins, now is the time to install and update the database for them. We don’t have them, so we’ll skip this step.
RAILS_ENV=production rake db:migrate:upgrade_plugin_migrations

Now let's update the database.
RAILS_ENV=production rake db:migrate

If this is a new installation, then we will load the standard information with the command
RAILS_ENV=production rake redmine:load_default_data

Create folders if they do not already exist and remove "/config/initializers/session_store.rb" from .gitignore
mkdir tmp public/plugin_assets
sed -i '/\/config\/initializers\/session_store.rb/d' .gitignore


The main step came to an end. Add all changes to git.
git add .
git commit -m "Initial configuration"


Installing plugins


Just like that, Redmine will not fully work on Heroku, for this we need to install plugins. We will use giternal to install them.
gem install giternal

Create a new “config / giternal.yml” file
 redmine_heroku: path: vendor/plugins repo: http://github.com/edavis10/redmine_heroku.git redmine_s3: path: vendor/plugins repo: http://github.com/tigrish/redmine_s3.git 


Install the plugins.
giternal update
giternal freeze


Now we need to configure the redmine_s3 plugin. This plugin allows you to save Redmine upload files in Amazon S3. So if you do not have an S3 account on Amazon, then it's time to start it.

Create a file "config / s3.yml"
 production: access_key_id: YOUR_S3_ACCESS_KEY_ID secret_access_key: YOUR_S3_SECRET_ACCESS_KEY bucket: YOUR_S3_REDMINE_PRODUCTION_BUCKET cname_bucket: false development: access_key_id: YOUR_S3_ACCESS_KEY_ID secret_access_key: YOUR_S3_SECRET_ACCESS_KEY bucket: YOUR_S3_REDMINE_DEVELOPMENT_BUCKET cname_bucket: false 


Remove the "/ public / plugin_assets" from .gitignore and configure the changes.
sed -i '/\/public\/plugin_assets/d' .gitignore
rake heroku:setup


Now you need to change the session_key in the file "/config/initializers/session_store.rb" again because he was replaced when generating a variable. In an ideal world, we should not save any passwords in the repository, but for the sake of simplicity, this article will do just that.

Now you can make another stop and save the changes.
git add .
git commit -m "Configure plugins"


Transfer files


Because we transfer the existing installation, we also need to transfer all download files. To do this, copy all the current files from the VPS via SSH and download them to Amazon S3. We can not just copy to S3, because file structure will change.
scp user@123.456.789.000:~/vps_redmine/files/* ~/redmine_heroku/files/
RAILS_ENV=production rake redmine_s3:files_to_s3


We start the server


Install gem heroku, it is needed to create and configure our application on the heroku servers.
gem install heroku

Let's create a new heroku application with the name “redmine”. The name must be unique, so it must be replaced with a non-existing one.
heroku create redmine
git push heroku master


And the last step is to upload the local database to the heroku servers. Gem taps are needed for this command, so we will pre-install it.
gem install taps
heroku db:push

The application should be available at redmine.heroku.com.

Additional Information


Customize email notifications

For example, we will use the Google Mail mailbox. Create "/config/configuration.yml" with email configuration.
 production: email_delivery: delivery_method: :smtp smtp_settings: tls: true enable_starttls_auto: true address: "smtp.gmail.com" port: '587' domain: "smtp.gmail.com" authentication: :plain user_name: "email_address@gmail.com" password: "email_password" 


Remove this file from gitignore and save the changes.
sed -i '/\/config\/configuration.yml/d' .gitignore
git add .
git commit -m "email config"

And finally, update the version on the server
git push heroku master

Security setting

As mentioned above, it is not a good idea to save passwords to the repository. As a way out, all secret data can be put into global variables that can be added to heroku with the command
config:add key=val [...] # add one or more config vars
The only drawback is that in some cases you need to change the code. Read more here.

Performance

On a free tariff plan, our application has a lower priority, plus if it does not receive requests, it stops completely and will start on the first next request (which will be quite noticeable, since it will take about 10 seconds). To check the performance with multiple users, we used the free version of one service . To be honest, the results are quite optimistic and I do not quite believe in their accuracy. If you believe the schedule, then at 50 users at the same time, the delay will be no more than 3 seconds if users are close to the server. The server with our application is located in the city of Seattle ( Seattle ). But I must note that the application runs fairly quickly and much faster than on a cheap VPS.


Finally


As a result of the relocation of the Redmine application from VPS to Heroku, the costs and performance increased significantly. Theoretically, this cannot be called a free solution because we will have to pay for Amazon S3, but these costs can be called pennies.

This article was written using blog.firsthand.ca/2010/10/installing-redmine-on-heroku-with-s3.html

Source: https://habr.com/ru/post/135258/


All Articles