Setup heroku environment on different machine - heroku

I have two laptops, one work laptop and another personal laptop. I have setup the Heroku environment on the work laptop. In git repo I have added github as origin and heroku as separate remote. Whenever I need to deploy anything I just use heroku remote to push my changes.
Now I have already cloned my code from github and also installed heroku-toolbelt on the second laptop. Now I want to push my code and access Postgres database from second laptop. But not sure how to do it. I am able to see the app config parameter by this command.
heroku config --app <MY-APP-NAME>
But when I try to access database I am not able to do so. The pg sub-command doesn't provide --app option to specify the app name.
I tried to look into heroku fork but this command will basically create another app from an existing app. I don't want to do this.
I also looked into herku git:clone but this command will basically clone the repo. I have already cloned my repo from githu.
I am not sure how to have the same heroku enviornment as I have on my work laptop.
EDIT1
I executed the following command to add heroku remote in git config.
heroku git:remote -a <MY-APP-NAME>
So I don't need to specify the --app option to access the config. It automatically picks the right config. But I when I try to access the Postgres database it gives me following error.
>heroku pg:psql
---> Connecting to DATABASE_URL
sh: psql: command not found
This exact same command works on another laptop.
EDIT2
I figured out the problem. Actually heroku is trying to run psql on my local box but psql was not installed on my machine and hence it couldn't successfully connect to remote database. So I executed the following command to install psql and it worked like charm.
brew install postgres

First add the git remote by executing the following line.
heroku git:remote -a <MY-APP-NAME>
Then make sure your system has the postgres client installed. If it is not installed then installed it using the following command.
brew install postgres
The above command is only valid for Mac which has brew installed. You can search internet to find the specific command for your own platform.

Related

Ruby app no longer able to access remote Heroku Postgres - AFTER installing Postgres.app locally

For months now, a ruby (sinatra) app "foo.rb" on my dev't Mac has been using a remote Heroku-hosted Postgres database.
The app does not use ANY local database, neither in development nor production.
For another project, I installed Postgress.app from Heroku, first removing a very OLD version as recommended, using brew remove postgresql
The next time I ran foo.rb, and tried at access the (remote) database with SomeModel.count, I get the error:
PG::ConnectionBad: FATAL: no pg_hba.conf entry for host , user , database , SSL off
I'm confused why the error shows my devt machine address when the database connection config points to a remote postgres url, and why it says SSL off.
Any thoughts how to get rid of the error? Is there any way to see the PATH to the pg_hba.conf it is complaining about, so I can verify it contains the correct host entries?
(I wonder if the pg gem has its own copy squirreled away somewhere.)
The copies of pg_hba.conf that I can find (in /Library/Application Support/XXXX for both the old and new Postgress.app versions) have the correct (and unchanged) host entries.
It looks like your script is trying to connect somewhere that is not properly configured
Things to check in that case:
your database.yml or connection string, DATABASE_URL matches your localhost from postgres.app
is your postgres.app is running and have a db server running (check the elephant icon on the top bar of your osx)
You installed and configured properly the postgres app you need to set the path, you can check by typing psql in a new terminal window, if it runs is ok to go.
Configure your $PATH to use the included command line tools (optional):
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
post your file or part of it in the question, it helps a lot to debug :)
The answer turned out to be:
comment out pg in Gemfile
bundle install
replace pg
bundle install
I suspect when the gem pg is installed, it dynamically establishes some link to postgresql, so if you move postgresql (as I did when I installed Postgres.app) you need to remove the pg gem then re-add it.

How can I run as root on Heroku?

I tried using sudo to run a command on Heroku. Then I get a message that I cannot use the sudo command on Heroku. My real question is: How can I run a command with root privilege on Heroku, because it is required for some of the commands I'm trying to run?
You cannot run as root on a Heroku Dyno, as Dynos are effectively containers, isolated from the host system. However, you should be able to install most packages via Buildpacks, either via first party supported buildpacks, thirdparty buildpacks, or via heroku-buildpack-apt. Attempting to alter any system files, will likely either not work, or will have unintended consequences.

