We are going to deploy the latest version of the project on Heroku first and then we’ll see what we need to change if we want to deploy this version on local machine or a server.

Heroku deployment:

This link from Heroku dev center “Getting Started with Rails 3.x on Heroku” is covering the basics needed to connect to Heroku and deploy, which is a very simple process and it relies on git, and the three main commands is:

Creating the application on the Heroku to deploy on, you run this command from the project directory

 heroku create pageonex

And then push the project to the Heroku server via git

git push heroku master

Last command is to run the migrations, and that’s it

heroku run rake db:migrate

There is an important note, which is Heroku is using PostgreSQL for the production, so you will have to install PostgreSQL on you’r machine first, and the “pg” and run the bundle command before pushing the code

Installing PostgreSQL isn’t easy, and configuring it is much complex than MySQL for example, so my suggestion if you are not interested to use PostgreSQL (which you can do) so at least install it, so you’ll be able to install the pg gem and bundle the gems

The limitations of Heroku deployment, and how we are dealing with it:

  • Disk storage limitation which was causing this images low resolution problem, and this is happening because Heroku remove any images after few hours of storing them, and if the thread contains a huge number of images, so it will fail.The solution for this problem was that we’ve decided not to store the images on the disk, and we will use the direct links from Kiosko to display the images, so because we are trying to fetch many images from the same domain, so Kiosko server send the 300px images instead of the 740px to reduce the bandwidth, but we’ve added the original link of the image beside each image, so if you want to see the full image, you can copy and past the link in a new tab, and we didn’t use a direct link, because it’ll cause the same problem because the request comes from the same domain
  • The processing power is very limited (because it’s a free version for sure) so we are not be able to use any image processing libraries in this version like “RMagick”The solution is to comment this library, and use other ways to get the images coordinates (this was the use of RMagick in the kiosko scraper) and not to use the elpais scraper, because it use RMagick to convert the pdf scraped file into images
We are going no to see how to remove the limitation changes in the Heroku deployed version to back to the original code, because we have commented the parts which can’t fit for Heroku, instead of creating new branch for this version, so we’ll list all the files which have to be change, and which parts will have to change exactly in this files
The files that we’ll need to change, and the lines inside each one related to this, to add more highlighted areas:
  1.  app/assets/javascript/coding.js
    line 116-117:  change this with a loop over all highlighted areas
    line 161: change this method to loop over all highlighted areas
    line 229: change this method to  loop over all highlighted areas instead of checking with if statement for each one
    line 338: change this as the line 229
    line 297: change this to loop over all highlighted areas
  2. app/assets/javascript/display.js
    line 43: change this method to loop over all the highlighted areas
  3. app/views/coding/display.html.erb
    link 150-152: replace this two line with any number of highlighted areas
  4. app/views/coding/process_images.html.erb
    link 96-98: replace this two line with any number of highlighted areas
  5. app/controllers/threads_controller.rb
    line 133-136, 278-285: change this with any number of highlighted areas
The files that we’ll need to change and the lines inside each one related to this to, to switch to the older version, where we download the images and store them:
  1. lib/scraper.rb
    line 4: un-comment the RMagick library
    line 29-35: un-comment this part were we open the images links and path their content to saving method
    line 37-39: delete this part
    line 118-126: un-comment this part which save the downloaded image to the disk
    line 130-136: delete this part
  2. app/controller/threads_controller.rb
    line 95-96: un-comment this part, to get the images size
    line 98-100: delete this part
    line 105-106: un-comment this part
    line 234-235, 243-244: un-comment this part
  3. app/views/threads/index.html.erb
    line 21: un-comment this to get the images from the local storage
    line 23-25: delete this part
  4. app/views/threads/new.html.erb
    line 7-10: delete this part 
  5. app/views/coding/display.html.erb
    line 135: un-comment this line
    line 137-148: delete this part
  6. app/views/coding/process_images.html.erb
    line 60, 74: un-comment this line 
    line 62-68, 76-83: delete this part
  7. app/assets/javascript/coding.js
    line 216-219: delete this part
  8. app/assets/javascript/display.js
    line 141-144: delete this part

 

Notes on the pending feature, and how they can be implemented

  • Exporting the display result as an image
    The gem we’ll need is IMGKit, and in the coding controller we’ll use this gem to convert the rendered view into image
  • Create user profile pages
    We’ll override the user controller of Devise, and add a view for the user profile pages
  • Implementing tags
    To implement the full featured tags we’ll need to use ActsAsTaggableOn

