Heroku: Difference between revisions

From Wiki RB4
Line 78: Line 78:
  heroku addons:create heroku-postgresql // add a PostgrsSQL database
  heroku addons:create heroku-postgresql // add a PostgrsSQL database
  heroku config // shows DB connection URL postgres://cepxizounlueue:e78e393778c5d3e6b5dd26d6ebff081f50d3e5c34a817ec4e8653b1dcf99e91e@ec2-3-230-122-20.compute-1.amazonaws.com:5432/defpfuas3qslld
  heroku config // shows DB connection URL postgres://cepxizounlueue:e78e393778c5d3e6b5dd26d6ebff081f50d3e5c34a817ec4e8653b1dcf99e91e@ec2-3-230-122-20.compute-1.amazonaws.com:5432/defpfuas3qslld
  postgres://
  postgres:
  cepxizounlueue
//
  cepxizounlueue // username
  :
  :
  e78e393778c5d3e6b5dd26d6ebff081f50d3e5c34a817ec4e8653b1dcf99e91e
  e78e393778c5d3e6b5dd26d6ebff081f50d3e5c34a817ec4e8653b1dcf99e91e // password
  @
  @
  ec2-3-230-122-20.compute-1.amazonaws.com
  ec2-3-230-122-20.compute-1.amazonaws.com

Revision as of 09:04, 16 April 2022

Installation

Concepts

  • all Heroku applications run in a collection of lightweight Linux containers called Dynos. To find out the dynos:
heroku ps
  • Procfiles can contain additional process types. For example, you can declare a background worker that processes items off a queue.
  • The set of dynos declared in your Procfile and managed by the dyno manager via heroku ps:scale are known as the dyno formation. These dynos do the app’s regular business (such as handling web requests and processing background jobs) as it runs. When you wish to do one-off administrative or maintenance tasks for the app, or execute some task periodically using Heroku Scheduler, you can spin up a one-off dyno.

Interface

Config and Environment Variables

  • config variables are static and available via heroku config or via the Heroku Dashboard
  • environment variables are dynamic and are available via heroku run env

Add Ons

Databases

  • documentation
  • connection information see config var DATABASE_URL [database type]://[username]:[password]@[host]:[port]/[database name]

Postgres

  • DB info dashboard -> <APPLICATION> -> Resources

Operation

Delete Application

heroku apps:destroy uweheuer-capstone

List all Applications

heroku apps

List all Domains (for Applications)

heroku domains

Logging

heroku logs --tail

Example

Official Tutorial

PS C:\Temp\python-getting-started> heroku login
  • clone example
  • create app and push code
  • start the app
PS C:\Temp\python-getting-started> heroku ps:scale web=1
Scaling dynos... done, now running web at 1:Free
PS C:\Temp\python-getting-started> heroku open
// opens https://arcane-peak-78109.herokuapp.com/
  • open the dashboard
  • stop it or scale it down to 0
heroku ps:scale web=0
  • prepare for running locally
PS C:\Temp\python-getting-started> python -m venv venv
PS C:\Temp\python-getting-started> .\venv\Scripts\activate
(venv) PS C:\Temp\python-getting-started> pip install -r .\requirements.txt
  • run it locally
(venv) PS C:\Temp\python-getting-started> python manage.py collectstatic
(venv) PS C:\Temp\python-getting-started> heroku local -f .\Procfile.windows

Spring Boot

cd C:\Uwes\eclipse\workspace_2020-12\SpringBoot
spring init --dependencies=web demo1 // create a spring app with Spring CLI
cd demo1
  • edit C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\src\main\java\com\example\demo1
git init
git add .
git commit -m "first commit"
heroku login
heroku create // creates an app and a Git remote (named heroku) associated with your local Git repository
  • When deploying an app, Heroku reads pom.xml file and installs the dependencies by running mvn clean install.
  • create C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\src\main\java\com\example\demo1\system.properties
  • add java versioin
git add .
git push heroku master
heroku open // opens the application https://intense-caverns-96515.herokuapp.com/ in a browser 
heroku addons:create heroku-postgresql // add a PostgrsSQL database
heroku config // shows DB connection URL postgres://cepxizounlueue:e78e393778c5d3e6b5dd26d6ebff081f50d3e5c34a817ec4e8653b1dcf99e91e@ec2-3-230-122-20.compute-1.amazonaws.com:5432/defpfuas3qslld
postgres:
//
cepxizounlueue // username
:
e78e393778c5d3e6b5dd26d6ebff081f50d3e5c34a817ec4e8653b1dcf99e91e // password
@
ec2-3-230-122-20.compute-1.amazonaws.com
:
5432
/
defpfuas3qslld
heroku info // shows basic application information
heroku run env // shows all dynamic environment varialbles

Resources