Building a dev environment in Heroku for Phoenix - heroku

I'm trying to set up Phoenix 1.2 so that I have two Heroku environments: one for dev/testing (which will keep the this-app-12345.herokuapp.com url), and a standard production environment.
Currently, I set up my app the usual way:
mix phoenix.new my_app
cd my_app
mix ecto.create
mix ecto.migrate
git init && git add . && git commit -m "Initial commit"
heroku create
This gives me a Heroku instance:
Creating app... done, ⬢ first-instance-12345
https://first-instance-12345.herokuapp.com/ | https://git.heroku.com/first-instance-12345.git
I then add the buildpacks, change the config/ files and run git push heroku master and everything works.
Now I'd like to create another Heroku instance, to which I can also deploy. If I run heroku create again, I get:
Creating app... done, ⬢ second-instance-23456
https://second-instance-23456.herokuapp.com/ | https://git.heroku.com/second-instance-23456.git
If I replace the url in prod.exs with the new instance...
config :my_app, MyApp.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "second-instance-23456.herokuapp.com", port: 443], force_ssl: [rewrite_on: [:x_forwarded_proto]],
...and then commit and run git push heroku master, it will still deploy to first-instance-12345.herokuapp.com, which isn't what I want.
Re-running buildpacks doesn't help either.
$ heroku buildpacks:add https://github.com/HashNuke/heroku-buildpack-elixir
▸ The buildpack https://github.com/HashNuke/heroku-buildpack-elixir is already set on your app.
$ heroku buildpacks:add https://github.com/gjaldon/phoenix-static-buildpack
▸ The buildpack https://github.com/gjaldon/phoenix-static-buildpack is already set on your app.
Is there a standard method (or any method) to get Phoenix to deploy to multiple heroku environments? (And hopefully specify which one/s on deploy)

The standard way to deploy an app to multiple Heroku apps is to add multiple remotes to the repo and push to the one you want to deploy to. Making that change to config/prod.exs will have no effect on where the app is deployed.
Here's how to add the two remotes:
$ git remote add first https://git.heroku.com/first-instance-12345.git
$ git remote add second https://git.heroku.com/second-instance-23456.git
Now you can deploy to the first one using:
$ git push first master
and to the second using:
$ git push second master

Certainly the best way to do so is to have two different instances as #dogbert wrote.
Also remember about changing Procfile for heroku, because you want to run app using different environments eg.
# Procfile for prod
web: MIX_ENV=prod mix phoenix.server
# Procfile for dev
web: MIX_ENV=dev mix phoenix.server
For both environments you would need to apply migrations:
heroku run MIX_ENV=<env> ecto.migrate

Related

heroku - Couldn't find that process type (web)

I am following the tutorial here
but I got the error
Scaling dynos... !
▸ Couldn't find that process type (web).
when doing
heroku ps:scale web=1
I followed the solution here
by delete the buildpack and use heroku buildpacks:set heroku/python
But the error still happend
and for buildpacks:
heroku buildpacks
=== teaching-system Buildpack URL
heroku/python
it seem to be correct
What is wrong with it?
This is what I did to past this error in Django. It's on Windows10
Add Procfile -in the same folder where you have git, manage.py
Procfile
-------------------------------
web: gunicorn <django-root-name(containing wsgi)>.wsgi --log-file -
Installing gunicorn(for later use)
>python -m pip install gunicorn
Clearing BuildPacks & fixing them
>heroku buildpacks:clear
>heroku buildpacks:add heroku/python
commit(empty-commit) & push
>git commit --allow-empty -m "Adjust push heroku master"
git push heroku master
That's what made me pass this scaling dyno.. blah blah
Update:
For local development, add following file
Procfile.windows
------------------------------------------
web: python manage.py runserver 0.0.0.0:5000
Make sure that you have a Procfile that is in the same directory as your Pipfile and Pipfile.lock files.
I'm using django and in Procfile I had:
#Procfile
web: gunicorn <my_project_name>.wsgi --log-file -
Install gunicorn if you haven't already. I had the same error and spent a long time trying to resolve it so I hope this helps. The syntax will change depending on what framework and language you're using, but the idea should be similar.
in Django,i solved creating the next files:
--------------------------------------------
**Procfile.windows** :
web: python manage.py runserver 0.0.0.0:5000
-------------------------------------------
**requirements.txt** :
django
gunicorn
django-heroku
------------------------------------------
**runtime.txt** :
python-3.7.7
-------------------------------------------------------
**Procfile** :
web: gunicorn <name of my main folder app>.wsgi --log-file -
----------------------
**.env** :
TIMES=2
----------------------
and after just do a commit to local repository,so the steps will be:
*
heroku login
heroku create
git commit -m "gogogo heroku"
git push heroku master
heroku ps:scale web=1
heroku open
*
I solved this problem a few week later in another Flask project
It was caused by loosing library: gunicorn in current virtual environment
It may have happened if you have modified your Procfile or renamed it after pushing to Heroku master. If so, you can try to make it work by rebuilding the index.
In my case this worked:
remove cached files (only the paths are removed from the index, not the real files!!!)
git rm -r --cached .
add all files to the index
git add .
commit
git commit -m "hopefully fixed error"
run rest of the heroku commands again
worked for me! hope it does for you.

