heroku reference file path - ruby-on-rails

How do you reference a file when a ruby on rails application is deployed on Heroku? I'm using CURL::EASY and the cert parameter requires a path to the .p12 cert. This works on my local, but not when I deploy to heroku.

try bash with your heroku
heroku run bash -a your-app-name
It will connect you the file directory. Type ls to view all files of your application.
Try more Gemfile.lock to view the code on your file.

What you're looking for is:
Rails.root.join('/path/to/cert')
However, committing a private certificate file to a code repository is very poor practice, for numerous security reasons. A much preferrable solution would be to store the certificate in a heroku config file using:
heroku config:set CERTIFICATE="your cert source here"
And then pass it to Curl::Easy using:
my_curl_easy.cacert = ENV['CERTIFICATE']

Related

How to deploy file with sensitive data to heroku? (Rails project with Settingslogic gem)

Im using Settingslogic gem as alternative to Environment Variables, and I found it more convenient. But, how to deploy the application to Heroku if my file with configs is out of the repo? I mean, all configs I save in application.yml, which is included in .gitignore file (because there is sensitive data). And when I push it to heroku, server can't find this file and can't complete deploy.
I've tried to create the file from heroku bash, but after git push heroku master command, created file disappears, and deploy failes with the same error.
How can I implement this deploy with one config file, and how can I force heroku to read this file or store it if I have no it in Git? Thanks a lot!

Can a Rails app be deployed without using Heroku Toolbelt? If so, how?

I want to deploy rails app without using Heroku ToolBelt. Is it possible? If so, how? I'm only allowed to use Heroku dashboard; I'm not allowed to use any other cloud service :(
I have to run PostgreSQL commands, adding add-ons and setting configuration variables and possibly other tasks for which we have Heroku Toolbelt to deploy a application in production environment.
Error:
user#xx ~/Desktop/github/blog (master)
$ git push git#heroku.com:herokugui.git master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I don't want to use Heroku Toolbelt. That's why I am using Git commands to deploy code on Heroku. I am not able to push code to Heroku using Git commands. Is it possible to do this task without the toolbelt?
Another question I have is: is there any way to run PostgreSQL commands on Heroku GUI? If so, how?
It's not easy (as with Heroku toolbelt), but it's possible. It involves hanging around your Heroku dashboard at least, so make sure you can access it.
First off, you need a key. If you're on a Linux machine (as me), then in your home directory you should have a folder named .ssh (it may be hidden, hit Ctrl+H to reveal, again, if Linux) and a file id_rsa.pub in there. If not, you need to generate your SSH key first.
ssh-keygen -t rsa
That will prompt you for a folder, default is fine, just hit Enter, then enter the passphrase (twice) to protect your key from being accessed by anyone else on your computer: without a passphrase it's unencrypted and free for anyone to take and use from that machine.
Once that is done, locate your public key file: id_rsa.pub. Note: not id_rsa, it's a private key, you may not want to give it to anyone, it's much like your future Heroku password, except for it's insanely large for a password. Open id_rsa.pub, you should see stuff like:
ssh-rsa aWhOLELotofUnreadABLEGibbERishWHiCHiSactUALLyYourPubLIcKeY...
You need to enter that line into your account settings in Heroku dashboard, under SSH Keys. You can find more info on keys here, in Heroku docs. Make sure Heroku actually recognizes you by issuing this:
ssh -v git#heroku.com
It should state you're authenticated.
Now for the git address. I assume you know your way around git, so I'll keep it short: you'll need to derive your repository address from your app name. Heroku usually generates weird (yet somewhat poetic) names like falling-wind-1624 or shielded-fjord-1858. I'll take the first one as an example, this is how you add its address as a git remote:
git remote add heroku git#heroku.com:falling-wind-1624.git
I'll explain a bit of it below. So what the toolbelt does here, is to use your app name only, it just builds the URL the same way by adding a path to Heroku server. Once that's done, you should be able to push your code:
git push heroku master
I've named a Heroku remote heroku, above, that's why I'm using heroku name here, you can name it whatever you want and use this afterwards. Once you've pushed the code, the rest is up to you.

How to access Heroku from command line if directory has been deleted

A little while ago the files on my Macbook Pro were deleted by Apple, including a directory from which I used to access Heroku and be able to do command line operations in the Ruby/Rails console. Now that the directory is gone, I'm not sure if it's possible to access this repository from the command line, which I need to do to reduce the size of my database to stay within Heroku limits.
Update
before the directory was deleted on my mac, I used to simply cd into that directory and then run something like bundle exec heroku run console or heroku run bundle exec console, anyways if I did it from that directory heroku knew which application i was trying to access and it would take me into the rails console for it (where I could manipulate data)
Install the Heroku toolbelt (it's unclear whether you still have that)
From the terminal, perform a heroku login to authenticate
From a directory where you want the new app to live, run heroku git:clone APP-NAME
You'll now have a directory, which will have the latest files you pushed to Heroku - which will allow you to do things like git push heroku master, or heroku run rails console.
You probably want to then also attach your git repo where you are storing your source code with something like git remote add origin git#github.com:whoyouare/app-name.git
From the Heroku docs:
You can also take an existing Git repo and add a remote using the git URL provided when you created your app. You may need to do this to associate a Git repo with an existing application. The heroku git:remote command will add this remote for you based on your applications git url.
$ heroku git:remote -a falling-wind-1624
This will add your Heroku repo with the remote name of heroku to your working directory.

Unable to push ruby on rails master project to heroku windows 8

I have a problem whenever I do git push heroku master, it gives me the following error:
!Invalid path!
Syntax is: git#heroku.com<app>.git where <app> is your app's name
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I have used MSysGit and I created a ruby on rails project, pushed it to github.
then in the project folder I did heroku login, succesfully authenticated. Did heroku create sucessfully, created a RSA keypair, added it to heroku. then I try to push to heroku and it fails everytime, anyone able to help?
The problem is that your SSH key being used is NOT yet uploaded to Heroku. I'm not familiar with your Git client, but what you need to do is find your SSH key file, then run:
heroku keys:add /path/to/my/key.pub
This will upload your public SSH key to Heroku, allowing you to push your repository.

Heroku: upload single unversioned file

I have a Rails 4 application hosted by Heroku.
Seeing as I'm working on an open-source project, there are several unversioned files containing sensitive information listed in .gitignore. For example, I have a .secret file at the root of the app that contains the key with which cookies are encrypted. I created this file by running the rake secret command.
My problem is that I cannot send this file to my heroku app since it is not versioned, it is not included in the deployment. Furthermore, I am using Github and cannot risk having my key disclosed publicly in the commit history.
I have attempted to use the heroku run command to create the file (heroku run 'rake secret > .secret' to no avail). I have attempted to connect with the terminal using heroku run bash but as the filesystem is ephemeral, my changes are not preserved when I exit the terminal.
Do you have any idea how I could achieve having unversioned files on a Heroku application?
Secret data (keys, passwords, etc) should be stored as config vars on Heroku. They are then accessed via the ENV hash in your code.
If you use something like figaro, you can place these vars in an application.yml (don't commit the file)
application.yml:
SECRET_KEY: my_secret_key
Figaro then has a rake task to push these to heroku:
rake figaro:heroku
Or, you can manually set them:
heroku config:set SECRET_KEY=my_secret_key
Finally, access them in your app as:
ENV['SECRET_KEY']

Resources