One thought on “How to deploy PageOneX on Heroku and the required changes

  1. We’ve been testing this guide, and here are some tricks to make it work on heroku without the need of installing the (painful gem pg).

    0. Download the code in a s¡.zip at https://github.com/numeroteca/PageOneX-ruby
    or type in your console
    $ git clone git@github.com:numeroteca/PageOneX-ruby.git

    1. Go to the directory with the shell and type:
    $ heroku create pageonex //choose your name instead of “pageonex” like “pageonextester”
    it should return something like:
    “Creating pageonextester… done, stack is cedar I think so
    http://pageonextest.herokuapp.com/ | git@heroku.com:pageonextester.git ”

    After installing pg, you’ll have to run bundle, and then commit the GemFile.lock
    To install the pg gem you’ll need to install PostgreSQL
    In ubuntu via http://www.guia-ubuntu.org/index.php?title=PostgreSQL
    $ sudo aptitude install postgresql-8.2 postgresql-client-8.2 pgadmin3
    if you’re in OS X, try http://postgresapp.com via @dcabo
    Then run
    $ gem install pg

    BUT, if you are not able to make this work, there is a way to cheat heroku and not need to install and bundle the pg gem that @ahmdrefat discovered:
    Copy the content of the GemFile.lock (copy it from the last lines in this comment) and overwrite (copy+paste) your own GemFile.lock. Don’t bundle!

    2. inig a git repository
    $ git init //initiating
    $ git add . //adding all the files
    $ git commit -m “this is the first comment and the frist commit” //commiting

    3. login to your heroku account
    $ heroku login //create a previous one at http://www.heroku.com/

    4. ‘upload’ your project to heroku
    $ git push heroku master //if that fails try
    $ heroku keys:add ~/.ssh/id_rsa.pub //to send your key via http://stackoverflow.com/questions/4269922/permission-denied-publickey-when-deploying-heroku-code-fatal-the-remote-end

    5.
    $ heroku run rake db:migrate
    $ heroku run rake scraping:kiosko_names_cvs //to make the list of newspapers work

    6. Enjoy, go to the url generated http://pageonextester.herokuapp.com/ and enjoy!

    Soon you’ll no need to do all this, as we hope to deploy it in pageonex.com asap!

    —————-
    GemFile.lock to be used to make heroku work

    GEM
    remote: https://rubygems.org/
    specs:
    actionmailer (3.2.2)
    actionpack (= 3.2.2)
    mail (~> 2.4.0)
    actionpack (3.2.2)
    activemodel (= 3.2.2)
    activesupport (= 3.2.2)
    builder (~> 3.0.0)
    erubis (~> 2.7.0)
    journey (~> 1.0.1)
    rack (~> 1.4.0)
    rack-cache (~> 1.1)
    rack-test (~> 0.6.1)
    sprockets (~> 2.1.2)
    activemodel (3.2.2)
    activesupport (= 3.2.2)
    builder (~> 3.0.0)
    activerecord (3.2.2)
    activemodel (= 3.2.2)
    activesupport (= 3.2.2)
    arel (~> 3.0.2)
    tzinfo (~> 0.3.29)
    activeresource (3.2.2)
    activemodel (= 3.2.2)
    activesupport (= 3.2.2)
    activesupport (3.2.2)
    i18n (~> 0.6)
    multi_json (~> 1.0)
    addressable (2.2.8)
    arel (3.0.2)
    awesome_print (1.0.2)
    bcrypt-ruby (3.0.1)
    builder (3.0.0)
    capybara (1.1.2)
    mime-types (>= 1.16)
    nokogiri (>= 1.3.3)
    rack (>= 1.0.0)
    rack-test (>= 0.5.4)
    selenium-webdriver (~> 2.0)
    xpath (~> 0.1.4)
    childprocess (0.3.2)
    ffi (~> 1.0.6)
    coffee-rails (3.2.2)
    coffee-script (>= 2.2.0)
    railties (~> 3.2.0)
    coffee-script (2.2.0)
    coffee-script-source
    execjs
    coffee-script-source (1.3.3)
    commonjs (0.2.5)
    daemons (1.1.8)
    devise (2.0.4)
    bcrypt-ruby (~> 3.0)
    orm_adapter (~> 0.0.3)
    railties (~> 3.1)
    warden (~> 1.1.1)
    diff-lcs (1.1.3)
    erubis (2.7.0)
    eventmachine (0.12.10)
    execjs (1.4.0)
    multi_json (~> 1.0)
    factory_girl (3.0.0)
    activesupport (>= 3.0.0)
    factory_girl_rails (3.0.0)
    factory_girl (~> 3.0.0)
    railties (>= 3.0.0)
    faker (1.0.1)
    i18n (~> 0.4)
    ffi (1.0.11)
    foreman (0.51.0)
    thor (>= 0.13.6)
    guard (1.0.1)
    ffi (>= 0.5.0)
    thor (~> 0.14.6)
    guard-rspec (0.7.0)
    guard (>= 0.10.0)
    hike (1.2.1)
    i18n (0.6.0)
    journey (1.0.4)
    jquery-rails (2.0.2)
    railties (>= 3.2.0, < 5.0) thor (~> 0.14)
    jquery-ui-rails (1.1.0)
    jquery-rails
    railties (>= 3.1.0)
    json (1.7.3)
    launchy (2.0.5)
    addressable (~> 2.2.6)
    less (2.0.12)
    commonjs (~> 0.2.0)
    therubyracer (~> 0.9.9)
    less-rails (2.1.8)
    actionpack (>= 3.1)
    less (~> 2.0.7)
    libv8 (3.3.10.4)
    libwebsocket (0.1.3)
    addressable
    mail (2.4.4)
    i18n (>= 0.4.0)
    mime-types (~> 1.16)
    treetop (~> 1.4.8)
    mime-types (1.19)
    multi_json (1.3.6)
    nokogiri (1.5.5)
    orm_adapter (0.0.7)
    pg (0.14.0)
    polyglot (0.3.3)
    rack (1.4.1)
    rack-cache (1.2)
    rack (>= 0.4)
    rack-ssl (1.3.2)
    rack
    rack-test (0.6.1)
    rack (>= 1.0)
    rails (3.2.2)
    actionmailer (= 3.2.2)
    actionpack (= 3.2.2)
    activerecord (= 3.2.2)
    activeresource (= 3.2.2)
    activesupport (= 3.2.2)
    bundler (~> 1.0)
    railties (= 3.2.2)
    railties (3.2.2)
    actionpack (= 3.2.2)
    activesupport (= 3.2.2)
    rack-ssl (~> 1.3.2)
    rake (>= 0.8.7)
    rdoc (~> 3.4)
    thor (~> 0.14.6)
    rake (0.9.2.2)
    rdoc (3.12)
    json (~> 1.4)
    rspec (2.9.0)
    rspec-core (~> 2.9.0)
    rspec-expectations (~> 2.9.0)
    rspec-mocks (~> 2.9.0)
    rspec-core (2.9.0)
    rspec-expectations (2.9.1)
    diff-lcs (~> 1.1.3)
    rspec-mocks (2.9.0)
    rspec-rails (2.9.0)
    actionpack (>= 3.0)
    activesupport (>= 3.0)
    railties (>= 3.0)
    rspec (~> 2.9.0)
    rubyzip (0.9.9)
    sass (3.1.19)
    sass-rails (3.2.5)
    railties (~> 3.2.0)
    sass (>= 3.1.10)
    tilt (~> 1.3)
    selenium-webdriver (2.24.0)
    childprocess (>= 0.2.5)
    libwebsocket (~> 0.1.3)
    multi_json (~> 1.0)
    rubyzip
    sprockets (2.1.3)
    hike (~> 1.2)
    rack (~> 1.0)
    tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.6)
    therubyracer (0.9.10)
    libv8 (~> 3.3.10)
    thin (1.3.1)
    daemons (>= 1.0.9)
    eventmachine (>= 0.12.6)
    rack (>= 1.0.0)
    thor (0.14.6)
    tilt (1.3.3)
    treetop (1.4.10)
    polyglot
    polyglot (>= 0.3.1)
    twitter-bootstrap-rails (2.0.4)
    actionpack (>= 3.1)
    less-rails (~> 2.1.8)
    railties (>= 3.1)
    tzinfo (0.3.33)
    uglifier (1.2.5)
    execjs (>= 0.3.0)
    multi_json (~> 1.3)
    warden (1.1.1)
    rack (>= 1.0)
    xpath (0.1.4)
    nokogiri (~> 1.3)

    PLATFORMS
    ruby

    DEPENDENCIES
    awesome_print
    capybara
    coffee-rails (~> 3.2.1)
    devise
    factory_girl_rails
    faker
    foreman
    guard-rspec
    jquery-rails
    jquery-ui-rails
    launchy
    pg
    rails (= 3.2.2)
    rspec-rails
    sass-rails (~> 3.2.3)
    sqlite3
    thin
    twitter-bootstrap-rails
    uglifier (>= 1.0.3)

    Reply

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required