Deploying Angular-fullstack app on Heroku using Codeship

I'm trying to deploy a website via CodeShip unto Heroku. The site is built with Yeoman's Angular-Fullstack generator, which is pushed to GitHub. Codeship detects the push, builds the entire thing and then the trouble start.
Angular-Fullstack is set up so that the dist/ folder contains the entire Heroku app, so blindly deploying everything will not work on Heroku.
Locally, I can use the Heroku toolbelt to login, add a remote inside the dist folder, and then use grunt buildcontrol to deploy the entire thing unto Heroku.
But in Codeship there are a few caveats:
* I cannot install the Heroku toolbelt with wget because it needs sudo and Codeship doesn't support that
* If I could, I couldn't login to Heroku using the CLI because I cannot interact with the shell in Codeship
* I cannot go into the dist/ folder and after adding the remote, simply push to Heroku because I need to enter my credentials.
Is there a way that I missed here? I'd like to let Codeship handle everything from building to deployment to Heroku (only on the master branch).
Figured it out!
I skipped the step where I was trying to install the Heroku Toolbelt, and just added the repo on Heroku as remote:
git remote add heroku ssh://git#heroku.com/[your-heroku-app-name].git
Codeship has public keys available for every build. So, I added that publick key to my Heroku account.
Then I noticed that Git was still trying to push using HTTPS instead of SSH, so I added this to the deployment script:
git config --global url.ssh://git#heroku.com/.insteadOf https://git.heroku.com/
This made sure that Git uses the SSH url for Heroku. I then let Codeship build the entire project and push it with grunt buildcontrol:heroku.

Multiple apps in git remotes when trying to access rails console

I have two git branches, staging and production, and I deployed them on Heroku in the same Heroku acccount. Suppose my app names are app1.heroku-app.com and app2.heroku-app.com and the remote names are heroku-staging and heroku-production,respectively. I deployed both apps on Heroku. After I login to Heroku from the console using heroku login and then try to access a Rails console using heroku run rails c, I get this message :
▸ multiple apps in git remotes
▸ remotes: heroku-staging heroku-production
How can I access a console?
If there's only one Heroku remote, heroku can infer which you want. When there are multiple (or if you want to access an application that doesn't have a remote in this Git repo, or when you're not in a Git repo at all), you need to use the --app option to specify which application you want a console on.
$ heroku --help
Usage: heroku COMMAND [--app APP] [command-specific-options]
$ heroku run rails c --app app1
$ heroku run rails c --app app2
In addition to being able to specify the app as a per-command flag, if you'd like for there to be a default environment, setting the environment variable HEROKU_APP to the app you want will make it so that heroku commands don't rely on git config.
$ heroku logs
› Error: Multiple apps in git remotes
...
$ export HEROKU_APP=app1
$ heroku logs
2018-12-31T03:56:34.888350+00:00 app[web.1]: 1.2.3.4 ...

How to deploy meteor 0.6.0 + to heroku

