Skip to content
Blog Rails: How to Update the Source code of an existing app on Heroku

Rails: How to Update the Source code of an existing app on Heroku

Recently, i was working on an existing rails app hosted on Heroku.
After making few updates to the code, i was wondering on how to get it updated on Heroku.
This is what i did on my ubuntu machine.

  1. You will need access to the Heroku command-line client, Foreman, and the Git revision control system.

    For that i installed the Heroku Toolbelt on my machine using the command given below.

    wget -qO- https://toolbelt.heroku.com/install.sh | sh

  2. Login to the Heroku account

    Once Heroku toolbelt is installed, we’ll have access to the heroku command from our command shell. Log in using the email address and password you used when creating your Heroku account using the command given below.

    heroku login

    Eg:-

    dipin@localhost:~$ heroku login
    Enter your Heroku credentials.
    Email: [email protected]
    Password (typing will be hidden):
    Authentication successful.

  3. Add/Upload your key to Heroku

    To download/update the source code on heroku you will need to upload your public key to heroku. To do this just run the command given below.

    heroku keys:add

    Eg:-

    dipin@localhost:~$ heroku keys:add
    Found existing public key: /home/dipin/.ssh/id_rsa.pub
    Uploading SSH public key /home/dipin/.ssh/id_rsa.pub… done

    If you don’t have a key pair, it would generate one for you and upload it.

    dipin@localhost:~$ heroku keys:add
    Could not find an existing public key.
    Would you like to generate one? [Yn] Y
    Generating new SSH public key.
    Uploading SSH public key /home/dipin/.ssh/id_rsa.pub… done

  4. Clone the current git repo from Heroku to your machine

    The source code of an app is in a git repo on heroku. Log into your Heroku cpanel and get the git url of the app. See the image given below

    heroku git url
    Now clone the repo onto your machine using the command given below.

    git clone [email protected]:example.git

    Eg:-

    dipin@localhost:~/rails$ ls
    updated_app
    dipin@localhost:~/rails$ git clone [email protected]:example.git
    Initialized empty Git repository in /home/dipin/rails/example/.git/
    The authenticity of host ‘heroku.com (50.19.85.156)’ can’t be established.
    RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added ‘heroku.com,50.19.85.156’ (RSA) to the list of known hosts.
    remote: Counting objects: 3394, done.
    remote: Compressing objects: 100% (1329/1329), done.
    remote: Total 3394 (delta 2230), reused 3024 (delta 1955)
    Receiving objects: 100% (3394/3394), 8.38 MiB | 1.11 MiB/s, done.
    Resolving deltas: 100% (2230/2230), done.
    dipin@localhost:~/rails$ ls
    example updated_app
    dipin@localhost:~/rails$

  5. Update the code and commit/push it to Heroku

    Now update the git repo with the new source. Then commit and push the commits to Heroku.

    Eg:-

    dipin@localhost:~/rails$ cd example
    dipin@localhost:~/rails/example$ cp -r ../updated_app/* .
    dipin@localhost:~/rails/example$ git add *
    dipin@localhost:~/rails/example$ git commit -a -m "Updates"
    dipin@localhost:~/rails/example$ git push
    Counting objects: 9, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (5/5), 429 bytes, done.
    Total 5 (delta 4), reused 0 (delta 0)
    
    -----> Heroku receiving push
    -----> Ruby/Rails app detected
    -----> Installing dependencies using Bundler version 1.2.1
           Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
           Using rake (0.9.2.2)
           Using i18n (0.6.0)
           Using multi_json (1.3.6)
    .........
    .........
           Using unicorn (4.3.1)
           Using whenever (0.7.3)
           Using will_paginate (3.0.3)
           Your bundle is complete! It was installed into ./vendor/bundle
           Cleaning up the bundler cache.
    -----> Writing config/database.yml to read from DATABASE_URL
    -----> Preparing app for Rails asset pipeline
           Running: rake assets:precompile
           rake aborted!
           Alpha channel 3 must be between 0 and 1 for `rgba'
           (in /tmp/build_2launv61w6b1o/app/assets/stylesheets/application.css)
           Tasks: TOP => assets:precompile:primary
           (See full trace by running task with --trace)
           Precompiling assets failed, enabling runtime asset compilation
           Injecting rails31_enable_runtime_asset_compilation
           Please see this article for troubleshooting help:
           http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
    -----> Rails plugin injection
           Injecting rails_log_stdout
           Injecting rails3_serve_static_assets
    -----> Discovering process types
           Procfile declares types      -> web
           Default types for Ruby/Rails -> console, rake, worker
    -----> Compiled slug size: 30.6MB
    -----> Launching... done, v39
           http://example.herokuapp.com deployed to Heroku
    
    To [email protected]:example.git
       d8ae781..5df9ced  master -> master
    dipin@localhost:~/rails/example$
  6. Checking Logs

    If the app is not running check the logs. Fix the code and commit/push again.
    To see the logs use:

    heroku logs

I got the app updated on Heroku.
Hope, it does for you! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.