Introductory article on heroku I often see ruby or node.js on OSX. Not so.
--In Python --On Win7 --I have an account registered on heroku -(I'm not good friends with git yet)
Let's start from such a place. As a goal, I don't go to apps or anything like that. Until something is displayed.
heroku official Python introductory documentation https://devcenter.heroku.com/articles/getting-started-with-python It is also an experience memo of (however, I eat only the parts that I think I need).
Download it from here and install it.
https://www.python.org/downloads/
Here, I put 2.7.11 which was the latest in 2 series at this time. (For CG, I think it's better to match the version with Python in the main tool. Here, I rushed without thinking about it. Then I thought later that I would put in 3 series)
Add it to the Windows environment variable PATH.
C:\Python27;C:\Python27\Scripts;
Actually, this time, I forgot to do this halfway and made it normal (?) From the middle. So, halfway through, it may include errors that didn't occur when you first did this. It may not be included.
If you want to add it with a command, it's setx
python
> setx /?
There are three ways to use SetX:
Syntax 1:
SETX [/S system[/U [domain\]user[/P [password]]]]Variable value[/M]
Syntax 2:
SETX [/S system[/U [domain\]user[/P [password]]]]
variable/K registry path[/M]
Syntax 3:
SETX [/S system[/U [domain\]user[/P [password]]]]
/F file{variable{/A x,y | /R x,y string}[/M] | /X} [/D delimiter]
Description:
Create environment variables or create environment variables in the user or system environment
change. Arguments, registry keys, or file input
You can set variables based on it.
(Omission)
virtualenv You said that you need virtualenv, so I'll put it in.
python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>> pip.main(["list"])
pip (7.1.2)
setuptools (18.2)
0
>>> pip.main(["install","virtualenv"])
Collecting virtualenv
Downloading virtualenv-13.1.2-py2.py3-none-any.whl (1.7MB)
100% |################################| 1.7MB 271kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-13.1.2
0
>>>
You can usually use pip install virtualenv
, but
Here via Python's pip module.
There is an installer called ** heroku Toolbelt ** that will put in heroku and a set of tools related to it.
https://toolbelt.heroku.com/
The contents are git and ruby.
↓ It will be installed in this location and added to your PATH.
Technical details
The heroku client will be installed into C:\Program Files\Heroku and will be added to your %PATH%.
At the time of installation, did you wait for a while at the last git? It will be, but you don't have to be afraid.
git At this point, git is also included. I will check it. With emotional problems.
git -h
.
git-h
C:\Users\{user}>git -h
Unknown option: -h
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
HM.
getting-started Follow this procedure below.
https://devcenter.heroku.com/articles/getting-started-with-python
heroku Immediately after installing Toolbelt "Once installed, you can use it with the
heroku
command! " It says something like Anyway, I saw it and executed it innocently withheroku
. Did.
Then something like initialization ran, I've been waiting for a while because of add dependencies or something. let's wait. I was upset because I thought I had done something wrong. I don't have to wait a minute. Every time I wait in an unexpected place, I get scared. Because of a small person
By the way, in the log at this time, the window closed automatically after the initialization was completed. There is none (Because it was opened with win key> heroku)
heroku login
You will then be asked for your heroku account email address and password.
python
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\{user}>heroku login
Enter your Heroku credentials.
Email: [email protected]
Password (typing will be hidden):
Logged in as [email protected]
Yes. It looks like.
heroku version
python
C:\Users\{user}>heroku version
heroku/toolbelt/3.42.29 (i386-mingw32) ruby/2.1.7
heroku-cli/4.27.13-9dddf39 (386-windows) go1.5.3
=== Installed Plugins
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
I'm proceeding while reading this (▼)
http://developers.mobage.jp/blog/how-to-use-for-beginners-heroku
It is the content written in [2] there.
Create a folder that you want to use as the workshop this time and move it.
python
C:\Users\{user}>cd C:\Users\{user}\Documents\path\to\heroku_proj
C:\Users\{user}\Documents\path\to\heroku_proj>mkdir testapp
C:\Users\{user}\Documents\path\to\heroku_proj>cd testapp
C:\Users\{user}\Documents\path\to\heroku_proj\testapp>
You will get ** python-getting-started ** published on github.
git clone https://github.com/heroku/python-getting-started.git
python
C:\Users\{user}\Documents\path\to\heroku_proj\testapp>git clone https://github.com/heroku/python-getting-started.git
Cloning into 'python-getting-started'...
remote: Counting objects: 204, done.
emote: Total 204 (delta 0), reused 0 (delta 0), pack-reused 204Receiving objects
Receiving objects: 75% (153/204)
Receiving objects: 100% (204/204), 32.17 KiB | 0 bytes/s, done.
Resolving deltas: 100% (91/91), done.
Checking connectivity... done.
Then move with cd
python
C:\Users\{user}\Documents\path\to\heroku_proj\testapp>cd python-getting-started
C:\Users\{user}\Documents\path\to\heroku_proj\testapp\python-getting-started>
From now on, please understand that all commands are executed from C: \ Users \ {user} \ Documents \ path \ to \ heroku_proj \ testapp \ python-getting-started>
.
Imakoko
https://devcenter.heroku.com/articles/getting-started-with-python#deploy-the-app
heroku create
.
python
>heroku create
Creating app... done, stack is cedar-14
https://ancient-taiga-0000.herokuapp.com/ | https://git.heroku.com/ancient-taiga-0000.git
** What is ancient-taiga-0000? ** ** Is it a sudden kitchen term? I think that, if you do not decide the name when creating, it seems that ** it will automatically name it **. Is it okay because it's a test?
If you name it properly
heroku create your-app-name
in this way.
Or you can log in to heroku via a browser and change from there (not done)
Here is a sudden git experience.
git push heroku master
It takes about 1-2 minutes.
python
>git push heroku master
Counting objects: 204, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (98/98), done.
Writing objects: 100% (204/204), 32.16 KiB | 0 bytes/s, done.
Total 204 (delta 91), reused 204 (delta 91)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing runtime (python-2.7.11)
remote: -----> Installing dependencies with pip
remote: Collecting dj-database-url==0.3.0 (from -r requirements.txt (line 1))
remote: Downloading dj_database_url-0.3.0-py2.py3-none-any.whl
remote: Collecting Django==1.9.1 (from -r requirements.txt (line 2))
remote: Downloading Django-1.9.1-py2.py3-none-any.whl (6.6MB)
remote: Collecting gunicorn==19.4.5 (from -r requirements.txt (line 3))
remote: Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
remote: Collecting psycopg2==2.6.1 (from -r requirements.txt (line 4))
remote: Downloading psycopg2-2.6.1.tar.gz (371kB)
remote: Collecting whitenoise==2.0.6 (from -r requirements.txt (line 5))
remote: Downloading whitenoise-2.0.6-py2.py3-none-any.whl
remote: Installing collected packages: dj-database-url, Django, gunicorn, psycopg2, whitenoise
remote: Running setup.py install for psycopg2
remote: Successfully installed Django-1.9.1 dj-database-url-0.3.0 gunicorn-19.4.5 psycopg2-2.6.1 whitenoise-2.0.6
remote:
remote: -----> Preparing static assets
remote: Running collectstatic...
remote: Post-processed 'admin/js/vendor/xregexp/LICENSE-XREGEXP.txt' as 'admin/js/vendor/xregexp/LICENSE-XREGEXP.d64cecf4f157.txt'
(Omitted)
remote: Post-processed 'lang-logo.png' as 'lang-logo.019c8743b7cf.png'
remote: 58 static files copied to '/app/staticfiles', 58 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 42.1MB
remote: -----> Launching...
remote: Released v4
remote: https://ancient-taiga-0000.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/ancient-taiga-0000.git
* [new branch] master -> master
>
** requirements.txt ** is placed in python-getting-started, During the above process, it is read and installed with pip.
Then, heroku ps: scale web = 1
.
python
>heroku ps:scale web=1
Scaling dynos... done, now running web at 1:Free.
from
heroku open
python
>heroku open
Opening ancient-taiga-0000... done
Then, the browser will be launched and the app (here * ancient-taiga-0000.herokuapp.com *) will be opened.
Hmm.
So far
--Preparation --Make heroku app --Deploy and run on heroku
I was able to experience ...
Imakoko
https://devcenter.heroku.com/articles/getting-started-with-python#view-logs
heroku logs --tail
If you add --tail
, logs will be acquired more and more in real time. When you stop, Ctl + C
python
>heroku logs --tail
2016-01-17T13:37:24.947150+00:00 heroku[api]: Enable Logplex by [email protected]
2016-01-17T13:37:24.947150+00:00 heroku[api]: Release v2 created by [email protected]
2016-01-17T13:40:12.180138+00:00 heroku[api]: Attach DATABASE resource by [email protected]
2016-01-17T13:40:12.180177+00:00 heroku[api]: Release v3 created by [email protected]
2016-01-17T13:40:12.470201+00:00 heroku[api]: Scale to web=1 by [email protected]
2016-01-17T13:40:12.529336+00:00 heroku[api]: Deploy fe7f948 by [email protected]
2016-01-17T13:40:12.529336+00:00 heroku[api]: Release v4 created by [email protected]
2016-01-17T13:40:12.842955+00:00 heroku[slug-compiler]: Slug compilation started
2016-01-17T13:40:12.842964+00:00 heroku[slug-compiler]: Slug compilation finished
2016-01-17T13:40:15.096972+00:00 heroku[web.1]: Starting process with command `gunicorn gettingstarted.wsgi --log-file -`
2016-01-17T13:40:16.642246+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [3] [INFO] Listening at: http://0.0.0.0:10178 (3)
2016-01-17T13:40:16.642313+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [3] [INFO] Using worker: sync
2016-01-17T13:40:16.640646+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [3] [INFO] Starting gunicorn 19.4.5
2016-01-17T13:40:16.645613+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [9] [INFO] Booting worker with pid: 9
2016-01-17T13:40:16.684880+00:00 app[web.1]: [2016-01-17 13:40:16 +0000] [10] [INFO] Booting worker with pid: 10
2016-01-17T13:40:17.171330+00:00 heroku[web.1]: State changed from starting to up
(ry
2016-01-17T13:45:25.167623+00:00 app[web.1]: Not Found: /favicon.ico
If you try to stop with ctl + c, you will see the following
python
! Command cancelled.
Do you want to end the batch job?(Y/N)? y
>
Procfile Imakoko
https://devcenter.heroku.com/articles/getting-started-with-python#define-a-procfile
It is placed directly under "getting-started-with-python" that has been git cloned. I would like to know about ** Procfile file **.
On github, this
https://github.com/heroku/python-getting-started/blob/master/Procfile
In the initial state, the contents are like this
web: gunicorn gettingstarted.wsgi --log-file -
It seems that you write clock: ~~
when you want heroku to process it automatically.
It's a file that writes such settings.
ps Imakoko
https://devcenter.heroku.com/articles/getting-started-with-python#scale-the-app
Try heroku ps
.
python
>heroku ps
=== web (Free): gunicorn gettingstarted.wsgi --log-file -
web.1: up 2016/01/17 22:40:17 (~ 18m ago)
>
heroku run ~~
It seems that something can be done with heroku run ~~
python
>heroku run
! Usage: heroku run COMMAND
!
! Example: heroku run bash
>
I need something after run
. .. ..
By the way, I haven't helped heroku since I started working on it, so I'll try it here.
python
>heroku -h
Usage: heroku COMMAND [--app APP] [command-specific-options]
Primary help topics, type "heroku help TOPIC" for more details:
addons # manage add-on resources
apps # manage apps (create, destroy)
auth # authentication (login, logout)
config # manage app config vars
domains # manage domains
logs # display logs for an app
ps # manage dynos (dynos, workers)
releases # manage app releases
run # run one-off commands (console, rake)
sharing # manage collaborators on an app
Additional topics:
2fa # manage two-factor authentication settings
buildpacks # manage the buildpack for an app
certs # manage ssl endpoints for an app
drains # display drains for an app
features # manage optional features
fork # clone an existing app
git # manage local git repository for app
help # list commands and display help
keys # manage authentication keys
labs # manage optional features
local # run heroku app locally
login # Login with your Heroku credentials.
maintenance # manage maintenance mode for an app
members # manage membership in organization accounts
orgs # manage organization accounts
pg # manage heroku-postgresql databases
pgbackups # manage backups of heroku postgresql databases
plugins # manage plugins to the heroku gem
regions # list available regions
spaces # manage heroku private spaces
stack # manage the stack for an app
status # Status of Heroku Platform
twofactor # manage two-factor authentication settings
update # update the heroku client
version # display version
List your apps
heroku apps
>heroku apps
=== My Apps
ancient-taiga-0000
Of course, there is only one at present.
heroku apps:info
>heroku apps:info
=== ancient-taiga-0000
Addons: heroku-postgresql:hobby-dev
Dynos: web: 1
Git URL: [email protected]:ancient-taiga-0000.git
Owner: [email protected]
Region: us
Repo Size: 36 kB
Slug Size: 42 MB
Stack: cedar-14
Web URL: https://ancient-taiga-0000.herokuapp.com/
You can check what add-on you are using and the URL for access. Speaking of which, ** Region is us **.
heroku plugins
python
>heroku plugins
=== Installed Plugins
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
heroku addons
>heroku addons
Add-on Plan Price
─────────────────────────────────────────────── ───────── ──
───
heroku-postgresql (postgresql-dimensional-7392) hobby-dev free
└─ as DATABASE
The table above shows add-ons and the attachments to the current app (ancient-taiga-0000) or other apps.
Open the add-on page
>heroku addons:open heroku-postgresql
Opening heroku-postgresql (postgresql-dimensional-7392) for ancient-taiga-0000... done
Then this was opened ↓
https://postgres.heroku.com/databases
[email protected] does not exist or cannot be accessed by this account
Is that so.
By the way, some add-ons will not install unless you verify your account. In short, please register your payment information (credit card) It seems that.
※reference: Create a Twitter ToDo service with Unfiltered + Heroku (Try using heroku Add-on, configuration file and Scalate) @ Meinoshi http://mao-instantlife.hatenablog.com/entry/20120310/1331388396
If you skip the payment information registration and try to add an add-on, you will get this attitude.
I knew it!
heroku releases
>heroku releases
=== ancient-taiga-0000 Releases
v4 Deploy fe7f948 [email protected] 2016/01/17 22:40:12 (~ 2h ago)
v3 Attach DATABASE resource [email protected] 2016/01/17 22:40:12 (~ 2h ago)
v2 Enable Logplex [email protected] 2016/01/17 22:37:24 (~ 2h ago)
v1 Initial release [email protected] 2016/01/17 22:37:24 (~ 2h ago)
heroku config
>heroku config
=== ancient-taiga-0000 Config Vars
DATABASE_URL: postgres://abcdefghijklmn:GaEMJZBYWhqmI9xXOOudegwpxf@ec2-54-83-61-45.compute-1.amazonaws.com:5432/d7vc7kpol1v9vn
It's been long, so once. ~~ If you can write the second half, I will paste the link ~~> I wrote the second half
http://qiita.com/it_ks/items/ca6c7f6e8fc89e49e46d
Recommended Posts