Im trying to deploy my meteor 0.6.3 app to heroku i tried using https://github.com/jordansissel/heroku-buildpack-meteor.git it only supports meteor 0.5.9 i also tried bundling my app in a .tgz file as suggested by the meteor docs but was not able to deploy I kept getting the no cedar app detected?
I had to do a bit of work to get Meteor 0.8.2 to deploy properly to Heroku. I'm posting the sequence of steps that worked for me. You could turn this into a parameterized Bash script, if you were so inclined.
# Define Meteor/Heroku app name:
export APP_NAME='Your-App-Name-Here'
# Create Meteor app:
meteor create --example leaderboard "${APP_NAME}"
cd "${APP_NAME}"
git init .
git add .
git commit -m 'Initial commit'
if ( heroku apps | egrep --silent "^${APP_NAME}$" )
then
# If re-using an existing Heroku app:
echo "Heroku app '${APP_NAME}' already exists; configuring..."
git remote remove heroku
heroku git:remote -a "${APP_NAME}"
heroku config:set \
BUILDPACK_URL=https://github.com/oortcloud/heroku-buildpack-meteorite.git
else
# If creating the Heroku app for the first time:
echo "Creating Heroku app '${APP_NAME}'..."
heroku create --stack cedar --app "${APP_NAME}" \
--buildpack https://github.com/oortcloud/heroku-buildpack-meteorite.git
fi
heroku config:add ROOT_URL="http://${APP_NAME}.herokuapp.com"
# Make sure you have a verified account to enable the mongohq:sandbox add-on
heroku addons:add mongohq:sandbox
# Visit: https://addons-sso.heroku.com/apps/${APP_NAME}/addons/mongohq:sandbox
open "https://addons-sso.heroku.com/apps/${APP_NAME}/addons/mongohq:sandbox"
# - Click 'add a database user'
# - Enter a user name and password, and click 'Add user'
# - Click 'Overview' tab
# Set the following variables appropriately, based on the user name, password, and
# values within the 'Mongo URI' string in the Overview tab
export MONGO_DB_HOST='kahana.mongohq.com'
export MONGO_DB_PORT='db-port'
export MONGO_DB_NAME='db-name'
export MONGO_DB_USER='db-user'
export MONGO_DB_PASS='db-pass'
# Calculate connection string and URL:
export MONGO_DB_CONN="${MONGO_DB_HOST}:${MONGO_DB_PORT}/${MONGO_DB_NAME}"
export MONGO_DB_URL="mongodb://${MONGO_DB_USER}:${MONGO_DB_PASS}#${MONGO_DB_CONN}"
# If you have mongo client installed, verify the connection:
export MONGO_CMD='mongo'
"${MONGO_CMD}" "${MONGO_DB_CONN}" -u "${MONGO_DB_USER}" -p"${MONGO_DB_PASS}"
heroku config:add MONGO_URL="${MONGO_DB_URL}"
# Verify configs look okay:
heroku config
# Configure a public/private SSH key pair in order to perform builds:
export HEROKU_RSA_NAME='id_rsa#herokuapp.com'
export HEROKU_RSA_FILE=~/.ssh/"${HEROKU_RSA_NAME}"
# If creating the keys for the first time:
[[ -f "${HEROKU_RSA_FILE}" ]] || {
ssh-keygen -t rsa -f "${HEROKU_RSA_FILE}"
ssh-add "${HEROKU_RSA_FILE}"
}
heroku keys:add "${HEROKU_RSA_FILE}.pub"
# Deploy the Meteor app via Git and the custom build pack:
git push heroku master
# Any errors?
heroku logs
# Make sure the Heroku app is running using one web dyno:
heroku ps:scale web=1
# Test the app
heroku open
Use this, works like a charm.
https://github.com/oortcloud/heroku-buildpack-meteorite
To those having trouble with the bash: node: command not found issue, I went through that too and I solved it by deleting the Procfile.
Apparently, the Procfile indicates Heroku to run the app using node main.js but node is not a valid command since it is not included in the PATH varialbe, or similar.
By deleting the Procfile, Heroku detects that the app is a meteor app and runs it using the node binary with the full path.
Sorry for posting an answer instead of a comment, but my reputation doesn't let me comment.
Also, remember the ROOT_URL must be set begining with http://
I am running two Meteor applications on Heroku (both apps are connected to mongolab, so external MongoDB instances).
Here I have documented how I did it:
.../how-to-deploy-meteor-on-heroku-with.html

Heroku toolbelt command requires app-name

How do you specify the app you want when you log in to Heroku from the command line?
I was trying to check the logs so when I first logged in I tried:
Heroku logs
this then told me:
! No app specified.
! Run this command from an app folder or specify which app to use with --app <app name>
I then tried:
heroku --app my-appname
but i get:
`--app` is not a heroku command.
I have tried all combinations.
You still need to include the command:
heroku logs --app app-name
You can also use -a instead of --app:
heroku logs -a app-name
Another option is to associate your (git) project to Heroku. From heroku open - no app specified:
$ cd app-dir
$ heroku git:remote -a app-name
$ heroku logs
Try this:
heroku git:remote -a [app_name]
This should allow you to call commands without having to specify which app you want them to be called on.
You could try adding --app app-name after you sentence.
Example: $ heroku domains:add your-domain --app app-name
Heroku CLI automatically detects the app name by scanning the git remotes for the current working copy.
If you're not in the app's local git clone, you need to specify the app name:
heroku logs --app app-name
or
heroku logs -a app-name
or by specifying the remote name:
heroku logs --remote production
You can reference this part of the Heroku documentation:
https://devcenter.heroku.com/articles/using-the-cli#app-commands
From my tests the Heroku CLI will infer the app from the current Git remote.
So to change to the "test" app:
git config heroku.remote test
And to come back to the default "heroku" application, which is probably your production app:
git config heroku.remote heroku
Not sure this is a good idea though...
For future solution seekers-
The error says a possible solution.
Run this command from an app folder
cd to the app directory root, then run your desired command.

Resources