heroku commands are hanging on windows CMD

I am new to heroku.I installed heroku toolbelt few days ago and was able to run commands like heroku version, heroku login and heroku create without any issue.Today I was trying to follow instructions in https://devcenter.heroku.com/articles/getting-started-with-spring-mvc-hibernate and installed PostgreSQL in my machine.But I am not able to run any of the commands suddenly.Cursor just keeps blinking.Could any one please advise me how to fix this
Solution 1: Install and use Cygwin
Solution 2:
Install Git for Windows with Git Bash option.
Then use the Git Bash CLI to execute Heroku commands.

heroku error: Unable to connect to heroku API

I'm trying to access heroku from my command line, and I keep getting this same error: "Unable to connect to heroku API. Please check your internet connectivity and try again."
My internet connectivity is fine.
This question has been asked on StackOverflow before, but I don't quite understand the answer that seemed to be effective, as I'm a complete newbie. Apparently, it might have to do with an environment variable?
The other answer suggested a missing heroku remote branch, but mine is set up.
What, exactly, should I do to regain my connection with heroku?
Thanks!
Get the same message "Unable to connect to heroku API. Please check your internet connectivity and try again." when using heroku toolbelt on Mac.
In my case I installed the heroku toolbelt using homebrew. Installing the heroku toolbelt from https://toolbelt.heroku.com/ can solve the issue.
Well, it seems to have been a problem with my antivirus program . . . I reinstalled that, and heroku is accessible again.
If you’re behind a firewall that requires use of a proxy to connect with external HTTP/HTTPS services, you can set the HTTP_PROXY or HTTPS_PROXY environment variables in your local developer environment, before running the heroku command.
For example, on a Unix system you could do something like this:
$ export HTTP_PROXY=http://proxy.server.com:portnumber
or
$ export HTTPS_PROXY=https://proxy.server.com:portnumber
$ heroku login
On a Windows machine, either set it in the System Properties/Environment Variables, or do it from the terminal:
> set HTTP_PROXY=http://proxy.server.com:portnumber
or
> set HTTPS_PROXY=https://proxy.server.com:portnumber
> heroku login
I Got the same error on Mac OS X 10.13, and it's work for me, since I am behind the proxy,It's gathered from the Heroku Dev center page
https://devcenter.heroku.com/articles/using-the-cli

Bored to write app name in every heroku command though I got only 1 app [duplicate]

This question already has answers here:
Is there a way to set a default app for Heroku Toolbelt?
(3 answers)
Closed 1 year ago.
Heroku toolbelt is always forcing me to write an app name at the end like this:
heroku pg:reset DATABASE --app [app_name]
Is there a way to set the default app to which all my CLI heroku commands will apply?
Going to post this just in case it helps someone else out. I had the same problem even though there was only one app installed. I had to switch my heroku remote url from https to git.
https://git.heroku.com/[heroku-app-1234].git
to
git#heroku.com:[heroku-app-1234].git
Then everything worked normally for myself.
git remote remove heroku
git remote add heroku git#heroku.com:[heroku-app-1234].git
If heroku is claiming that there are multiple apps in the folder you must have more than one remote in your .git/config.
Remove the extra heroku remote or set the default using git config heroku.remote remote_name
If you have the heroku-accounts plugin installed, switching to the heroku branch worked for me, as discussed in this answer.
To swap out your existing version of the heroku-accounts plugin, use:
heroku plugins:install https://github.com/heroku/heroku-accounts.git
Note that if you've followed #Moemars answer, you'll need to switch your git remote back to https.
If you run heroku from the Git repo linked to your Heroku app, you don't have to specify an app name (unless the repo is connected to multiple apps).
This seems to be the easiest way to fix the issue:
heroku git:remote -a <app_name>
Since this wasn't mentioned until now:
Apart from the git remote, the Heroku CLI also looks into the HEROKU_APP environment variable.
By using direnv, dotenv or similar tools for project-specific environments you can easily set the respective Heroku app for each project or directory.

Resources