Heroku – wdrożenie pierwszej aplikacji

Rozwiązania chmurowe stoją się coraz popularniejsze wśród deweloperów aplikacji webowych. Jednym z powodów wyboru takich platform jest np. uproszczenie procesu wdrażania nowych wersji aplikacji na produkcję. W przypadku platformy Heroku w skonfigurowanym środowisku po wykonaniu commit’a dla zmian w kodzie źródłowym i wysłaniu go na serwer, platforma automatycznie przebuduje aplikację i wykona jej aktualizację. W poniższym poście przedstawię najważniejsze z poleceń CLI dla Heroku, które z pewnością przydadzą się przy pierwszym uruchomieniu aplikacji w Heroku. Jeśli szukacie informacji o innych rozwiązaniach chmurowych, zachęcam do zapoznania się z postem opisującym najważniejsze z nich.

Instalacja klienta Heroku na komputerze z macOS

$ brew install heroku
$ heroku version
$ heroku update

Logowanie do Heroku

$ heroku login
Enter your Heroku credentials:
Email: ...@gmail.com
Password: ********
Logged in as ...@gmail.com

Wyświetlenie listy kluczy SSH oraz dodanie nowych

$ heroku keys
=== sebaczech@gmail.com keys
ssh-rsa AAAAB3NzaC...6/9me1IXeh sebaheroku keys:add

Wyświetlenie listy aplikacji

$ heroku apps 
=== ...@gmail.com Apps
sebastianczech-notes (eu)

Podłączenie lokalnego repozytorium GIT do Heroku

heroku git:remote -a sebastianczech-notes

Wdrożenie nowej wersji aplikacji

git push heroku master
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 274 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote: 
remote: -----> $ python notes/manage.py collectstatic --noinput
remote:        61 static files copied to '/tmp/build_89fc76d1d9f94b9674b3d27b5faf9841/notes/collectstatic', 49 unmodified.
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 63.1M
remote: -----> Launching...
remote:        Released v20
remote:        https://sebastianczech-notes.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/sebastianczech-notes.git
   c5e59f5..39d3d25  master -> master

Wyświetlenie informacji o dyno

$ heroku ps
Free dyno hours quota remaining this month: 1000h 0m (100%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping
=== web (Free): cd notes && gunicorn notes.wsgi:application --log-file - (1)
web.1: up 2017/07/30 15:13:23 +0200 (~ 1m ago)

Weryfikacji statusu aplikacji i danych

$ heroku status
Apps:      No known issues at this time.
Data:      No known issues at this time.
Tools:     No known issues at this time.

Podłączenie się po shell’u do aplikacji

$ heroku run bash
Running bash on ⬢ sebastianczech-notes... up, run.7070 (Free)
~ $ ls -la
total 112
drwx------  5 u23547 dyno 4096 Jul 30 13:16 .
drwxr-xr-x 15 root   root 4096 Feb 24 09:26 ..
drwx------  7 u23547 dyno 4096 Jul 30 13:12 notes
-rw-------  1 u23547 dyno   62 Jul 30 13:12 Procfile
-rw-------  1 u23547 dyno  162 Jul 30 13:12 requirements.txt

Pokazania aktywnych dodatków

$ heroku addons
Add-on                                      Plan       Price  State 
──────────────────────────────────────────  ─────────  ─────  ───────
heroku-postgresql (postgresql-acute-52566)  hobby-dev  free   created
└─ as DATABASE
heroku-redis (redis-rigid-43525)            hobby-dev  free   created
└─ as REDIS
mongolab (mongolab-cubed-59927)             sandbox    free   created
└─ as MONGODB
The table above shows add-ons and the attachments to the current app (sebastianczech-notes) or other apps.

Analiza logów

$ heroku logs
...
2017-07-30T13:13:19.699652+00:00 heroku[web.1]: Starting process with command `cd notes && gunicorn notes.wsgi:application --log-file -`
2017-07-30T13:13:22.476236+00:00 app[web.1]: [2017-07-30 13:13:22 +0000] [6] [INFO] Starting gunicorn 19.7.1
2017-07-30T13:13:22.476907+00:00 app[web.1]: [2017-07-30 13:13:22 +0000] [6] [INFO] Listening at: http://0.0.0.0:57456 (6)
2017-07-30T13:13:22.476992+00:00 app[web.1]: [2017-07-30 13:13:22 +0000] [6] [INFO] Using worker: sync
2017-07-30T13:13:22.483545+00:00 app[web.1]: [2017-07-30 13:13:22 +0000] [9] [INFO] Booting worker with pid: 9
2017-07-30T13:13:22.502295+00:00 app[web.1]: [2017-07-30 13:13:22 +0000] [10] [INFO] Booting worker with pid: 10
2017-07-30T13:13:23.384296+00:00 heroku[web.1]: State changed from starting to up

Pomoc

$ heroku help
Usage: heroku COMMAND
Help topics, type heroku help TOPIC for more details:
 access          manage user access to apps
 addons          tools and services for developing, extending, and operating your app
 apps            manage apps
 auth            heroku authentication
 authorizations  OAuth authorizations
 buildpacks      manage the buildpacks for an app
 certs           a topic for the ssl plugin
 ci              run an application test suite on Heroku
 clients         OAuth clients on the platform
 config          manage app config vars
 container       Use containers to build and deploy Heroku apps
 domains         manage the domains for an app
 drains          list all log drains
 features        manage optional features
 git             manage local git repository for app
 keys            manage ssh keys
 labs            experimental features
 local           run heroku app locally
 logs            display recent log output
 maintenance     manage maintenance mode for an app
 members         manage organization members
 notifications   display notifications
 orgs            manage organizations
 pg              manage postgresql databases
 pipelines       manage collections of apps in pipelines
 plugins         manage plugins
 ps              manage dynos (dynos, workers)
 redis           manage heroku redis instances
 regions         list available regions
 releases        manage app releases
 run             run a one-off process inside a Heroku dyno
 sessions        OAuth sessions
 spaces          manage heroku private spaces
 status          status of the Heroku platform
 teams           manage teams

 

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

Time limit is exhausted. Please reload CAPTCHA.