Deploying Ruby on Rails - Is there a good alternative for Heroku?

I am starting a new small business, POC, if you want, and I want to deploy the Rails application somewhere. I found that there is Geroku, are there any other options?

+31
ruby-on-rails deployment heroku openshift
Jul 18 '13 at 15:30
source share
1 answer

Yes there is

This is a very good post that I found on this subject.

http://blog.sudobits.com/2013/02/15/heroku-alternatives-for-deploying-rails-applications

I looked at the options there one by one, and, to my humble opinion, OpenShift is the best option for a small website, at least to start developing and creating POC \ Prototype

Why is it better?

  • It gives you what Heroku will give you.
  • This gives you local (persistent) storage. Therefore, you do not need to pay for S3 on Amazon or its equivalent. I think at some point you would like to do this (use S3), but at least for that you do not need to invest in it.
  • The site seems to be faster
  • I find it more flexible in terms of control over what happens on the machine.

Are there any disadvantages?

  • The only drawback I could find in Openshift is that it seems that the deployment takes much longer than on Heroku, and the first time you access the website, there is a significant delay (but after the first time it works faster - not related to browser caching if you think this is a problem).

Perhaps the Gemfile section in this document https://www.openshift.com/blogs/converting-an-existing-rails-app-to-run-on-openshift can solve this problem ... I will try later

What are the steps I need to take to deploy an existing application on Openshift?

In many places I found explanations on how to create and deploy a new application , but it was a little difficult to understand how to put my existing application in OpenShift

That's why I want to explain that

Assumptions - Your git application is already executed - Its path is / home / dev / MyApp - now you are under / home / dev

  • Create an Openshift Account at https://www.openshift.com
  • Use command line tools, I found them more informative
  • Go to https://www.openshift.com/get-started
  • Follow steps 1..3 to install and configure command line tools.
  • cd to the application folder rails / home / dev / MyApp
  • Create a new application domain - Run: rhc domain-create <domain name>
  • Create an application in OpenShift by running

    rhc app-create -a MyApp -t ruby-1.9 --no-git

    -a sets the application name under OpenShift - it may be something completely different from your rails application name

    -t sets the type of application - I think Ruby 1.9 is currently their highest supported version.

    - no- git says not to create git - because we already have one

  • Setting up your database

    • Install the appropriate DB cartridge for your OpenShift application by calling

      rhc cartridge add <DB cartridge type> -a <Application Name>

      For example:

      rhc cartridge add mysql-5.1 -a MyApp

      It also supports MongoDB and PostgreSQL.

      (see here https://www.openshift.com/developers/technologies )

    • Change your .yml database to link to the OpenShift database. Now itโ€™s very simple, since OpenShift got most of its configuration as environment variables, and you can just use it wherever you need - for example:

     production: adapter: mysql encoding: utf8 database: <%=ENV['OPENSHIFT_APP_NAME']%> pool: 5 host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%> port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%> username: <%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%> password: <%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%> socket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%> 
  • Make sure everything works locally

    • Run: 'bundle install'
    • Run: 'rails s' - See that everything is in order
  • Git - Add an OpenShift repository as one of your remote repositories and push it

    • Make sure all your work is up to date, complete and in sync with your GitHub. This can save you a lot of headaches later.
    • Run: rhc app-show <application name> - this will show you all the information about your application. Copy git url
    • Launch: git remote add openshift <OpenShift repo URL>
    • Take all that OpenShift adds by combining

      Launch: git merge openshift/master -s recursive -X ours

    • Commit the changes: git commit -am 'adding OpenShift files

    • Click on OpenShift: git push openshift

That's all, now your application should be deployed to OpenShift

How to open my deployed website?

Using the rhc app-show <application name> command, you can see the URL of your site

This will usually be http://<application name>-<domain name>.rhcloud.com

Easy to change it to your domain

  • Just run rhc alias add <app name> <your domain>
  • Then in your DNS management. Edit the CNAME definition of 'www' to point to http://<application name>-<domain name>.rhcloud.com

How to connect to my OpenShift machine?

Again, using rhc app-show <application name> , you can see the SSH address Just run ssh <SSH address> to connect

How to start migration and seed automatically after deployment?

One good thing about OpenShift is the ability to add custom actions (action-hooks) that run at different stages of deployment.

You can read more about this here https://www.openshift.com/developers/deploying-and-building-applications

So far I will only talk about deploying action-hook

  • In your application folder, go to the .openshift / action_hooks file and create a file under it deploy
  • Make this file executable - Run: chmod +x deploy
  • Put some code in it

    For example:

    #! / Bin / bash

    echo "Launch deployment"

    pushd $ {OPENSHIFT_REPO_DIR}> / dev / null

    echo "Change directory to $ {OPENSHIFT_REPO_DIR} public"

    cd $ {OPENSHIFT_REPO_DIR}

    cd public

    echo "Creating a soft link for $ {OPENSHIFT_DATA_DIR} loads named downloads"

    ln -s $ {OPENSHIFT_DATA_DIR} downloads downloads

    echo "Run bundle exec rake db: migrate RAILS_ENV = production"

    bundle exec rake db: migrate RAILS_ENV = "production"

    echo "Run bundle exec rake db: seed RAILS_ENV = production"

    bundle exec rake db: seed RAILS_ENV = "production"

    popd> / dev / null

    • Further explanation of the soft link - for routing, you need to find the downloaded Carrierwave files.
  • Add the file to your git - git add deploy (from inside the folder, of course)
  • Commit your changes and click on remotehift remote

How to integrate Carrierwave so that I can upload files and save to OpenShift?

There are two points

  • Where will the files be saved? - It's easy.
  • Will routing know how to upload my downloaded files?

Setting the save path:

Set the initializer file \ carrierwave.rb as

 CarrierWave.configure do |config| if Rails.env.production? config.storage = :file config.enable_processing = true config.root = ENV['OPENSHIFT_DATA_DIR'] config.cache_dir = config.root + 'uploads' end end 

leave the loaders at your discretion, which means storage :file

and

def store_dir

"add-ons / # {model.class.to_s.underscore} / {# mounted_as} / {# model.id}"

end

Using the $ OPENSHIFT_DATA_DIR folder ensures that we can write files and stay there.

Make sure routing finds the files:

It took me a while to come up with this trick (not too much, just a couple of hours)

Rails routing knows how to link only folders located in the application folder - soo, on the OpenShift machine, it will look for the downloaded files folder (named uploads in our case) in the $ {OPENSHIFT_REPO_DIR} \ public folder, where a convenient link is placed in the file Deployment becomes convenient - it simply tricks the system and makes it accessible and extracts these files from a folder that is not in the application folder




I know that there are many reports about these problems and how to deploy them and thatโ€™s all, but I just wanted to put some order into it.

Of course, there may be errors and inaccuracies in what I wrote, since I did not document every step on the way, but only from what I remember, do not hesitate to correct me if I am mistaken in some details.

One of the best sources is OpenShift documentation

I hope these things help people and save you time and money.

Enjoy

+67
Jul 18 '13 at 15:30
source share



All Articles