This is a memo for myself, the details are as follows.
https://c9.io/new Create workspace by specifying Python in Choose a template
By default, Cloud9 has a Python version of Python2, so change it to use Python3.5.1. Press the green + button at the bottom of the screen to open a terminal with [New Terminal] and type commands there.
#Check the version before change
$ python --version
Python 2.7.6
#Save the Python2 system
$ sudo mv /usr/bin/python /usr/bin/python2
#Python3.Link to 5
$ sudo ln -s /usr/bin/python3.5 /usr/bin/python
#Confirm that the version has changed
$ python --version
Python 3.5.1
If it is as it is, the bottle to be used this time is not included, so I will introduce it.
$ sudo pip install bottle
Downloading/unpacking bottle
Downloading bottle-0.12.9.tar.gz (69kB): 69kB downloaded
Running setup.py (path:/tmp/pip_build_root/bottle/setup.py) egg_info for package bottle
Installing collected packages: bottle
Running setup.py install for bottle
changing mode of build/scripts-3.5/bottle.py from 644 to 755
changing mode of /usr/local/bin/bottle.py to 755
Successfully installed bottle
Cleaning up...
For the time being, delete all the files that were originally generated.
Create a file with [Right click] => [New File], and enter app.py with [Right click] => [Rename] on the created file.
Finally, we will implement app.py from here. First and foremost, when you access http: // {your-domain} / hello / on your browser, Hello World will be displayed.
app.py
# -*- coding:utf-8 -*-
import os
from bottle import route, run
@route('/hello/')
def hello():
return "Hello World"
run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
When you press the Run button and execute it, it will tell you the URL to view in the browser, so open it. At this time, don't forget to add "/ hello /" with the routing set at the end.
It was safely displayed in the browser !!
Once you've done this, commit to GitHub.
First, create a new repository on GitHub. https://github.com/new
You need to register your SSH key to commit from Cloud9 to GitHub. From the Cloud9 dashboard, register the public key displayed in [Gear mark] => [SSH Keys] on the upper right to the linked GitHub. https://c9.io/account/ssh => https://github.com/settings/ssh
After registering the key, push it on the Cloud9 terminal.
#Pay attention to the directory to execute
$ pwd
/home/ubuntu/workspace
#Generate files required for deploy
$ pip freeze | grep bottle > requirements.txt #It seems better to put only the package you are using
$ python --version | sed 's/\ /-/g' |sed 's/P/p/g' > runtime.txt
$ echo web: python app.py > Procfile
#The following is for reference only, please copy the command displayed on the screen of the newly created repository as appropriate.
$ echo "# cloud9-bottle-heroku" >> README.md
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/path/to-youre-repository.git #Please note that it depends on the person
git push -u origin master
Next, we will reflect it on heroku, and continue to work on the Cloud9 terminal. Heroku toolbelt seems to have been installed in advance, so no addition is necessary.
#First, log in to heroku.
$ heroku login
#Create app(Please change as appropriate so that the name is not covered)
$ heroku create cloud9-bottle-heroku
Creating cloud9-bottle-heroku... done, stack is cedar-14
https://cloud9-bottle-heroku.herokuapp.com/ | https://git.heroku.com/cloud9-bottle-heroku.git
$ git push heroku master
Counting objects: 21, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (21/21), 1.95 KiB | 0 bytes/s, done.
Total 21 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.5.1
remote: $ pip install -r requirements.txt
remote: Collecting bottle==0.12.9 (from -r requirements.txt (line 1))
remote: Downloading bottle-0.12.9.tar.gz (69kB)
remote: Installing collected packages: bottle
remote: Running setup.py install for bottle: started
remote: Running setup.py install for bottle: finished with status 'done'
remote: Successfully installed bottle-0.12.9
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 49M
remote: -----> Launching...
remote: Released v3
remote: https://cloud9-bottle-heroku.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/cloud9-bottle-heroku.git
* [new branch] master -> master
I was able to open it in my browser !! https://cloud9-bottle-heroku.herokuapp.com/hello/
If you push to GitHub, change the setting so that it will be automatically deployed to heroku. Select the target application from the Heroku dashboard and select Deploy at the top of the screen.
Select GitHub in the Deployment method, enter the repository name in Connect to GitHub, search, and Connect where the target repository is displayed.
Select the target branch as appropriate and press Enable Automatic Deploys to complete the setting.
You can check if the automatic Deploy works from Activity at the top of the screen. Try pushing an empty commit from the Cloud9 terminal and see if Deploy is actually done.
$ git commit --allow-empty -m "deploy test"
[master 9912982] deploy test
$ git push origin master
If you wait about 1 minute after typing the command and then open the Activity tab, you can see that Deploy has been executed.
Now, if you push to GitHub without git push heroku master, the update will be reflected on Heroku side as well.
It seems better to keep it to the minimum necessary.
#the first
$ pip freeze > requirements.txt
#I got angry with a dependency when I pushed to heroku
$ git push heroku master
Counting objects: 18, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (18/18), 1.73 KiB | 0 bytes/s, done.
Total 18 (delta 4), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.5.1
remote: $ pip install -r requirements.txt
remote: Collecting Pillow==2.3.0 (from -r requirements.txt (line 1))
remote: Downloading Pillow-2.3.0.zip (2.4MB)
remote: Collecting bottle==0.12.9 (from -r requirements.txt (line 2))
remote: Downloading bottle-0.12.9.tar.gz (69kB)
remote: Collecting chardet==2.2.1 (from -r requirements.txt (line 3))
remote: Downloading chardet-2.2.1-py2.py3-none-any.whl (180kB)
remote: Collecting colorama==0.2.5 (from -r requirements.txt (line 4))
remote: Downloading colorama-0.2.5.zip
remote: Collecting decorator==3.4.0 (from -r requirements.txt (line 5))
remote: Downloading decorator-3.4.0.tar.gz
remote: Collecting html5lib==0.999 (from -r requirements.txt (line 6))
remote: Downloading html5lib-0.999.tar.gz (885kB)
remote: Collecting ipython==1.2.1 (from -r requirements.txt (line 7))
remote: Downloading ipython-1.2.1.tar.gz (8.7MB)
remote: Collecting matplotlib==1.3.1 (from -r requirements.txt (line 8))
remote: Downloading matplotlib-1.3.1.tar.gz (42.7MB)
remote: Collecting nose==1.3.1 (from -r requirements.txt (line 9))
remote: Downloading nose-1.3.1.tar.gz (274kB)
remote: Collecting numpy==1.8.2 (from -r requirements.txt (line 10))
remote: Downloading numpy-1.8.2.tar.gz (3.8MB)
remote: Collecting pycurl==7.19.3 (from -r requirements.txt (line 11))
remote: Downloading pycurl-7.19.3.tar.gz (113kB)
remote: Collecting pygobject==3.12.0 (from -r requirements.txt (line 12))
remote: Could not find a version that satisfies the requirement pygobject==3.12.0 (from -r requirements.txt (line 12)) (from versions: 2.28.3)
remote: No matching distribution found for pygobject==3.12.0 (from -r requirements.txt (line 12))
remote:
remote: ! Push rejected, failed to compile Python app
remote:
remote: Verifying deploy....
remote:
remote: ! Push rejected to cloud9-bottle-heroku.
remote:
To https://git.heroku.com/cloud9-bottle-heroku.git
![remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cloud9-bottle-heroku.git'
#It was okay if I squeezed it.
$ pip freeze | grep bottle > requirements.txt
When I printed the result of python --version, it was python instead of python.
#Bad example
Python-3.5.1
#Good example
python-3.5.1
Thanks to Cloud9, it is not necessary to build a local environment, but for some reason the movement sometimes gets stuck, so in my environment development using PyCharm was a more comfortable impression. However, considering the case of developing with multiple terminals, I think that it is troublesome to arrange those development environments, so I think that there is an option to use in such a case. Since Heroku is using only the minimum this time, there are many parts that I do not understand well yet, and it seems that I need to sleep for 6 hours a day, but it is nice to be able to publish the application without detailed settings. ..
Heroku Python Support | Heroku Dev Center : https://devcenter.heroku.com/articles/python-support Publish a web app in 4 minutes 33 seconds using Heroku x bottle --Qiita: http://qiita.com/ohbarye/items/55ec574f10685a012baf