Heroku: Difference between revisions

From Wiki RB4
 
(23 intermediate revisions by the same user not shown)
Line 9: Line 9:


===Interface===
===Interface===
* [https://id.heroku.com/login Dashboard]
* [https://id.heroku.com/login Dashboard] login with user, password and Salesforce App on mobile


===Config and Environment Variables===
===Config and Environment Variables===
Line 24: Line 24:


==Operation==
==Operation==
===List all Applications===
heroku apps
===Delete Application===
===Delete Application===
  heroku apps:destroy uweheuer-capstone
  heroku apps:destroy uweheuer-capstone


===List all Applications===
===Show Infos for Apps like Repo Size===
  heroku apps
  heroku apps:info


===List all Domains (for Applications)===
===List all Domains (for Applications)===
Line 34: Line 37:


===Logging===
===Logging===
* via dasboard
[[File:heroku1.PNG|400px]]
* or via command line
  heroku logs --tail
  heroku logs --tail


Line 59: Line 65:
* open it http://localhost:5000/
* open it http://localhost:5000/


===Spring Boot===
===Spring Boot Demo===
* from [https://devcenter.heroku.com/articles/deploying-spring-boot-apps-to-heroku offical Spring Boot tutorial]
====Configuration for Heroku====
cd C:\Uwes\eclipse\workspace_2020-12\SpringBoot
* steps from [https://devcenter.heroku.com/articles/deploying-spring-boot-apps-to-heroku offical Spring Boot tutorial]
spring init --dependencies=web demo1 // create a spring app with Spring CLI
* create demo1 application in <code>C:\Uwes\Programme\eclipse\workspace\demo1</code> and git it
cd demo1
* see SpringBoot.docx
* edit <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\src\main\java\com\example\demo1</code>
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 <code>pom.xml</code> file and installs the dependencies by running <code>mvn clean install</code>.  
* When deploying an app, Heroku reads <code>pom.xml</code> file and installs the dependencies by running <code>mvn clean install</code>.  
* in order to run it locally change java version in <code>pom.xml</code> from 11 to 8
* check DB connection by
* create <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\src\main\java\com\example\demo1\system.properties</code> and add java version 1.8
C:\Uwes\Programme\PostgreSQL\12\bin> .\[[Postgres#Operation|psql]] -h ec2-3-230-122-20.compute-1.amazonaws.com -U cepxizounlueue defpfuas3qslld
git add .
* set specific configurations for Heroku by adding profile <code>heroku</code> to <code>pom.xml</code> and set config var <code>MAVEN_CUSTOM_OPTS</code> to <code>-P !local_dev,heroku</code>
 
====Run on Heroku====
  git push heroku master
  git push heroku master
  heroku open // opens the application https://intense-caverns-96515.herokuapp.com/ in a browser  
  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 // DB
* check DB connection by
C:\Uwes\Programme\PostgreSQL\12\bin> .\psql -h ec2-3-230-122-20.compute-1.amazonaws.com -U cepxizounlueue defpfuas3qslld
* more infos
heroku info // shows basic application information
heroku run env // shows all dynamic environment varialbles


===Prepare and Run Locally===
====Prepare Locally Heroku====
* create Procfile <code>Procfile.windows</code> for running locally with command to start the Spring application <code>java -jar target/demo1-0.0.1-SNAPSHOT.jar</code>
* create Procfile <code>Procfile.windows</code> for running locally with command to start the Spring application <code>java -jar target/demo1-0.0.1-SNAPSHOT.jar</code>
* compile and build a JAR, with dependencies, placing it into your application’s target directory. The <code>spring-boot-maven-plugin</code> in the <code>pom.xml</code> provides this process
* compile and build a JAR, with dependencies, placing it into your application’s target directory. The <code>spring-boot-maven-plugin</code> in the <code>pom.xml</code> provides this process
  mvn install
  mvn install
* run the application
heroku local -f Procfile.windows
* create local DB
* create local DB
  C:\Uwes\Programme\xampp7.2.27\mysql\bin\mysql --user=root --password=mHalloo0@1m
  C:\Uwes\Programme\xampp7.2.27\mysql\bin\mysql --user=root --password=mHalloo0@1m
Line 106: Line 88:
* create <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\set_local_dev.bat</code>
* create <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\set_local_dev.bat</code>
* add profile local_dev to <code>pom.xml</code>
* add profile local_dev to <code>pom.xml</code>
====Run Heroku Locally====
* run the application
set_local_dev.bat
// start eclipse by start_eclipse.bat from shell and run it or
heroku local -f Procfile.windows
====Run Eclipse Locally====
* see <code>src\main\resources\application.properties</code> which is not in Git repository
* start eclipse


==Resources==
==Resources==
* [https://devcenter.heroku.com/articles/getting-started-with-python Tutorial]
* [https://devcenter.heroku.com/articles/getting-started-with-python Tutorial]
* [https://dashboard.heroku.com/apps Heroku dashboard]
* [https://dashboard.heroku.com/apps Heroku dashboard]

Latest revision as of 21:50, 13 August 2022

Installation[edit]

Concepts[edit]

  • 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[edit]

  • Dashboard login with user, password and Salesforce App on mobile

Config and Environment Variables[edit]

  • 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[edit]

Databases[edit]

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

Postgres[edit]

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

Operation[edit]

List all Applications[edit]

heroku apps

Delete Application[edit]

heroku apps:destroy uweheuer-capstone

Show Infos for Apps like Repo Size[edit]

heroku apps:info

List all Domains (for Applications)[edit]

heroku domains

Logging[edit]

  • via dasboard

  • or via command line
heroku logs --tail

Example[edit]

Official Tutorial[edit]

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 Demo[edit]

Configuration for Heroku[edit]

  • steps from offical Spring Boot tutorial
  • create demo1 application in C:\Uwes\Programme\eclipse\workspace\demo1 and git it
  • see SpringBoot.docx
  • When deploying an app, Heroku reads pom.xml file and installs the dependencies by running mvn clean install.
  • check DB connection by
C:\Uwes\Programme\PostgreSQL\12\bin> .\psql -h ec2-3-230-122-20.compute-1.amazonaws.com -U cepxizounlueue defpfuas3qslld
  • set specific configurations for Heroku by adding profile heroku to pom.xml and set config var MAVEN_CUSTOM_OPTS to -P !local_dev,heroku

Run on Heroku[edit]

git push heroku master
heroku open // opens the application https://intense-caverns-96515.herokuapp.com/ in a browser

Prepare Locally Heroku[edit]

  • create Procfile Procfile.windows for running locally with command to start the Spring application java -jar target/demo1-0.0.1-SNAPSHOT.jar
  • compile and build a JAR, with dependencies, placing it into your application’s target directory. The spring-boot-maven-plugin in the pom.xml provides this process
mvn install
  • create local DB
C:\Uwes\Programme\xampp7.2.27\mysql\bin\mysql --user=root --password=mHalloo0@1m
  create database demo1;
  • create C:\Uwes\eclipse\workspace_2020-12\SpringBoot\demo1\set_local_dev.bat
  • add profile local_dev to pom.xml

Run Heroku Locally[edit]

  • run the application
set_local_dev.bat
// start eclipse by start_eclipse.bat from shell and run it or
heroku local -f Procfile.windows

Run Eclipse Locally[edit]

  • see src\main\resources\application.properties which is not in Git repository
  • start eclipse

Resources[edit]